in Unix/micxx/dinstance.cpp [1612:1960]
bool DInstance::StaticToDynamic(
const Instance& sinst,
bool keysOnly,
DInstance& dinst)
{
// Reject if static instance has no internal instance.
if (!sinst.m_instance)
{
return false;
}
// Get class declaration from static instance.
const MI_ClassDecl* cd = sinst.m_instance->classDecl;
if (!cd)
{
return false;
}
// Create new instance with given class name.
{
MetaType mt;
memset(&mt, 0, sizeof(mt));
if (cd->flags & MI_FLAG_ASSOCIATION)
mt = ASSOCIATION;
else if (cd->flags & MI_FLAG_INDICATION)
mt = INDICATION;
else if (cd->flags & MI_FLAG_METHOD)
mt = METHOD;
else if (cd->flags & MI_FLAG_CLASS)
mt = CLASS;
dinst = DInstance(cd->name, mt);
}
// Convert each property.
for (Uint32 i = 0; i < cd->numProperties; i++)
{
MI_PropertyDecl* pd = cd->properties[i];
bool key = (pd->flags & MI_FLAG_KEY) != 0;
if (!key && keysOnly)
continue;
switch (pd->type)
{
case MI_BOOLEAN:
{
dinst.AddBoolean(
pd->name,
sinst.GetField<Boolean>(pd->offset).value,
!sinst.GetField<Boolean>(pd->offset).exists,
key);
break;
}
case MI_UINT8:
{
dinst.AddUint8(
pd->name,
sinst.GetField<Uint8>(pd->offset).value,
!sinst.GetField<Uint8>(pd->offset).exists,
key);
break;
}
case MI_SINT8:
{
dinst.AddSint8(
pd->name,
sinst.GetField<Sint8>(pd->offset).value,
!sinst.GetField<Sint8>(pd->offset).exists,
key);
break;
}
case MI_UINT16:
{
dinst.AddUint16(
pd->name,
sinst.GetField<Uint16>(pd->offset).value,
!sinst.GetField<Uint16>(pd->offset).exists,
key);
break;
}
case MI_SINT16:
{
dinst.AddSint16(
pd->name,
sinst.GetField<Sint16>(pd->offset).value,
!sinst.GetField<Sint16>(pd->offset).exists,
key);
break;
}
case MI_UINT32:
{
dinst.AddUint32(
pd->name,
sinst.GetField<Uint32>(pd->offset).value,
!sinst.GetField<Uint32>(pd->offset).exists,
key);
break;
}
case MI_SINT32:
{
dinst.AddSint32(
pd->name,
sinst.GetField<Sint32>(pd->offset).value,
!sinst.GetField<Sint32>(pd->offset).exists,
key);
break;
}
case MI_UINT64:
{
dinst.AddUint64(
pd->name,
sinst.GetField<Uint64>(pd->offset).value,
!sinst.GetField<Uint64>(pd->offset).exists,
key);
break;
}
case MI_SINT64:
{
dinst.AddSint64(
pd->name,
sinst.GetField<Sint64>(pd->offset).value,
!sinst.GetField<Sint64>(pd->offset).exists,
key);
break;
}
case MI_REAL32:
{
dinst.AddReal32(
pd->name,
sinst.GetField<Real32>(pd->offset).value,
!sinst.GetField<Real32>(pd->offset).exists,
key);
break;
}
case MI_REAL64:
{
dinst.AddReal64(
pd->name,
sinst.GetField<Real64>(pd->offset).value,
!sinst.GetField<Real64>(pd->offset).exists,
key);
break;
}
case MI_CHAR16:
{
dinst.AddChar16(
pd->name,
sinst.GetField<Char16>(pd->offset).value,
!sinst.GetField<Char16>(pd->offset).exists,
key);
break;
}
case MI_DATETIME:
{
dinst.AddDatetime(
pd->name,
sinst.GetField<Datetime>(pd->offset).value,
!sinst.GetField<Datetime>(pd->offset).exists,
key);
break;
}
case MI_STRING:
{
dinst.AddString(
pd->name,
sinst.GetField<String>(pd->offset).value,
!sinst.GetField<String>(pd->offset).exists,
key);
break;
}
case MI_REFERENCE:
case MI_INSTANCE:
{
DInstance x;
if (!DInstance::StaticToDynamic(
sinst.GetField<Instance>(pd->offset).value,
keysOnly,
x))
{
return false;
}
dinst.AddInstance(
pd->name,
x,
!sinst.GetField<Instance>(pd->offset).exists,
key);
break;
}
case MI_BOOLEANA:
{
dinst.AddBooleanA(
pd->name,
sinst.GetField<BooleanA>(pd->offset).value,
!sinst.GetField<BooleanA>(pd->offset).exists,
key);
break;
}
case MI_UINT8A:
{
dinst.AddUint8A(
pd->name,
sinst.GetField<Uint8A>(pd->offset).value,
!sinst.GetField<Uint8A>(pd->offset).exists,
key);
break;
}
case MI_SINT8A:
{
dinst.AddSint8A(
pd->name,
sinst.GetField<Sint8A>(pd->offset).value,
!sinst.GetField<Sint8A>(pd->offset).exists,
key);
break;
}
case MI_UINT16A:
{
dinst.AddUint16A(
pd->name,
sinst.GetField<Uint16A>(pd->offset).value,
!sinst.GetField<Uint16A>(pd->offset).exists,
key);
break;
}
case MI_SINT16A:
{
dinst.AddSint16A(
pd->name,
sinst.GetField<Sint16A>(pd->offset).value,
!sinst.GetField<Sint16A>(pd->offset).exists,
key);
break;
}
case MI_UINT32A:
{
dinst.AddUint32A(
pd->name,
sinst.GetField<Uint32A>(pd->offset).value,
!sinst.GetField<Uint32A>(pd->offset).exists,
key);
break;
}
case MI_SINT32A:
{
dinst.AddSint32A(
pd->name,
sinst.GetField<Sint32A>(pd->offset).value,
!sinst.GetField<Sint32A>(pd->offset).exists,
key);
break;
}
case MI_UINT64A:
{
dinst.AddUint64A(
pd->name,
sinst.GetField<Uint64A>(pd->offset).value,
!sinst.GetField<Uint64A>(pd->offset).exists,
key);
break;
}
case MI_SINT64A:
{
dinst.AddSint64A(
pd->name,
sinst.GetField<Sint64A>(pd->offset).value,
!sinst.GetField<Sint64A>(pd->offset).exists,
key);
break;
}
case MI_REAL32A:
{
dinst.AddReal32A(
pd->name,
sinst.GetField<Real32A>(pd->offset).value,
!sinst.GetField<Real32A>(pd->offset).exists,
key);
break;
}
case MI_REAL64A:
{
dinst.AddReal64A(
pd->name,
sinst.GetField<Real64A>(pd->offset).value,
!sinst.GetField<Real64A>(pd->offset).exists,
key);
break;
}
case MI_CHAR16A:
{
dinst.AddChar16A(
pd->name,
sinst.GetField<Char16A>(pd->offset).value,
!sinst.GetField<Char16A>(pd->offset).exists,
key);
break;
}
case MI_DATETIMEA:
{
dinst.AddDatetimeA(
pd->name,
sinst.GetField<DatetimeA>(pd->offset).value,
!sinst.GetField<DatetimeA>(pd->offset).exists,
key);
break;
}
case MI_STRINGA:
{
dinst.AddStringA(
pd->name,
sinst.GetField<StringA>(pd->offset).value,
!sinst.GetField<StringA>(pd->offset).exists,
key);
break;
}
case MI_REFERENCEA:
case MI_INSTANCEA:
{
Array<DInstance> da;
const Array<Instance>& sa =
sinst.GetField<InstanceA>(pd->offset).value;
for (Uint32 index = 0; index < sa.GetSize(); index++)
{
DInstance x;
if (!DInstance::StaticToDynamic( sa[index], keysOnly, x))
return false;
da.PushBack(x);
}
dinst.AddInstanceA(
pd->name,
da,
!sinst.GetField<InstanceA>(pd->offset).exists,
key);
break;
}
default:
break;
}
}
return true;
}