예제 #1
0
void
FreezeScript::TransformVisitor::visitInteger(const IntegerDataPtr& dest)
{
    Slice::TypePtr type = dest->getType();
    if(_info->doDefaultTransform(type))
    {
        IntegerDataPtr i = IntegerDataPtr::dynamicCast(_src);
        if(i)
        {
            dest->setValue(i->getValue(), false);
        }
        else
        {
            StringDataPtr s = StringDataPtr::dynamicCast(_src);
            if(s)
            {
                string str = s->getValue();
                Ice::Long value;
                if(IceUtil::stringToInt64(str, value))
                {
                    dest->setValue(value, false);
                }
                else
                {
                    conversionError(type, _src->getType(), str);
                }
            }
            else
            {
                typeMismatchError(type, _src->getType());
            }
        }
    }
    _info->executeCustomTransform(dest, _src);
}
예제 #2
0
void
FreezeScript::AssignVisitor::visitEnum(const EnumDataPtr& dest)
{
    Slice::TypePtr type = dest->getType();
    IntegerDataPtr i = IntegerDataPtr::dynamicCast(_src);
    if(i)
    {
        if(_convert)
        {
            Ice::Long l = i->integerValue();
            if(l < 0 || l > INT_MAX || !dest->setValue(static_cast<Ice::Int>(l)))
            {
                rangeError(i->toString(), type);
            }
        }
        else
        {
            conversionError(type, i->getType(), i->toString());
        }
    }
    else
    {
        string name;
        EnumDataPtr e = EnumDataPtr::dynamicCast(_src);
        if(e && isCompatible(type, _src->getType()))
        {
            name = e->toString();
        }
        else
        {
            StringDataPtr s = StringDataPtr::dynamicCast(_src);
            if(s)
            {
                name = s->getValue();
            }
            else
            {
                typeMismatchError(type, _src->getType());
            }
        }

        if(!dest->setValueAsString(name))
        {
            conversionError(type, _src->getType(), name);
        }
    }
}