示例#1
0
文件: variant.cpp 项目: renokun/Aspen
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."));
        }
}
示例#2
0
文件: variant.cpp 项目: renokun/Aspen
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;
}
示例#3
0
文件: variant.cpp 项目: renokun/Aspen
Variant Variant::operator %(Variant var)
{
    if ((var.Typeof() == VAR_INT) && (type == VAR_INT))
        {
            return Variant(i32 % var.GetInt());
        }
    else
        {
            throw(InvalidVariableTypeException("Tried to get modulous of illegal value."));
        }
}
示例#4
0
文件: variant.cpp 项目: renokun/Aspen
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."));
        }
}
示例#5
0
文件: variant.cpp 项目: renokun/Aspen
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;
        }
}
示例#6
0
文件: variant.cpp 项目: renokun/Aspen
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."));
        }
}