LevelFactory * TransformationFactoryDataModel::InternalRead(ifstream * stream, map<string, LevelFactory*>* previousFactories)
	{
		// Name of the subLevelFactory to be read in the file.
		string subLevelFactoryName;
		// Get the string name of the sublevel factory.
		getline(*stream, subLevelFactoryName);
		// Get the sublevel factory according to its name, if it exist.
		LevelFactory* subLevelFactory = GetFactoryByName(subLevelFactoryName, previousFactories);

		// The sublevel has to exist.
		if (subLevelFactory == NULL)
		{
			throw new std::invalid_argument("A transformation factory should always have a sublevel.");
		}

		// Descriptor of the matrix constructor to read and use.
		string matrixConstructor;
		// Get the matrix constructor.
		getline(*stream, matrixConstructor);

		// Final transformation matrix.
		Matrix4 transformation;

		if (matrixConstructor == "Matrix")
		{
			transformation = ReadMatrix4(stream);
		}
		else if(matrixConstructor == "YRotation")
		{
			transformation = ReadYRotation(stream);
		}
		else if (matrixConstructor == "Translation")
		{
			transformation = ReadTranslation(stream);
		}
		else
		{
			throw new std::exception("Invalid constructor specified.");
		}

		return new TransformationFactory(subLevelFactory, transformation);
	}
Exemple #2
0
Variant Deserializer::ReadVariant(VariantType type)
{
    switch (type)
    {
    case VAR_INT:
        return Variant(ReadInt());

    case VAR_BOOL:
        return Variant(ReadBool());

    case VAR_FLOAT:
        return Variant(ReadFloat());

    case VAR_VECTOR2:
        return Variant(ReadVector2());

    case VAR_VECTOR3:
        return Variant(ReadVector3());

    case VAR_VECTOR4:
        return Variant(ReadVector4());

    case VAR_QUATERNION:
        return Variant(ReadQuaternion());

    case VAR_COLOR:
        return Variant(ReadColor());

    case VAR_STRING:
        return Variant(ReadString());

    case VAR_BUFFER:
        return Variant(ReadBuffer());

        // Deserializing pointers is not supported. Return null
    case VAR_VOIDPTR:
    case VAR_PTR:
        ReadUInt();
        return Variant((void*)0);

    case VAR_RESOURCEREF:
        return Variant(ReadResourceRef());

    case VAR_RESOURCEREFLIST:
        return Variant(ReadResourceRefList());

    case VAR_VARIANTVECTOR:
        return Variant(ReadVariantVector());

    case VAR_STRINGVECTOR:
        return Variant(ReadStringVector());

    case VAR_VARIANTMAP:
        return Variant(ReadVariantMap());

    case VAR_INTRECT:
        return Variant(ReadIntRect());

    case VAR_INTVECTOR2:
        return Variant(ReadIntVector2());

    case VAR_MATRIX3:
        return Variant(ReadMatrix3());

    case VAR_MATRIX3X4:
        return Variant(ReadMatrix3x4());

    case VAR_MATRIX4:
        return Variant(ReadMatrix4());

    case VAR_DOUBLE:
        return Variant(ReadDouble());

    default:
        return Variant();
    }
}