示例#1
0
Any Any::operator + (const Any &r) const {
	switch (this->type()) {
		case Any::Int:
			switch (r.type()) {
				case Any::Int: return this->getInt() + r.getInt();
				case Any::Float: return this->getInt() + r.getFloat();
				case Any::String: return boost::lexical_cast<string>(this->getInt()) + r.getString();
			}
			break;
		case Any::Float:
			switch (r.type()) {
				case Any::Int: return this->getFloat() + r.getInt();
				case Any::Float: return this->getFloat() + r.getFloat();
				case Any::String: return boost::lexical_cast<string>(this->getFloat()) + r.getString();
			}
			break;
		case Any::String:
			switch (r.type()) {
				case Any::Int: return this->getString() + boost::lexical_cast<string>(r.getInt());
				case Any::Float: return this->getString() + boost::lexical_cast<string>(r.getFloat());
				case Any::String: return this->getString() + r.getString();
			}
			break;
	}
	FIXME("Unsupported operation %s + %s", this->typeInfo().name(), r.typeInfo().name());
	return 0;
}
示例#2
0
int32_t Any::shr (const Any &l, const Any &r) {
	if (l.type() == Any::Int && r.type() == Any::Int) {
		int32_t a = l.getInt();
		int32_t b = r.getInt();
		uint32_t ret = *reinterpret_cast<uint32_t*>( &a ) >> *reinterpret_cast<uint32_t*>( &b );
		return *reinterpret_cast<int32_t*>( &ret );
	}
Texture::Encoding::Encoding(const Any& a) {
    *this = Encoding();

    if (a.type() == Any::STRING) {
        format = ImageFormat::fromString(a);
    } else if (a.nameBeginsWith("Color4")) {
        readMultiplyFirst = a;
	}
	else if (anyNameIsColor3Variant(a)) {
        readMultiplyFirst = Color4(Color3(a), 1.0f);
    } else if (a.type() == Any::NUMBER) {
        readMultiplyFirst = Color4::one() * float(a.number());
    } else {
        AnyTableReader r(a);

        r.getIfPresent("frame", frame);
        r.getIfPresent("readMultiplyFirst", readMultiplyFirst);
        r.getIfPresent("readAddSecond", readAddSecond);

        String fmt;
        if (r.getIfPresent("format", fmt)) {
            format = ImageFormat::fromString(fmt);
        }
    }
}
示例#4
0
Any Converter<float>::convert(const Any& a)
{
	if (typeid(int) == a.type())
		return Any(helper<float, int>::convert(a));
	else if (typeid(const char *) == a.type())
		return Any(helper<float, const char *>::convert(a));

	return any_cast<float>(a);
}
示例#5
0
Any Converter<int>::convert(const Any& a)
{
	if (Type::from<float>() == a.type())
		return helper<int, double>::convert(a);
    else if (Type::from<const char *>() == a.type())
		return helper<int, const char *>::convert(a);

	return any_cast<int>(a);
}
示例#6
0
Any Converter<float>::convert(const Any& a)
{
    if (Type::from<int>() == a.type())
		return Any(helper<float, int>::convert(a));
    else if (Type::from<const char *>() == a.type())
		return Any(helper<float, const char *>::convert(a));

	return any_cast<float>(a);
}
示例#7
0
Any Converter<int>::convert(const Any& a)
{
	if (typeid(float) == a.type())
		return helper<int, double>::convert(a);
	else if (typeid(const char *) == a.type())
		return helper<int, const char *>::convert(a);

	return any_cast<int>(a);
}
Texture::Specification::Specification(const Any& any, bool assumesRGBForAuto, Dimension defaultDimension) {
    *this = Specification();
    assumeSRGBSpaceForAuto = assumesRGBForAuto;
    dimension              = defaultDimension;

    if (any.type() == Any::STRING) {
        filename = any.string();
        if (filename == "<whiteCube>") {
            filename = "<white>";
            dimension = Texture::DIM_CUBE_MAP;
        }

        if (! beginsWith(filename, "<")) {
            filename = any.resolveStringAsFilename();
            if (FilePath::containsWildcards(filename)) {

                // Assume this is a cube map
                dimension = Texture::DIM_CUBE_MAP;
            }
        }
    } else if ((any.type() == Any::NUMBER) ||
               any.nameBeginsWith("Color4") || 
			   anyNameIsColor3Variant(any)) {
        filename = "<white>";
        encoding.readMultiplyFirst = Color4(any);
    } else {

        any.verifyNameBeginsWith("Texture::Specification");
        AnyTableReader r(any);
        r.getFilenameIfPresent("filename", filename);
        r.getFilenameIfPresent("alphaFilename", alphaFilename);
        r.getIfPresent("encoding", encoding);
        r.getIfPresent("assumeSRGBSpaceForAuto", assumeSRGBSpaceForAuto);
        {
            Any a;
            if (r.getIfPresent("dimension", a)) {
                dimension = toDimension(a);
            }
        }
        r.getIfPresent("generateMipMaps", generateMipMaps);
        r.getIfPresent("preprocess", preprocess);
        r.getIfPresent("visualization", visualization);
        r.getIfPresent("cachable", cachable);
        r.verifyDone();

        if (! any.containsKey("dimension") && FilePath::containsWildcards(filename)) {
            // Assume this is a cube map
            dimension = Texture::DIM_CUBE_MAP;
        }
    }
}
示例#9
0
void AnyTest::testComplexType()
{
	SomeClass str(13,std::string("hello"));
	Any a = str;
	Any b = a;
	assert (a.type() == typeid(SomeClass));
	assert (b.type() == typeid(SomeClass));
	SomeClass str2 = AnyCast<SomeClass>(a);
	assert (str == str2);
	const SomeClass& strCRef = RefAnyCast<SomeClass>(a);
	assert (str == strCRef);
	SomeClass& strRef = RefAnyCast<SomeClass>(a);
	assert (str == strRef);
}
示例#10
0
static void testParse() {
    {
        const String& src = "name[ \"foo\", b4r, { a = b, c = d}]";
        Any a = Any::parse(src);
        a.verifyType(Any::ARRAY);
        a[0].verifyType(Any::STRING);
        testAssert(a[0].string() == "foo"); 
        testAssert(a[1].string() == "b4r");
        testAssert(a[2]["a"].string() == "b");
    }
    {
        const String& src =  
        "[v = 1,\r\n/*\r\n*/\r\nx = 1]";
        Any a = Any::parse(src);
        testAssert(a.type() == Any::TABLE);
        testAssert(a.size() == 2);

        Any val1 = a["v"];
        testAssert(val1.type() == Any::NUMBER);
        testAssert(val1.number() == 1);
    }
    {
        const String& src =  
        "{\n\
            val0 : (1);\n\
           \n\
           // Comment 1\n\
           val1 : 3;\n\
           \
           // Comment 2\n\
           // Comment 3\n\
           val2 : None;\n\
           val3 : none;\n\
           val4 : NIL;\n\
        }";

        Any a = Any::parse(src);
        testAssert(a.type() == Any::TABLE);
        testAssert(a.size() == 5);

        Any val1 = a["val1"];
        testAssert(val1.type() == Any::NUMBER);
        testAssert(val1.number() == 3);
        testAssert(val1.comment() == "Comment 1");
        testAssert(a["val2"].isNil());       
        testAssert(a["val3"].string() == "none");
        testAssert(a["val4"].isNil());
    }
示例#11
0
void SoundInterface::commandPlaySound(void) {
	int32_t freg = cb->popValue().toInt();
	float balance = cb->popValue().toFloat();
	float volume = cb->popValue().toFloat();
	Any any = cb->popValue();
	
	// If passed parameter is integer, the sound is preloaded. Otherwise load it.
	if (any.type() == Any::Int) {
		CBChannel* channel = new CBChannel;
		channel->setMixer(al_get_default_mixer());
		int32_t id = any.toInt();
		channel->playSound((*sounds[id]), volume, balance, freg);
		int32_t nextChannel = nextChannelId();
		channels[nextChannel] = channel;
	}
	else {
		CBChannel* channel = new CBChannel;
		channel->setMixer(al_get_default_mixer());
		ALLEGRO_PATH *path = any.toString().getPath();
		const char *cpath = al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP);
		channel->playSound(cpath, volume, balance, freg);
		int32_t nextChannel = nextChannelId();
		channels[nextChannel] = channel;
	}
}
示例#12
0
    void
    Any_Handler::extract_into_any (const Any& desc,
                                   CORBA::Any& toconfig)
    {
      DANCE_TRACE("Any_Handler::extract_into_any");
      try
        {
          DynamicAny::DynAny_var dyn = DYNANY_HANDLER->extract_into_dynany (desc.type (),
                                                                            desc.value ());
          CORBA::Any_var any_safe (dyn->to_any ());
          toconfig = *any_safe;

          dyn->destroy ();
        }
      catch (CORBA::Exception &ex)
        {
          DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
                           ACE_TEXT ("Any_Handler::extract_into_any -")
                           ACE_TEXT (" Caught CORBA Exception while extracting into")
                           ACE_TEXT (" dynany: %C\n"),
                           ex._info ().c_str ()));
          throw Config_Error (ACE_TEXT (""),
                              ACE_TEXT ("CORBA Exception while extracting into dynany\n"));
        }
      catch (Config_Error &ex)
        {
          throw ex;
        }
      catch (...)
        {
          throw Config_Error (ACE_TEXT (""), ACE_TEXT ("Caught error whilst parsing XML into Any\n"));
        }
    }
示例#13
0
Sampler::Sampler(const Any& any) {
    *this = Sampler::defaults();
    any.verifyNameBeginsWith("Sampler");
    if (any.type() == Any::TABLE) {
        AnyTableReader r(any);
        r.getIfPresent("maxAnisotropy", maxAnisotropy);
        r.getIfPresent("maxMipMap", maxMipMap);
        r.getIfPresent("minMipMap", minMipMap);
        r.getIfPresent("mipBias", mipBias);
        r.getIfPresent("xWrapMode", xWrapMode);
        if (! r.getIfPresent("yWrapMode", yWrapMode)) {
            yWrapMode = xWrapMode;
        }
        r.getIfPresent("depthReadMode", depthReadMode);
        r.getIfPresent("interpolateMode", interpolateMode);
        r.verifyDone();
    } else {
        any.verifySize(0);
        const String& n = any.name();
        if (n == "Sampler::defaults") {
            // Done!
        } else if (n == "Sampler::buffer") {
            *this = Sampler::buffer();
        } else if (n == "Sampler::cubeMap") {
            *this = Sampler::cubeMap();
        } else if (n == "Sampler::shadow") {
            *this = Sampler::shadow();
        } else if (n == "Sampler::video") {
            *this = Sampler::video();
        } else {
            any.verify(false, "Unrecognized name for Sampler constructor or factory method.");
        }
    }
}
ArticulatedModel::Instruction::Identifier::Identifier(const Any& a) {
    switch (a.type()) {
    case Any::NUMBER:
        id = ID(iRound(a.number()));
        a.verify(id >= 0, "Illegal ID");
        break;

    case Any::STRING:
        name = a.string();
        break;

    case Any::ARRAY:
        a.verifySize(0);
        if (a.name() == "root") {
            *this = root();
        } else if (a.name() == "all") {
            *this = all();
        } else {
            a.verify(false, "Illegal function call: " + a.name());
        }
        break;

    default:
        a.verify(false, "Expected a name, integer ID, root(), or all()");
    }
}
PhysicsFrame::PhysicsFrame(const Any& a) {
    const std::string& n = toLower(a.name());
    *this = PhysicsFrame();

    if (beginsWith(n, "vector3")) {
        *this = PhysicsFrame(Vector3(a));
    } else if (beginsWith(n, "matrix3")) {        
        *this = PhysicsFrame(Matrix3(a));
    } else if (beginsWith(n, "cframe") || beginsWith(n, "coordinateframe")) {        
        *this = PhysicsFrame(CoordinateFrame(a));
    } else if (beginsWith(n, "pframe") || beginsWith(n, "physicsframe")) {
        if (a.type() == Any::ARRAY) {
            a.verifySize(2);
            rotation    = a[0];
            translation = a[1];
        } else {
            for (Any::AnyTable::Iterator it = a.table().begin(); it.hasMore(); ++it) {
                const std::string& n = toLower(it->key);
                if (n == "translation") {
                    translation = it->value;
                } else if (n == "rotation") {
                    rotation = it->value;
                } else {
                    a.verify(false, "Illegal table key: " + it->key);
                }
            }
        }
    }
}
示例#16
0
void AnyTest::testDefaultCtor()
{
	const Any value;
	
	assert (value.empty());
	assert (0 == AnyCast<int>(&value));
	assert (value.type() == typeid(void));
}
示例#17
0
void AbstractBinder::bind(std::size_t pos, const Any& val, Direction dir)
{
	const std::type_info& type = val.type();

	if(type == typeid(Int32))
		bind(pos, RefAnyCast<Int32>(val), dir);
	else if(type == typeid(std::string))
		bind(pos, RefAnyCast<std::string>(val), dir);
	else if (type == typeid(bool))
		bind(pos, RefAnyCast<bool>(val), dir);
	else if(type == typeid(char))
		bind(pos, RefAnyCast<char>(val), dir);
	else if(type == typeid(Int8))
		bind(pos, RefAnyCast<Int8>(val), dir);
	else if(type == typeid(UInt8))
		bind(pos, RefAnyCast<UInt8>(val), dir);
	else if(type == typeid(Int16))
		bind(pos, RefAnyCast<Int16>(val), dir);
	else if(type == typeid(UInt16))
		bind(pos, RefAnyCast<UInt16>(val), dir);
	else if(type == typeid(UInt32))
		bind(pos, RefAnyCast<UInt32>(val), dir);
	else if(type == typeid(Int64))
		bind(pos, RefAnyCast<Int64>(val), dir);
	else if(type == typeid(UInt64))
		bind(pos, RefAnyCast<UInt64>(val), dir);
	else if(type == typeid(float))
		bind(pos, RefAnyCast<float>(val), dir);
	else if(type == typeid(double))
		bind(pos, RefAnyCast<double>(val), dir);
	else if(type == typeid(DateTime))
		bind(pos, RefAnyCast<DateTime>(val), dir);
	else if(type == typeid(Date))
		bind(pos, RefAnyCast<Date>(val), dir);
	else if(type == typeid(Time))
		bind(pos, RefAnyCast<Time>(val), dir);
	else if(type == typeid(BLOB))
		bind(pos, RefAnyCast<BLOB>(val), dir);
#ifndef POCO_LONG_IS_64_BIT
	else if(type == typeid(long))
		bind(pos, RefAnyCast<long>(val), dir);
#endif
	else
		throw UnknownTypeException(std::string(val.type().name()));
}
示例#18
0
ParticleSystemModel::Emitter::Specification::Specification(const Any& a) {
    a.verifyNameBeginsWith("ParticleSystemModel::Emitter");
    *this = Specification();
    AnyTableReader r(a);
    r.getIfPresent("location", location);
    r.getIfPresent("noisePower", noisePower);
    r.getIfPresent("initialDensity", initialDensity);
    r.getIfPresent("rateCurve", rateCurve);
    r.getIfPresent("coverageFadeInTime", coverageFadeInTime);
    r.getIfPresent("coverageFadeOutTime", coverageFadeOutTime);
    r.getIfPresent("particleLifetimeMean", particleLifetimeMean);
    r.getIfPresent("particleLifetimeVariance", particleLifetimeVariance);
    r.getIfPresent("angularVelocityMean", angularVelocityMean);
    r.getIfPresent("angularVelocityVariance", angularVelocityVariance);
    r.getIfPresent("material", material);
    r.getIfPresent("radiusMean", radiusMean);
    r.getIfPresent("radiusVariance", radiusVariance);
    r.getIfPresent("particleMassDensity", particleMassDensity);
    r.getIfPresent("dragCoefficient", dragCoefficient);

    shapeType = Shape::Type::NONE;
    Any shape;
    if (r.getIfPresent("shape", shape)) {
        if (shape.nameBeginsWith("ArticulatedModel") || (shape.type() == Any::STRING)) {
            shapeType = Shape::Type::MESH;
        } else {
            shapeType = Shape::Type(toUpper(shape.name()));
        }

        switch (shapeType) {
        case Shape::Type::BOX:
            box = Box(shape);
            break;

        case Shape::Type::CYLINDER:
            cylinder = Cylinder(shape);
            break;

        case Shape::Type::SPHERE:
            sphere = Sphere(shape);
            break;

        case Shape::Type::MESH:
            mesh = shape;
            break;

        default:
            shape.verify(false, "Shape must be a Box, Cylinder, Sphere, or ArticulatedModel specification");
        }
    }

    r.getIfPresent("velocityDirectionMean", velocityDirectionMean);
    r.getIfPresent("velocityConeAngleDegrees", velocityConeAngleDegrees);
    r.getIfPresent("velocityMagnitudeMean", velocityMagnitudeMean);
    r.getIfPresent("velocityMagnitudeVariance", velocityMagnitudeVariance);
    r.verifyDone();
}
示例#19
0
Any Any::operator % (const Any &r) const {
	switch (this->type()) {
		case Any::Int:
			switch (r.type()) {
				case Any::Int: return this->getInt() % r.getInt();
				case Any::Float: return (float)fmod((double)this->getInt(), (double)r.getFloat());
			}
			break;
		case Any::Float:
			switch (r.type()) {
				case Any::Int: return (float)fmod((double)this->getFloat(), (double)r.getInt());
				case Any::Float: return (float)fmod(this->getFloat(), r.getFloat());
			}
			break;
	}
	FIXME("Unsupported operation %s % %s", this->typeInfo().name(), r.typeInfo().name());
	return 0;
}
示例#20
0
Any Any::operator / (const Any &r) const {
	switch (this->type()) {
		case Any::Int:
			switch (r.type()) {
				case Any::Int: return this->getInt() / r.getInt();
				case Any::Float: return this->getInt() / r.getFloat();
			}
			break;
		case Any::Float:
			switch (r.type()) {
				case Any::Int: return this->getFloat() / r.getInt();
				case Any::Float: return this->getFloat() / r.getFloat();
			}
			break;
	}
	FIXME("Unsupported operation %s / %s", this->typeInfo().name(), r.typeInfo().name());
	return 0;
}
示例#21
0
void MathInterface::functionAbs(void) {
	Any v = cb->popValue();
	if (v.type() == Any::Float) {
		cb->pushValue(abs(v.getFloat()));
		return;
	}
	cb->pushValue(abs(v.getInt()));
	return;
}
示例#22
0
void MathInterface::functionWrapAngle(void) {
	Any a = cb->popValue();
	if (a.type() == Any::Float) {
		cb->pushValue(wrapAngle(a.getFloat()));
	}
	else { // Has to be int
		cb->pushValue(wrapAngle(a.getInt()));
	}
}
示例#23
0
Any Any::operator << (const Any &r) const {
	if (this->type() == Any::Int && r.type() == Any::Int) {
		int32_t a = this->getInt();
		int32_t b = r.getInt();
		uint32_t ret = *reinterpret_cast<uint32_t*>( &a ) << *reinterpret_cast<uint32_t*>( &b );
		return *reinterpret_cast<int32_t*>( &ret );
	}
	FIXME("Unsupported operation %s << %s", this->typeInfo().name(), r.typeInfo().name());
	return 0;
}
示例#24
0
文件: any.cpp 项目: VMML/Lunchbox
bool Any::operator == ( const Any& rhs ) const
{
    if( (this == &rhs) || (empty() && rhs.empty( )))
        return true;

    if( empty() != rhs.empty() || type() != rhs.type( ))
        return false;

    return *content == *rhs.content;
}
示例#25
0
void AnyTest::testInt()
{
	Any a = 13;
	assert (a.type() == typeid(int));
	int* i = AnyCast<int>(&a);
	assert (*i == 13);
	Any b = a;
	assert (b.type() == typeid(int));
	int *cpyI = AnyCast<int>(&b);
	assert (*cpyI == *i);
	*cpyI = 20;
	assert (*cpyI != *i);
	std::string* s = AnyCast<std::string>(&a);
	assert (s == NULL);

	int tmp = AnyCast<int>(a);
	const Any c = a;
	tmp = AnyCast<int>(a);
}
示例#26
0
void AnyTest::testCopyCtor()
{
	std::string text = "test message";
	Any original = text, copy = original;
	
	assert (!copy.empty());
	assert (original.type() == copy.type());
	assert (AnyCast<std::string>(original) == AnyCast<std::string>(copy));
	assert (text == AnyCast<std::string>(copy));
	assert (AnyCast<std::string>(&original) != AnyCast<std::string>(&copy));
}
示例#27
0
void AnyTest::testConvertingCtor()
{
	std::string text = "test message";
	Any value = text;
	
	assert (!value.empty());
	assert (value.type() == typeid(std::string));
	assert (0 == AnyCast<int>(&value));
	assert (0 != AnyCast<std::string>(&value));
	assert (AnyCast<std::string>(value) == text);
	assert (AnyCast<std::string>(&value) != &text);
}
示例#28
0
void StringInterface::functionStr(void) {
	Any a = cb->popValue();
	switch (a.type()) {
		case Any::Int:
			cb->pushValue(lexical_cast<string>(a.getInt()));
		return;
		case Any::Float:
			cb->pushValue(lexical_cast<string>(a.getFloat()));
		return;
		default:
			cb->pushValue(a);
	}
}
示例#29
0
Vector2int32::Vector2int32(const Any& any) {
    any.verifyName("Vector2int32", "Point2int32");
    any.verifyType(Any::TABLE, Any::ARRAY);
    any.verifySize(2);

    if (any.type() == Any::ARRAY) {
        x = any[0];
        y = any[1];
    } else {
        // Table
        x = any["x"];
        y = any["y"];
    }
}
示例#30
0
void AnyTest::testVector()
{
	std::vector<int> tmp;
	tmp.push_back(1);
	tmp.push_back(2);
	tmp.push_back(3);
	Any a = tmp;
	assert (a.type() == typeid(std::vector<int>));
	std::vector<int>tmp2 = AnyCast<std::vector<int> >(a);
	const std::vector<int >& vecCRef = RefAnyCast<std::vector<int> >(a);
	std::vector<int >& vecRef = RefAnyCast<std::vector<int> >(a);
	vecRef[0] = 0;
	assert (vecRef[0] == vecCRef[0]);
}