Example #1
0
Variant Variant::operator /(Variant var)
{
    VARIABLE_TYPE vtype = var.Typeof();

    switch(type)
        {
        case VAR_INT:
            switch(vtype)
                {
                case VAR_INT:
                    return Variant(i32 / var.GetInt());
                case VAR_DOUBLE:
                    return Variant(i32 / var.GetDouble());
                default:
                    throw(InvalidVariableTypeException("Tried to divide illegal value."));
                }
        case VAR_DOUBLE:
            switch(vtype)
                {
                case VAR_INT:
                    return Variant(d / var.GetInt());
                case VAR_DOUBLE:
                    return Variant(d / var.GetDouble());
                default:
                    throw(InvalidVariableTypeException("Tried to divide illegal value."));
                }
        default:
            throw(InvalidVariableTypeException("Tried to divide illegal value."));
        }
}
Variant ValueAnimation::SubstractAndMultiply(const Variant& value1, const Variant& value2, float t) const
{
    switch (valueType_)
    {
    case VAR_FLOAT:
        return (value1.GetFloat() - value2.GetFloat()) * t;

    case VAR_VECTOR2:
        return (value1.GetVector2() - value2.GetVector2()) * t;

    case VAR_VECTOR3:
        return (value1.GetVector3() - value2.GetVector3()) * t;

    case VAR_VECTOR4:
        return (value1.GetVector4() - value2.GetVector4()) * t;

    case VAR_QUATERNION:
        return (value1.GetQuaternion() - value2.GetQuaternion()) * t;

    case VAR_COLOR:
        return (value1.GetColor() - value2.GetColor()) * t;

    case VAR_DOUBLE:
        return (value1.GetDouble() - value2.GetDouble()) * t;

    default:
        ATOMIC_LOGERROR("Invalid value type for spline interpolation's subtract and multiply operation");
        return Variant::EMPTY;
    }
}
Example #3
0
BOOL Variant::Compare(const Variant &var) const
{
    VARIABLE_TYPE vtype = var.Typeof();
    switch(type)
        {
        case VAR_STR:
            switch(vtype)
                {
                case VAR_STR:
                    return (str == var.GetStr()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare a string with an illegal value."));
                }
        case VAR_INT:
            switch(vtype)
                {
                case VAR_INT:
                    return (i32 == var.GetInt()?1:0);
                case VAR_DOUBLE:
                    return (i32 == (int)var.GetDouble()?1:0);
                case VAR_BYTE:
                    return (i32 == var.GetByte()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare integer with an illegal type."));
                }
        case VAR_DOUBLE:
            switch(vtype)
                {
                case VAR_INT:
                    return ((int)d == var.GetInt()?1:0);
                case VAR_DOUBLE:
                    return d==var.GetDouble();
                case VAR_BYTE:
                    return ((char)d == var.GetByte()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare double with an illegal type."));
                }
        case VAR_BYTE:
            switch(vtype)
                {
                case VAR_INT:
                    return (byte == var.GetInt()?1:0);
                case VAR_DOUBLE:
                    return (byte == (char)var.GetDouble()?1:0);
                case VAR_BYTE:
                    return (byte == var.GetByte()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare byte with an illegal type."));
                }
        default:
            throw(InvalidVariableTypeException("Tried to compare with an illegal type."));
        }

    return false;
}
Example #4
0
bool Variant::operator >(Variant var)
{
    VARIABLE_TYPE vtype = var.Typeof();
    switch(type)
        {
        case VAR_STR:
            switch(vtype)
                {
                case VAR_STR:
                    return (str > var.GetStr()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare a string with an illegal value."));
                }
        case VAR_INT:
            switch(vtype)
                {
                case VAR_INT:
                    return (i32 > var.GetInt()?1:0);
                case VAR_DOUBLE:
                    return (i32 > var.GetDouble()?1:0);
                case VAR_BYTE:
                    return (i32 > var.GetByte()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare integer with an illegal type."));
                }
        case VAR_DOUBLE:
            switch(vtype)
                {
                case VAR_INT:
                    return (d > var.GetInt()?1:0);
                case VAR_DOUBLE:
                    return (d > var.GetDouble()?1:0);
                case VAR_BYTE:
                    return (d > var.GetByte()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare double with an illegal type."));
                }
        case VAR_BYTE:
            switch(vtype)
                {
                case VAR_INT:
                    return (byte > var.GetInt()?1:0);
                case VAR_DOUBLE:
                    return (byte > var.GetDouble()?1:0);
                case VAR_BYTE:
                    return (byte > var.GetByte()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare byte with an illegal type."));
                }
        default:
            throw(InvalidVariableTypeException("Tried to compare with an illegal type."));
        }
}
Variant Spline::LinearInterpolation(const Variant& lhs, const Variant& rhs, float t) const
{
    switch (lhs.GetType())
    {
    case VAR_FLOAT:
        return Lerp(lhs.GetFloat(), rhs.GetFloat(), t);
    case VAR_VECTOR2:
        return lhs.GetVector2().Lerp(rhs.GetVector2(), t);
    case VAR_VECTOR3:
        return lhs.GetVector3().Lerp(rhs.GetVector3(), t);
    case VAR_VECTOR4:
        return lhs.GetVector4().Lerp(rhs.GetVector4(), t);
    case VAR_COLOR:
        return lhs.GetColor().Lerp(rhs.GetColor(), t);
    case VAR_DOUBLE:
        return Lerp(lhs.GetDouble(), rhs.GetDouble(), t);
    default:
        return Variant::EMPTY;
    }
}
Example #6
0
Variant::Variant(const Variant& var)
{
    type = var.Typeof();
    switch(type)
        {
        case VAR_BYTE:
            byte = var.GetByte();
            break;
        case VAR_INT:
            i32=var.GetInt();
            break;
        case VAR_DOUBLE:
            d=var.GetDouble();
            break;
        case VAR_STR:
            str=var.GetStr();;
        case VAR_EMPTY:
        default:
            break;
        }
}
Example #7
0
void JSONValue::SetVariantValue(const Variant& variant, Context* context)
{
    if (!IsNull())
    {
        LOGWARNING("JsonValue is not null");
    }

    switch (variant.GetType())
    {
    case VAR_BOOL:
        *this = variant.GetBool();
        return;
    
    case VAR_INT:
        *this = variant.GetInt();
        return;

    case VAR_FLOAT:
        *this = variant.GetFloat();
        return;

    case VAR_DOUBLE:
        *this = variant.GetDouble();
        return;

    case VAR_STRING:
        *this = variant.GetString();
        return;

    case VAR_VARIANTVECTOR:
        SetVariantVector(variant.GetVariantVector(), context);
        return;

    case VAR_VARIANTMAP:
        SetVariantMap(variant.GetVariantMap(), context);
        return;

    case VAR_RESOURCEREF:
        {
            if (!context)
            {
                LOGERROR("Context must not null for ResourceRef");
                return;
            }

            const ResourceRef& ref = variant.GetResourceRef();
            *this = String(context->GetTypeName(ref.type_)) + ";" + ref.name_;
        }
        return;

    case VAR_RESOURCEREFLIST:
        {
            if (!context)
            {
                LOGERROR("Context must not null for ResourceRefList");
                return;
            }

            const ResourceRefList& refList = variant.GetResourceRefList();
            String str(context->GetTypeName(refList.type_));
            for (unsigned i = 0; i < refList.names_.Size(); ++i)
            {
                str += ";";
                str += refList.names_[i];
            }
            *this = str;
        }
        return;

    case VAR_STRINGVECTOR:
        {
            const StringVector& vector = variant.GetStringVector();
            Resize(vector.Size());
            for (unsigned i = 0; i < vector.Size(); ++i)
                (*this)[i] = vector[i];
        }
        return;

    default:
        *this = variant.ToString();
    }
}
Example #8
0
Variant Variant::operator +(Variant var)
{
    VARIABLE_TYPE vtype = var.Typeof();

    switch(type)
        {
//string
        case VAR_STR:
            switch(vtype)
                {
                case VAR_STR:
                    return Variant(str+var.GetStr());
                case VAR_BYTE:
                    return Variant(str+var.GetByte());
                case VAR_INT:
                    return Variant(str+std::to_string(var.GetInt()));
                case VAR_DOUBLE:
                    return Variant(str + std::to_string(var.GetDouble()));
                default:
                    throw(VariableEmptyException("Tried to add an empty variant to another variant."));
                }
//integer
        case VAR_INT:
            switch(vtype)
                {
                case VAR_INT:
                    return Variant(i32 + var.GetInt());
                case VAR_DOUBLE:
                    return Variant(i32 + var.GetDouble());
                case VAR_BYTE:
                    return Variant(i32 + var.GetByte());
                case VAR_STR:
                    throw(InvalidVariableTypeException("Tried to add a string to an integer."));
                default:
                    throw(VariableEmptyException("Tried to add an empty variant to another variant."));
                }
//double
        case VAR_DOUBLE:
            switch(vtype)
                {
                case VAR_DOUBLE:
                    return Variant(d + var.GetDouble());
                case VAR_INT:
                    return Variant(d + var.GetInt());
                case VAR_BYTE:
                    throw(InvalidVariableTypeException("Tried to add byte to double."));
                case VAR_STR:
                    throw(InvalidVariableTypeException("Tried to add a string to a double."));
                default:
                    throw(VariableEmptyException("Tried to add an empty variant to another variant."));
                }
//byte
        case VAR_BYTE:
            switch(vtype)
                {
                case VAR_INT:
                    return Variant(byte + var.GetInt());
                case VAR_BYTE:
                    return Variant(byte + var.GetByte());
                default:
                    throw(InvalidVariableTypeException("Tried to add byte to an illegal value."));
                }
        default:
            throw(InvalidVariableTypeException("Tried to add empty variable."));
        }
}