示例#1
0
void CChoiceTypeInfoFunctions::WriteChoiceDefault(CObjectOStream& out,
        TTypeInfo objectType,
        TConstObjectPtr objectPtr)
{
    const CChoiceTypeInfo* choiceType =
        CTypeConverter<CChoiceTypeInfo>::SafeCast(objectType);

    BEGIN_OBJECT_FRAME_OF3(out, eFrameChoice, choiceType, objectPtr);
    out.BeginChoice(choiceType);
    TMemberIndex index = choiceType->GetVariants().FirstIndex();
    const CVariantInfo* variantInfo = choiceType->GetVariantInfo(index);
    if (variantInfo->GetId().IsAttlist()) {
        const CMemberInfo* memberInfo =
            dynamic_cast<const CMemberInfo*>(
                choiceType->GetVariants().GetItemInfo(index));
        memberInfo->WriteMember(out,objectPtr);
    }

    index = choiceType->GetIndex(objectPtr);
    if ( index == kInvalidMember )
        out.ThrowError(out.fInvalidData, "cannot write empty choice");

    variantInfo = choiceType->GetVariantInfo(index);
    BEGIN_OBJECT_FRAME_OF2(out, eFrameChoiceVariant, variantInfo->GetId());
    out.BeginChoiceVariant(choiceType, variantInfo->GetId());

    variantInfo->WriteVariant(out, objectPtr);

    out.EndChoiceVariant();
    END_OBJECT_FRAME_OF(out);
    out.EndChoice();
    END_OBJECT_FRAME_OF(out);
}
示例#2
0
 static void Write(CObjectOStream& out, TTypeInfo ,
                   TConstObjectPtr objectPtr)
     {
         if ( objectPtr != 0 ) {
             out.ThrowError(out.fInvalidData,
                 "non-null value when writing NULL member");
         }
         out.WriteNull();
     }