CObjectHookGuardBase::CObjectHookGuardBase(const CObjectTypeInfo& info, const string& id, CSkipChoiceVariantHook& hook, CObjectIStream* stream) : m_Hook(&hook), m_HookMode(eHook_Skip), m_HookType(eHook_Variant), m_Id(id) { m_Stream.m_IStream = stream; CObjectTypeInfoVI variant = info.FindVariant(id); if ( stream ) { variant.SetLocalSkipHook(*stream, &hook); } }
CObjectHookGuardBase::CObjectHookGuardBase(const CObjectTypeInfo& info, const string& id, CCopyChoiceVariantHook& hook, CObjectStreamCopier* stream) : m_Hook(&hook), m_HookMode(eHook_Copy), m_HookType(eHook_Variant), m_Id(id) { m_Stream.m_Copier = stream; CObjectTypeInfoVI variant = info.FindVariant(id); if ( stream ) { variant.SetLocalCopyHook(*stream, &hook); } else { variant.SetGlobalCopyHook(&hook); } }
CObjectHookGuardBase::CObjectHookGuardBase(const CObjectTypeInfo& info, const string& id, CWriteChoiceVariantHook& hook, CObjectOStream* stream) : m_Hook(&hook), m_HookMode(eHook_Write), m_HookType(eHook_Variant), m_Id(id) { m_Stream.m_OStream = stream; CObjectTypeInfoVI variant = info.FindVariant(id); if ( stream ) { variant.SetLocalWriteHook(*stream, &hook); } else { variant.SetGlobalWriteHook(&hook); } }
int main(int argc, char** argv) { auto_ptr<CObjectIStream> in(CObjectIStream::Open(eSerial_AsnText, "if")); auto_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, "of")); CObjectTypeInfo typeInfo = CType<CAuth_list>(); CObjectTypeInfoMI memberInfo = typeInfo.FindMember("names"); CObjectTypeInfoVI variantInfo = (*memberInfo).GetPointedType() .FindVariant("std"); variantInfo.SetLocalWriteHook(*out, new CDemoHook); (*CObjectTypeInfo(CType<CAuth_list>()).FindMember("names")) .GetPointedType() .FindVariant("std") .SetLocalWriteHook(*out, new CDemoHook); CCit_art article; *in >> article; *out << article; return 0; }
void CObjectHookGuardBase::ResetHook(const CObjectTypeInfo& info) { switch (m_HookType) { case eHook_Object: switch (m_HookMode) { case eHook_Read: if ( m_Stream.m_IStream ) { info.ResetLocalReadHook(*m_Stream.m_IStream); } else { info.ResetGlobalReadHook(); } break; case eHook_Write: if ( m_Stream.m_OStream ) { info.ResetLocalWriteHook(*m_Stream.m_OStream); } else { info.ResetGlobalWriteHook(); } break; case eHook_Skip: if ( m_Stream.m_IStream ) { info.ResetLocalSkipHook(*m_Stream.m_IStream); } break; case eHook_Copy: if ( m_Stream.m_Copier ) { info.ResetLocalCopyHook(*m_Stream.m_Copier); } else { info.ResetGlobalCopyHook(); } break; default: break; } break; case eHook_Member: { CObjectTypeInfoMI member = info.FindMember(m_Id); switch (m_HookMode) { case eHook_Read: if ( m_Stream.m_IStream ) { member.ResetLocalReadHook(*m_Stream.m_IStream); } else { member.ResetGlobalReadHook(); } break; case eHook_Write: if ( m_Stream.m_OStream ) { member.ResetLocalWriteHook(*m_Stream.m_OStream); } else { member.ResetGlobalWriteHook(); } break; case eHook_Skip: if ( m_Stream.m_IStream ) { member.ResetLocalSkipHook(*m_Stream.m_IStream); } break; case eHook_Copy: if ( m_Stream.m_Copier ) { member.ResetLocalCopyHook(*m_Stream.m_Copier); } else { member.ResetGlobalCopyHook(); } break; default: break; } break; } case eHook_Variant: { CObjectTypeInfoVI variant = info.FindVariant(m_Id); switch (m_HookMode) { case eHook_Read: if ( m_Stream.m_IStream ) { variant.ResetLocalReadHook(*m_Stream.m_IStream); } else { variant.ResetGlobalReadHook(); } break; case eHook_Write: if ( m_Stream.m_OStream ) { variant.ResetLocalWriteHook(*m_Stream.m_OStream); } else { variant.ResetGlobalWriteHook(); } break; case eHook_Skip: if ( m_Stream.m_IStream ) { variant.ResetLocalSkipHook(*m_Stream.m_IStream); } break; case eHook_Copy: if ( m_Stream.m_Copier ) { variant.ResetLocalCopyHook(*m_Stream.m_Copier); } else { variant.ResetGlobalCopyHook(); } break; default: break; } break; } case eHook_Element: case eHook_Null: default: break; } m_HookMode = eHook_None; m_HookType = eHook_Null; }