Exemplo n.º 1
0
void
FreezeScript::TransformVisitor::visitEnum(const EnumDataPtr& dest)
{
    Slice::TypePtr type = dest->getType();
    if(_info->doDefaultTransform(type))
    {
        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());
                return;
            }
        }

        if(!dest->setValueAsString(name))
        {
            conversionError(type, _src->getType(), name);
        }
    }
    _info->executeCustomTransform(dest, _src);
}
Exemplo n.º 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);
        }
    }
}