tbm_surface_h NativeImageSource::GetSurfaceFromAny( Any source ) const
{
  if( source.Empty() )
  {
    return NULL;
  }

  if( source.GetType() == typeid( tbm_surface_h ) )
  {
    return AnyCast< tbm_surface_h >( source );
  }
  else
  {
    return NULL;
  }
}
unsigned int EcoreXRenderSurface::GetSurfaceId( Any surface ) const
{
  unsigned int surfaceId = 0;

  if ( surface.Empty() == false )
  {
    // check we have a valid type
    DALI_ASSERT_ALWAYS( ( (surface.GetType() == typeid (XWindow) ) ||
                          (surface.GetType() == typeid (Ecore_X_Window) ) )
                        && "Surface type is invalid" );

    if ( surface.GetType() == typeid (Ecore_X_Window) )
    {
      surfaceId = AnyCast<Ecore_X_Window>( surface );
    }
    else
    {
      surfaceId = AnyCast<XWindow>( surface );
    }
  }
  return surfaceId;
}
Exemple #3
0
bool LDAPExpr::Compare( const Any& obj, int op, const std::string& s ) const
{
  if (obj.Empty())
    return false;
  if (op == EQ && s == WILDCARD_STRING)
    return true;

  try
  {
    const std::type_info& objType = obj.Type();
    if (objType == typeid(std::string))
    {
      return CompareString(ref_any_cast<std::string>(obj), op, s);
    }
    else if (objType == typeid(std::vector<std::string>))
    {
      const std::vector<std::string>& list = ref_any_cast<std::vector<std::string> >(obj);
      for (std::size_t it = 0; it != list.size(); it++)
      {
         if (CompareString(list[it], op, s))
           return true;
      }
    }
    else if (objType == typeid(std::list<std::string>))
    {
      const std::list<std::string>& list = ref_any_cast<std::list<std::string> >(obj);
      for (std::list<std::string>::const_iterator it = list.begin();
           it != list.end(); ++it)
      {
         if (CompareString(*it, op, s))
           return true;
      }
    }
    else if (objType == typeid(char))
    {
      return CompareString(std::string(1, ref_any_cast<char>(obj)), op, s);
    }
    else if (objType == typeid(bool))
    {
      if (op==LE || op==GE)
        return false;

      std::string boolVal = any_cast<bool>(obj) ? "true" : "false";
      return std::equal(s.begin(), s.end(), boolVal.begin(), stricomp);
    }
    else if (objType == typeid(short))
    {
      return CompareIntegralType<short>(obj, op, s);
    }
    else if (objType == typeid(int))
    {
      return CompareIntegralType<int>(obj, op, s);
    }
    else if (objType == typeid(long int))
    {
      return CompareIntegralType<long int>(obj, op, s);
    }
    else if (objType == typeid(long long int))
    {
      return CompareIntegralType<long long int>(obj, op, s);
    }
    else if (objType == typeid(unsigned char))
    {
      return CompareIntegralType<unsigned char>(obj, op, s);
    }
    else if (objType == typeid(unsigned short))
    {
      return CompareIntegralType<unsigned short>(obj, op, s);
    }
    else if (objType == typeid(unsigned int))
    {
      return CompareIntegralType<unsigned int>(obj, op, s);
    }
    else if (objType == typeid(unsigned long int))
    {
      return CompareIntegralType<unsigned long int>(obj, op, s);
    }
    else if (objType == typeid(unsigned long long int))
    {
      return CompareIntegralType<unsigned long long int>(obj, op, s);
    }
    else if (objType == typeid(float))
    {
      errno = 0;
      char* endptr = 0;
      double sFloat = strtod(s.c_str(), &endptr);
      if ((errno == ERANGE && (sFloat == 0 || sFloat == HUGE_VAL || sFloat == -HUGE_VAL)) ||
          (errno != 0 && sFloat == 0) || endptr == s.c_str())
      {
        return false;
      }

      double floatVal = static_cast<double>(any_cast<float>(obj));

      switch(op)
      {
      case LE:
        return floatVal <= sFloat;
      case GE:
        return floatVal >= sFloat;
      default: /*APPROX and EQ*/
        double diff = floatVal - sFloat;
        return (diff < std::numeric_limits<float>::epsilon()) && (diff > -std::numeric_limits<float>::epsilon());
      }
    }
    else if (objType == typeid(double))
    {
      errno = 0;
      char* endptr = 0;
      double sDouble = strtod(s.c_str(), &endptr);
      if ((errno == ERANGE && (sDouble == 0 || sDouble == HUGE_VAL || sDouble == -HUGE_VAL)) ||
          (errno != 0 && sDouble == 0) || endptr == s.c_str())
      {
        return false;
      }

      double doubleVal = any_cast<double>(obj);

      switch(op)
      {
      case LE:
        return doubleVal <= sDouble;
      case GE:
        return doubleVal >= sDouble;
      default: /*APPROX and EQ*/
        double diff = doubleVal - sDouble;
        return (diff < std::numeric_limits<double>::epsilon()) && (diff > -std::numeric_limits<double>::epsilon());
      }
    }
    else if (objType == typeid(std::vector<Any>))
    {
      const std::vector<Any>& list = ref_any_cast<std::vector<Any> >(obj);
      for (std::size_t it = 0; it != list.size(); it++)
      {
         if (Compare(list[it], op, s))
           return true;
      }
    }
  }
  catch (...)
  {
    // This might happen if a std::string-to-datatype conversion fails
    // Just consider it a false match and ignore the exception
  }
  return false;
}
Exemple #4
0
bool LDAPExpr::Compare( const Any& obj, int op, const std::string& s ) const
{
  if (obj.Empty())
    return false;
  if (op == EQ && s == WILDCARD_STRING)
    return true;

  try
  {
    const std::type_info& objType = obj.Type();
    if (objType == typeid(std::string))
    {
      return CompareString(ref_any_cast<std::string>(obj), op, s);
    }
    else if (objType == typeid(std::vector<std::string>))
    {
      const std::vector<std::string>& list = ref_any_cast<std::vector<std::string> >(obj);
      for (std::size_t it = 0; it != list.size(); it++)
      {
         if (CompareString(list[it], op, s))
           return true;
      }
    }
    else if (objType == typeid(std::list<std::string>))
    {
      const std::list<std::string>& list = ref_any_cast<std::list<std::string> >(obj);
      for (std::list<std::string>::const_iterator it = list.begin();
           it != list.end(); ++it)
      {
         if (CompareString(*it, op, s))
           return true;
      }
    }
    else if (objType == typeid(char))
    {
      return CompareString(std::string(1, ref_any_cast<char>(obj)), op, s);
    }
    else if (objType == typeid(bool))
    {
      if (op==LE || op==GE)
        return false;

      std::string boolVal = any_cast<bool>(obj) ? "true" : "false";
      return std::equal(s.begin(), s.end(), boolVal.begin(), stricomp);
    }
    else if (objType == typeid(Byte) || objType == typeid(int))
    {
      int sInt;
      std::stringstream ss(s);
      ss >> sInt;
      int intVal = any_cast<int>(obj);

      switch(op)
      {
      case LE:
        return intVal <= sInt;
      case GE:
        return intVal >= sInt;
      default: /*APPROX and EQ*/
        return intVal == sInt;
      }
    }
    else if (objType == typeid(float))
    {
      float sFloat;
      std::stringstream ss(s);
      ss >> sFloat;
      float floatVal = any_cast<float>(obj);

      switch(op)
      {
      case LE:
        return floatVal <= sFloat;
      case GE:
        return floatVal >= sFloat;
      default: /*APPROX and EQ*/
        float diff = floatVal - sFloat;
        return (diff < std::numeric_limits<float>::epsilon()) && (diff > -std::numeric_limits<float>::epsilon());
      }
    }