member.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:48k
源码类别:

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: member.cpp,v $
  4.  * PRODUCTION Revision 1000.3  2004/06/01 19:40:26  gouriano
  5.  * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.38
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. /*  $Id: member.cpp,v 1000.3 2004/06/01 19:40:26 gouriano Exp $
  10. * ===========================================================================
  11. *
  12. *                            PUBLIC DOMAIN NOTICE
  13. *               National Center for Biotechnology Information
  14. *
  15. *  This software/database is a "United States Government Work" under the
  16. *  terms of the United States Copyright Act.  It was written as part of
  17. *  the author's official duties as a United States Government employee and
  18. *  thus cannot be copyrighted.  This software/database is freely available
  19. *  to the public for use. The National Library of Medicine and the U.S.
  20. *  Government have not placed any restriction on its use or reproduction.
  21. *
  22. *  Although all reasonable efforts have been taken to ensure the accuracy
  23. *  and reliability of the software and data, the NLM and the U.S.
  24. *  Government do not and cannot warrant the performance or results that
  25. *  may be obtained by using this software or data. The NLM and the U.S.
  26. *  Government disclaim all warranties, express or implied, including
  27. *  warranties of performance, merchantability or fitness for any particular
  28. *  purpose.
  29. *
  30. *  Please cite the author in any work or product based on this material.
  31. *
  32. * ===========================================================================
  33. *
  34. * Author: Eugene Vasilchenko
  35. *
  36. * File Description:
  37. *   !!! PUT YOUR DESCRIPTION HERE !!!
  38. *
  39. * ===========================================================================
  40. */
  41. #include <ncbi_pch.hpp>
  42. #include <corelib/ncbistd.hpp>
  43. #include <corelib/ncbimtx.hpp>
  44. #include <serial/member.hpp>
  45. #include <serial/objectinfo.hpp>
  46. #include <serial/objectiter.hpp>
  47. #include <serial/objistr.hpp>
  48. #include <serial/objostr.hpp>
  49. #include <serial/objcopy.hpp>
  50. #include <serial/delaybuf.hpp>
  51. #include <serial/serialimpl.hpp>
  52. #ifdef _DEBUG
  53. #include <serial/serialbase.hpp>
  54. #endif
  55. #include <memory>
  56. BEGIN_NCBI_SCOPE
  57. class CMemberInfoFunctions
  58. {
  59. public:
  60.     static TConstObjectPtr GetConstSimpleMember(const CMemberInfo* memberInfo,
  61.                                                 TConstObjectPtr classPtr);
  62.     static TConstObjectPtr GetConstDelayedMember(const CMemberInfo* memberInfo,
  63.                                                  TConstObjectPtr classPtr);
  64.     static TObjectPtr GetSimpleMember(const CMemberInfo* memberInfo,
  65.                                       TObjectPtr classPtr);
  66.     static TObjectPtr GetWithSetFlagMember(const CMemberInfo* memberInfo,
  67.                                            TObjectPtr classPtr);
  68.     static TObjectPtr GetDelayedMember(const CMemberInfo* memberInfo,
  69.                                        TObjectPtr classPtr);
  70.     
  71.     static void ReadSimpleMember(CObjectIStream& in,
  72.                                  const CMemberInfo* memberInfo,
  73.                                  TObjectPtr classPtr);
  74.     static void ReadWithSetFlagMember(CObjectIStream& in,
  75.                                         const CMemberInfo* memberInfo,
  76.                                         TObjectPtr classPtr);
  77.     static void ReadLongMember(CObjectIStream& in,
  78.                                  const CMemberInfo* memberInfo,
  79.                                  TObjectPtr classPtr);
  80.     static void ReadHookedMember(CObjectIStream& in,
  81.                                  const CMemberInfo* memberInfo,
  82.                                  TObjectPtr classPtr);
  83.     static void ReadMissingSimpleMember(CObjectIStream& in,
  84.                                         const CMemberInfo* memberInfo,
  85.                                         TObjectPtr classPtr);
  86.     static void ReadMissingWithSetFlagMember(CObjectIStream& in,
  87.                                              const CMemberInfo* memberInfo,
  88.                                              TObjectPtr classPtr);
  89.     static void ReadMissingOptionalMember(CObjectIStream& in,
  90.                                             const CMemberInfo* memberInfo,
  91.                                             TObjectPtr classPtr);
  92.     static void ReadMissingHookedMember(CObjectIStream& in,
  93.                                         const CMemberInfo* memberInfo,
  94.                                         TObjectPtr classPtr);
  95.     static void WriteSimpleMember(CObjectOStream& out,
  96.                                   const CMemberInfo* memberInfo,
  97.                                   TConstObjectPtr classPtr);
  98.     static void WriteOptionalMember(CObjectOStream& out,
  99.                                       const CMemberInfo* memberInfo,
  100.                                       TConstObjectPtr classPtr);
  101.     static void WriteWithDefaultMember(CObjectOStream& out,
  102.                                          const CMemberInfo* memberInfo,
  103.                                          TConstObjectPtr classPtr);
  104.     static void WriteWithSetFlagMember(CObjectOStream& out,
  105.                                          const CMemberInfo* memberInfo,
  106.                                          TConstObjectPtr classPtr);
  107.     static void WriteLongMember(CObjectOStream& out,
  108.                                   const CMemberInfo* memberInfo,
  109.                                   TConstObjectPtr classPtr);
  110.     static void WriteHookedMember(CObjectOStream& out,
  111.                                   const CMemberInfo* memberInfo,
  112.                                   TConstObjectPtr classPtr);
  113.     static void SkipSimpleMember(CObjectIStream& in,
  114.                                  const CMemberInfo* memberInfo);
  115.     static void SkipMissingSimpleMember(CObjectIStream& in,
  116.                                         const CMemberInfo* memberInfo);
  117.     static void SkipMissingOptionalMember(CObjectIStream& in,
  118.                                           const CMemberInfo* memberInfo);
  119.     static void SkipHookedMember(CObjectIStream& in,
  120.                                  const CMemberInfo* memberInfo);
  121.     static void SkipMissingHookedMember(CObjectIStream& in,
  122.                                         const CMemberInfo* memberInfo);
  123.     static void CopySimpleMember(CObjectStreamCopier& copier,
  124.                                  const CMemberInfo* memberInfo);
  125.     static void CopyHookedMember(CObjectStreamCopier& copier,
  126.                                  const CMemberInfo* memberInfo);
  127.     static void CopyMissingSimpleMember(CObjectStreamCopier& copier,
  128.                                         const CMemberInfo* memberInfo);
  129.     static void CopyMissingOptionalMember(CObjectStreamCopier& copier,
  130.                                             const CMemberInfo* memberInfo);
  131.     static void CopyMissingHookedMember(CObjectStreamCopier& copier,
  132.                                         const CMemberInfo* memberInfo);
  133.     static void ReadParentClass(CObjectIStream& in,
  134.                                 const CMemberInfo* memberInfo,
  135.                                 TObjectPtr objectPtr);
  136.     static void ReadMissingParentClass(CObjectIStream& in,
  137.                                        const CMemberInfo* memberInfo,
  138.                                        TObjectPtr objectPtr);
  139.     static void WriteParentClass(CObjectOStream& out,
  140.                                  const CMemberInfo* memberInfo,
  141.                                  TConstObjectPtr objectPtr);
  142.     static void CopyParentClass(CObjectStreamCopier& copier,
  143.                                 const CMemberInfo* memberInfo);
  144.     static void CopyMissingParentClass(CObjectStreamCopier& copier,
  145.                                        const CMemberInfo* memberInfo);
  146.     static void SkipParentClass(CObjectIStream& in,
  147.                                 const CMemberInfo* memberInfo);
  148.     static void SkipMissingParentClass(CObjectIStream& in,
  149.                                        const CMemberInfo* memberInfo);
  150. };
  151. typedef CMemberInfoFunctions TFunc;
  152. CMemberInfo::CMemberInfo(const CClassTypeInfoBase* classType,
  153.                          const CMemberId& id, TPointerOffsetType offset,
  154.                          const CTypeRef& type)
  155.     : CParent(id, offset, type),
  156.       m_ClassType(classType), m_Optional(false), m_NonEmpty(false), m_Default(0),
  157.       m_SetFlagOffset(eNoOffset), m_BitSetFlag(false),
  158.       m_DelayOffset(eNoOffset),
  159.       m_GetConstFunction(&TFunc::GetConstSimpleMember),
  160.       m_GetFunction(&TFunc::GetSimpleMember),
  161.       m_ReadHookData(SMemberReadFunctions(&TFunc::ReadSimpleMember,
  162.                                           &TFunc::ReadMissingSimpleMember),
  163.                      SMemberReadFunctions(&TFunc::ReadHookedMember,
  164.                                           &TFunc::ReadMissingHookedMember)),
  165.       m_WriteHookData(&TFunc::WriteSimpleMember, &TFunc::WriteHookedMember),
  166.       m_SkipHookData(SMemberSkipFunctions(&TFunc::SkipSimpleMember,
  167.                                           &TFunc::SkipMissingSimpleMember),
  168.                      SMemberSkipFunctions(&TFunc::SkipHookedMember,
  169.                                           &TFunc::SkipMissingHookedMember)),
  170.       m_CopyHookData(SMemberCopyFunctions(&TFunc::CopySimpleMember,
  171.                                           &TFunc::CopyMissingSimpleMember),
  172.                      SMemberCopyFunctions(&TFunc::CopyHookedMember,
  173.                                           &TFunc::CopyMissingHookedMember))
  174. {
  175. }
  176. CMemberInfo::CMemberInfo(const CClassTypeInfoBase* classType,
  177.                          const CMemberId& id, TPointerOffsetType offset,
  178.                          TTypeInfo type)
  179.     : CParent(id, offset, type),
  180.       m_ClassType(classType), m_Optional(false), m_NonEmpty(false), m_Default(0),
  181.       m_SetFlagOffset(eNoOffset), m_BitSetFlag(false),
  182.       m_DelayOffset(eNoOffset),
  183.       m_GetConstFunction(&TFunc::GetConstSimpleMember),
  184.       m_GetFunction(&TFunc::GetSimpleMember),
  185.       m_ReadHookData(SMemberReadFunctions(&TFunc::ReadSimpleMember,
  186.                                           &TFunc::ReadMissingSimpleMember),
  187.                      SMemberReadFunctions(&TFunc::ReadHookedMember,
  188.                                           &TFunc::ReadMissingHookedMember)),
  189.       m_WriteHookData(&TFunc::WriteSimpleMember, &TFunc::WriteHookedMember),
  190.       m_SkipHookData(SMemberSkipFunctions(&TFunc::SkipSimpleMember,
  191.                                           &TFunc::SkipMissingSimpleMember),
  192.                      SMemberSkipFunctions(&TFunc::SkipHookedMember,
  193.                                           &TFunc::SkipMissingHookedMember)),
  194.       m_CopyHookData(SMemberCopyFunctions(&TFunc::CopySimpleMember,
  195.                                           &TFunc::CopyMissingSimpleMember),
  196.                      SMemberCopyFunctions(&TFunc::CopyHookedMember,
  197.                                           &TFunc::CopyMissingHookedMember))
  198. {
  199. }
  200. CMemberInfo::CMemberInfo(const CClassTypeInfoBase* classType,
  201.                          const char* id, TPointerOffsetType offset,
  202.                          const CTypeRef& type)
  203.     : CParent(id, offset, type),
  204.       m_ClassType(classType), m_Optional(false), m_NonEmpty(false), m_Default(0),
  205.       m_SetFlagOffset(eNoOffset), m_BitSetFlag(false),
  206.       m_DelayOffset(eNoOffset),
  207.       m_GetConstFunction(&TFunc::GetConstSimpleMember),
  208.       m_GetFunction(&TFunc::GetSimpleMember),
  209.       m_ReadHookData(SMemberReadFunctions(&TFunc::ReadSimpleMember,
  210.                                           &TFunc::ReadMissingSimpleMember),
  211.                      SMemberReadFunctions(&TFunc::ReadHookedMember,
  212.                                           &TFunc::ReadMissingHookedMember)),
  213.       m_WriteHookData(&TFunc::WriteSimpleMember, &TFunc::WriteHookedMember),
  214.       m_SkipHookData(SMemberSkipFunctions(&TFunc::SkipSimpleMember,
  215.                                           &TFunc::SkipMissingSimpleMember),
  216.                      SMemberSkipFunctions(&TFunc::SkipHookedMember,
  217.                                           &TFunc::SkipMissingHookedMember)),
  218.       m_CopyHookData(SMemberCopyFunctions(&TFunc::CopySimpleMember,
  219.                                           &TFunc::CopyMissingSimpleMember),
  220.                      SMemberCopyFunctions(&TFunc::CopyHookedMember,
  221.                                           &TFunc::CopyMissingHookedMember))
  222. {
  223. }
  224. CMemberInfo::CMemberInfo(const CClassTypeInfoBase* classType,
  225.                          const char* id, TPointerOffsetType offset,
  226.                          TTypeInfo type)
  227.     : CParent(id, offset, type),
  228.       m_ClassType(classType), m_Optional(false), m_NonEmpty(false), m_Default(0),
  229.       m_SetFlagOffset(eNoOffset), m_BitSetFlag(false),
  230.       m_DelayOffset(eNoOffset),
  231.       m_GetConstFunction(&TFunc::GetConstSimpleMember),
  232.       m_GetFunction(&TFunc::GetSimpleMember),
  233.       m_ReadHookData(SMemberReadFunctions(&TFunc::ReadSimpleMember,
  234.                                           &TFunc::ReadMissingSimpleMember),
  235.                      SMemberReadFunctions(&TFunc::ReadHookedMember,
  236.                                           &TFunc::ReadMissingHookedMember)),
  237.       m_WriteHookData(&TFunc::WriteSimpleMember, &TFunc::WriteHookedMember),
  238.       m_SkipHookData(SMemberSkipFunctions(&TFunc::SkipSimpleMember,
  239.                                           &TFunc::SkipMissingSimpleMember),
  240.                      SMemberSkipFunctions(&TFunc::SkipHookedMember,
  241.                                           &TFunc::SkipMissingHookedMember)),
  242.       m_CopyHookData(SMemberCopyFunctions(&TFunc::CopySimpleMember,
  243.                                           &TFunc::CopyMissingSimpleMember),
  244.                      SMemberCopyFunctions(&TFunc::CopyHookedMember,
  245.                                           &TFunc::CopyMissingHookedMember))
  246. {
  247. }
  248. void CMemberInfo::SetParentClass(void)
  249. {
  250.     GetId().SetParentTag();
  251.     m_ReadHookData.SetDefaultFunction(
  252.         SMemberReadFunctions(&TFunc::ReadParentClass,
  253.                              &TFunc::ReadMissingParentClass));
  254.     m_WriteHookData.SetDefaultFunction(&TFunc::WriteParentClass);
  255.     m_SkipHookData.SetDefaultFunction(
  256.         SMemberSkipFunctions(&TFunc::SkipParentClass,
  257.                              &TFunc::SkipMissingParentClass));
  258.     m_CopyHookData.SetDefaultFunction(
  259.         SMemberCopyFunctions(&TFunc::CopyParentClass,
  260.                              &TFunc::CopyMissingParentClass));
  261. }
  262. CMemberInfo* CMemberInfo::SetDelayBuffer(CDelayBuffer* buffer)
  263. {
  264.     m_DelayOffset = TPointerOffsetType(buffer);
  265.     UpdateFunctions();
  266.     return this;
  267. }
  268. CMemberInfo* CMemberInfo::SetOptional(void)
  269. {
  270.     m_Optional = true;
  271.     UpdateFunctions();
  272.     return this;
  273. }
  274. CMemberInfo* CMemberInfo::SetNonEmpty(void)
  275. {
  276.     m_NonEmpty = true;
  277.     return this;
  278. }
  279. CMemberInfo* CMemberInfo::SetNoPrefix(void)
  280. {
  281.     GetId().SetNoPrefix();
  282.     return this;
  283. }
  284. CMemberInfo* CMemberInfo::SetAttlist(void)
  285. {
  286.     GetId().SetAttlist();
  287.     return this;
  288. }
  289. CMemberInfo* CMemberInfo::SetNotag(void)
  290. {
  291.     GetId().SetNotag();
  292.     return this;
  293. }
  294. CMemberInfo* CMemberInfo::SetAnyContent(void)
  295. {
  296.     GetId().SetAnyContent();
  297.     return this;
  298. }
  299. CMemberInfo* CMemberInfo::SetDefault(TConstObjectPtr def)
  300. {
  301.     m_Optional = true;
  302.     m_Default = def;
  303.     UpdateFunctions();
  304.     return this;
  305. }
  306. CMemberInfo* CMemberInfo::SetSetFlag(const bool* setFlag)
  307. {
  308.     _ASSERT(Optional());
  309.     m_SetFlagOffset = TPointerOffsetType(setFlag);
  310.     m_BitSetFlag = false;
  311.     UpdateFunctions();
  312.     return this;
  313. }
  314. CMemberInfo* CMemberInfo::SetSetFlag(const Uint4* setFlag)
  315. {
  316.     m_SetFlagOffset = TPointerOffsetType(setFlag);
  317.     m_BitSetFlag = true;
  318.     UpdateFunctions();
  319.     return this;
  320. }
  321. bool CMemberInfo::CompareSetFlags(TConstObjectPtr object1,
  322.                                   TConstObjectPtr object2) const
  323. {
  324.     return GetSetFlagNo(object1) == GetSetFlagNo(object2);
  325. }
  326. CMemberInfo* CMemberInfo::SetOptional(const bool* setFlag)
  327. {
  328.     m_Optional = true;
  329.     return SetSetFlag(setFlag);
  330. }
  331. void CMemberInfo::UpdateFunctions(void)
  332. {
  333.     // determine function pointers
  334.     TMemberGetConst getConstFunc;
  335.     TMemberGet getFunc;
  336.     SMemberReadFunctions readFuncs;
  337.     TMemberWriteFunction writeFunc;
  338.     SMemberSkipFunctions skipFuncs;
  339.     SMemberCopyFunctions copyFuncs;
  340.     // get/readmain/write
  341.     if ( CanBeDelayed() ) {
  342.         getConstFunc = &TFunc::GetConstDelayedMember;
  343.         getFunc = &TFunc::GetDelayedMember;
  344.         readFuncs.m_Main = &TFunc::ReadLongMember;
  345.         writeFunc = &TFunc::WriteLongMember;
  346.     }
  347.     else if ( !HaveSetFlag() ) {
  348.         getConstFunc = &TFunc::GetConstSimpleMember;
  349.         getFunc = &TFunc::GetSimpleMember;
  350.         readFuncs.m_Main = &TFunc::ReadSimpleMember;
  351.         if ( GetDefault() )
  352.             writeFunc = &TFunc::WriteWithDefaultMember;
  353.         else if ( Optional() )
  354.             writeFunc = &TFunc::WriteOptionalMember;
  355.         else
  356.             writeFunc = &TFunc::WriteSimpleMember;
  357.     }
  358.     else {
  359.         // have set flag
  360.         getConstFunc = &TFunc::GetConstSimpleMember;
  361.         getFunc = &TFunc::GetWithSetFlagMember;
  362.         readFuncs.m_Main = &TFunc::ReadWithSetFlagMember;
  363.         writeFunc = &TFunc::WriteWithSetFlagMember;
  364.     }
  365.     // copymain/skipmain
  366.     copyFuncs.m_Main = &TFunc::CopySimpleMember;
  367.     skipFuncs.m_Main = &TFunc::SkipSimpleMember;
  368.     // readmissing/copymissing/skipmissing
  369.     if ( Optional() ) {
  370.         if ( HaveSetFlag() ) {
  371.             readFuncs.m_Missing = &TFunc::ReadMissingWithSetFlagMember;
  372.         }
  373.         else {
  374.             readFuncs.m_Missing = &TFunc::ReadMissingOptionalMember;
  375.         }
  376.         copyFuncs.m_Missing = &TFunc::CopyMissingOptionalMember;
  377.         skipFuncs.m_Missing = &TFunc::SkipMissingOptionalMember;
  378.     }
  379.     else {
  380.         readFuncs.m_Missing = &TFunc::ReadMissingSimpleMember;
  381.         copyFuncs.m_Missing = &TFunc::CopyMissingSimpleMember;
  382.         skipFuncs.m_Missing = &TFunc::SkipMissingSimpleMember;
  383.     }
  384.     // update function pointers
  385.     m_GetConstFunction = getConstFunc;
  386.     m_GetFunction = getFunc;
  387.     m_ReadHookData.SetDefaultFunction(readFuncs);
  388.     m_WriteHookData.SetDefaultFunction(writeFunc);
  389.     m_SkipHookData.SetDefaultFunction(skipFuncs);
  390.     m_CopyHookData.SetDefaultFunction(copyFuncs);
  391. }
  392. void CMemberInfo::UpdateDelayedBuffer(CObjectIStream& in,
  393.                                       TObjectPtr classPtr) const
  394. {
  395.     _ASSERT(CanBeDelayed());
  396.     _ASSERT(GetDelayBuffer(classPtr).GetIndex() == GetIndex());
  397.     GetTypeInfo()->ReadData(in, GetItemPtr(classPtr));
  398. }
  399. void CMemberInfo::SetReadFunction(TMemberReadFunction func)
  400. {
  401.     SMemberReadFunctions funcs = m_ReadHookData.GetDefaultFunction();
  402.     funcs.m_Main = func;
  403.     m_ReadHookData.SetDefaultFunction(funcs);
  404. }
  405. void CMemberInfo::SetReadMissingFunction(TMemberReadFunction func)
  406. {
  407.     SMemberReadFunctions funcs = m_ReadHookData.GetDefaultFunction();
  408.     funcs.m_Missing = func;
  409.     m_ReadHookData.SetDefaultFunction(funcs);
  410. }
  411. void CMemberInfo::SetWriteFunction(TMemberWriteFunction func)
  412. {
  413.     m_WriteHookData.SetDefaultFunction(func);
  414. }
  415. void CMemberInfo::SetSkipFunction(TMemberSkipFunction func)
  416. {
  417.     SMemberSkipFunctions funcs = m_SkipHookData.GetDefaultFunction();
  418.     funcs.m_Main = func;
  419.     m_SkipHookData.SetDefaultFunction(funcs);
  420. }
  421. void CMemberInfo::SetSkipMissingFunction(TMemberSkipFunction func)
  422. {
  423.     SMemberSkipFunctions funcs = m_SkipHookData.GetDefaultFunction();
  424.     funcs.m_Missing = func;
  425.     m_SkipHookData.SetDefaultFunction(funcs);
  426. }
  427. void CMemberInfo::SetCopyFunction(TMemberCopyFunction func)
  428. {
  429.     SMemberCopyFunctions funcs = m_CopyHookData.GetDefaultFunction();
  430.     funcs.m_Main = func;
  431.     m_CopyHookData.SetDefaultFunction(funcs);
  432. }
  433. void CMemberInfo::SetCopyMissingFunction(TMemberCopyFunction func)
  434. {
  435.     SMemberCopyFunctions funcs = m_CopyHookData.GetDefaultFunction();
  436.     funcs.m_Missing = func;
  437.     m_CopyHookData.SetDefaultFunction(funcs);
  438. }
  439. void CMemberInfo::SetGlobalReadHook(CReadClassMemberHook* hook)
  440. {
  441.     CMutexGuard guard(GetTypeInfoMutex());
  442.     m_ReadHookData.SetGlobalHook(hook);
  443. }
  444. void CMemberInfo::SetLocalReadHook(CObjectIStream& stream,
  445.                                    CReadClassMemberHook* hook)
  446. {
  447.     CMutexGuard guard(GetTypeInfoMutex());
  448.     m_ReadHookData.SetLocalHook(stream.m_ClassMemberHookKey, hook);
  449. }
  450. void CMemberInfo::ResetGlobalReadHook(void)
  451. {
  452.     CMutexGuard guard(GetTypeInfoMutex());
  453.     m_ReadHookData.ResetGlobalHook();
  454. }
  455. void CMemberInfo::ResetLocalReadHook(CObjectIStream& stream)
  456. {
  457.     CMutexGuard guard(GetTypeInfoMutex());
  458.     m_ReadHookData.ResetLocalHook(stream.m_ClassMemberHookKey);
  459. }
  460. void CMemberInfo::SetPathReadHook(CObjectIStream* in, const string& path,
  461.                                   CReadClassMemberHook* hook)
  462. {
  463.     CMutexGuard guard(GetTypeInfoMutex());
  464.     m_ReadHookData.SetPathHook(in,path,hook);
  465. }
  466. void CMemberInfo::SetGlobalWriteHook(CWriteClassMemberHook* hook)
  467. {
  468.     CMutexGuard guard(GetTypeInfoMutex());
  469.     m_WriteHookData.SetGlobalHook(hook);
  470. }
  471. void CMemberInfo::SetLocalWriteHook(CObjectOStream& stream,
  472.                                     CWriteClassMemberHook* hook)
  473. {
  474.     CMutexGuard guard(GetTypeInfoMutex());
  475.     m_WriteHookData.SetLocalHook(stream.m_ClassMemberHookKey, hook);
  476. }
  477. void CMemberInfo::ResetGlobalWriteHook(void)
  478. {
  479.     CMutexGuard guard(GetTypeInfoMutex());
  480.     m_WriteHookData.ResetGlobalHook();
  481. }
  482. void CMemberInfo::ResetLocalWriteHook(CObjectOStream& stream)
  483. {
  484.     CMutexGuard guard(GetTypeInfoMutex());
  485.     m_WriteHookData.ResetLocalHook(stream.m_ClassMemberHookKey);
  486. }
  487. void CMemberInfo::SetPathWriteHook(CObjectOStream* out, const string& path,
  488.                                    CWriteClassMemberHook* hook)
  489. {
  490.     CMutexGuard guard(GetTypeInfoMutex());
  491.     m_WriteHookData.SetPathHook(out,path,hook);
  492. }
  493. void CMemberInfo::SetGlobalSkipHook(CSkipClassMemberHook* hook)
  494. {
  495.     CMutexGuard guard(GetTypeInfoMutex());
  496.     m_SkipHookData.SetGlobalHook(hook);
  497. }
  498. void CMemberInfo::SetLocalSkipHook(CObjectIStream& stream,
  499.                                    CSkipClassMemberHook* hook)
  500. {
  501.     CMutexGuard guard(GetTypeInfoMutex());
  502.     m_SkipHookData.SetLocalHook(stream.m_ClassMemberSkipHookKey, hook);
  503. }
  504. void CMemberInfo::ResetGlobalSkipHook(void)
  505. {
  506.     CMutexGuard guard(GetTypeInfoMutex());
  507.     m_SkipHookData.ResetGlobalHook();
  508. }
  509. void CMemberInfo::ResetLocalSkipHook(CObjectIStream& stream)
  510. {
  511.     CMutexGuard guard(GetTypeInfoMutex());
  512.     m_SkipHookData.ResetLocalHook(stream.m_ClassMemberSkipHookKey);
  513. }
  514. void CMemberInfo::SetPathSkipHook(CObjectIStream* in, const string& path,
  515.                                   CSkipClassMemberHook* hook)
  516. {
  517.     CMutexGuard guard(GetTypeInfoMutex());
  518.     m_SkipHookData.SetPathHook(in,path,hook);
  519. }
  520. void CMemberInfo::SetGlobalCopyHook(CCopyClassMemberHook* hook)
  521. {
  522.     CMutexGuard guard(GetTypeInfoMutex());
  523.     m_CopyHookData.SetGlobalHook(hook);
  524. }
  525. void CMemberInfo::SetLocalCopyHook(CObjectStreamCopier& stream,
  526.                                    CCopyClassMemberHook* hook)
  527. {
  528.     CMutexGuard guard(GetTypeInfoMutex());
  529.     m_CopyHookData.SetLocalHook(stream.m_ClassMemberHookKey, hook);
  530. }
  531. void CMemberInfo::ResetGlobalCopyHook(void)
  532. {
  533.     CMutexGuard guard(GetTypeInfoMutex());
  534.     m_CopyHookData.ResetGlobalHook();
  535. }
  536. void CMemberInfo::ResetLocalCopyHook(CObjectStreamCopier& stream)
  537. {
  538.     CMutexGuard guard(GetTypeInfoMutex());
  539.     m_CopyHookData.ResetLocalHook(stream.m_ClassMemberHookKey);
  540. }
  541. void CMemberInfo::SetPathCopyHook(CObjectStreamCopier* stream, const string& path,
  542.                                   CCopyClassMemberHook* hook)
  543. {
  544.     CMutexGuard guard(GetTypeInfoMutex());
  545.     m_CopyHookData.SetPathHook(stream ? &(stream->In()) : 0,path,hook);
  546. }
  547. TObjectPtr CMemberInfo::CreateClass(void) const
  548. {
  549.     return GetClassType()->Create();
  550. }
  551. TConstObjectPtr
  552. CMemberInfoFunctions::GetConstSimpleMember(const CMemberInfo* memberInfo,
  553.                                            TConstObjectPtr classPtr)
  554. {
  555.     _ASSERT(!memberInfo->CanBeDelayed());
  556.     return memberInfo->GetItemPtr(classPtr);
  557. }
  558. TConstObjectPtr
  559. CMemberInfoFunctions::GetConstDelayedMember(const CMemberInfo* memberInfo,
  560.                                             TConstObjectPtr classPtr)
  561. {
  562.     _ASSERT(memberInfo->CanBeDelayed());
  563.     const_cast<CDelayBuffer&>(memberInfo->GetDelayBuffer(classPtr)).Update();
  564.     return memberInfo->GetItemPtr(classPtr);
  565. }
  566. TObjectPtr CMemberInfoFunctions::GetSimpleMember(const CMemberInfo* memberInfo,
  567.                                                  TObjectPtr classPtr)
  568. {
  569.     _ASSERT(!memberInfo->CanBeDelayed());
  570.     _ASSERT(!memberInfo->HaveSetFlag());
  571.     return memberInfo->GetItemPtr(classPtr);
  572. }
  573. TObjectPtr CMemberInfoFunctions::GetWithSetFlagMember(const CMemberInfo* memberInfo,
  574.                                                       TObjectPtr classPtr)
  575. {
  576.     _ASSERT(!memberInfo->CanBeDelayed());
  577.     _ASSERT(memberInfo->HaveSetFlag());
  578.     return memberInfo->GetItemPtr(classPtr);
  579. }
  580. TObjectPtr CMemberInfoFunctions::GetDelayedMember(const CMemberInfo* memberInfo,
  581.                                                   TObjectPtr classPtr)
  582. {
  583.     _ASSERT(memberInfo->CanBeDelayed());
  584.     memberInfo->GetDelayBuffer(classPtr).Update();
  585.     memberInfo->UpdateSetFlagYes(classPtr);
  586.     return memberInfo->GetItemPtr(classPtr);
  587. }
  588. void CMemberInfoFunctions::ReadSimpleMember(CObjectIStream& in,
  589.                                             const CMemberInfo* memberInfo,
  590.                                             TObjectPtr classPtr)
  591. {
  592.     _ASSERT(!memberInfo->CanBeDelayed());
  593.     _ASSERT(!memberInfo->HaveSetFlag());
  594.     in.ReadObject(memberInfo->GetItemPtr(classPtr),
  595.                   memberInfo->GetTypeInfo());
  596. }
  597. void CMemberInfoFunctions::ReadWithSetFlagMember(CObjectIStream& in,
  598.                                                  const CMemberInfo* memberInfo,
  599.                                                  TObjectPtr classPtr)
  600. {
  601.     _ASSERT(!memberInfo->CanBeDelayed());
  602.     _ASSERT(memberInfo->HaveSetFlag());
  603.     memberInfo->UpdateSetFlagYes(classPtr);
  604.     try {
  605.         in.ReadObject(memberInfo->GetItemPtr(classPtr),
  606.                       memberInfo->GetTypeInfo());
  607.     }
  608.     catch (CSerialException& e) {
  609.         if (e.GetErrCode() == CSerialException::eMissingValue) {
  610.             if ( memberInfo->Optional() && memberInfo->HaveSetFlag() ) {
  611.                 in.SetFailFlags(CObjectIStream::fNoError,0);
  612.                 if ( memberInfo->UpdateSetFlagNo(classPtr) ) {
  613.                     memberInfo->GetTypeInfo()->SetDefault(
  614.                         memberInfo->GetItemPtr(classPtr));
  615.                 }
  616.             } else {
  617.                 NCBI_RETHROW(e, CSerialException, eFormatError,
  618.                     "error while reading " + memberInfo->GetId().GetName());
  619.             }
  620.         } else {
  621.             NCBI_RETHROW_SAME(e,
  622.                 "error while reading " + memberInfo->GetId().GetName());
  623.         }
  624.     }
  625. }
  626. void CMemberInfoFunctions::ReadLongMember(CObjectIStream& in,
  627.                                           const CMemberInfo* memberInfo,
  628.                                           TObjectPtr classPtr)
  629. {
  630.     if ( memberInfo->CanBeDelayed() ) {
  631.         CDelayBuffer& buffer = memberInfo->GetDelayBuffer(classPtr);
  632.         if ( !buffer ) {
  633.             memberInfo->UpdateSetFlagYes(classPtr);
  634.             in.StartDelayBuffer();
  635.             memberInfo->GetTypeInfo()->SkipData(in);
  636.             in.EndDelayBuffer(buffer, memberInfo, classPtr);
  637.             return;
  638.         }
  639.         buffer.Update();
  640.     }
  641.     
  642.     memberInfo->UpdateSetFlagYes(classPtr);
  643.     in.ReadObject(memberInfo->GetItemPtr(classPtr),
  644.                   memberInfo->GetTypeInfo());
  645. }
  646. void CMemberInfoFunctions::ReadMissingSimpleMember(CObjectIStream& in,
  647.                                                    const CMemberInfo* memberInfo,
  648.                                                    TObjectPtr classPtr)
  649. {
  650.     _ASSERT(!memberInfo->Optional());
  651.     in.ExpectedMember(memberInfo);
  652.     if (memberInfo->HaveSetFlag()) {
  653.         memberInfo->UpdateSetFlagNo(classPtr);
  654.     }
  655.     memberInfo->GetTypeInfo()->SetDefault(memberInfo->GetItemPtr(classPtr));
  656. #ifdef _DEBUG
  657.     if (in.GetVerifyData() == eSerialVerifyData_No) {
  658.         if (memberInfo->GetTypeInfo()->GetTypeFamily() == eTypeFamilyPrimitive) {
  659.             CObjectInfo objinfo(memberInfo->GetItemPtr(classPtr),
  660.                                 memberInfo->GetTypeInfo());
  661.             if (objinfo.GetPrimitiveValueType() == ePrimitiveValueString) {
  662.                 objinfo.SetPrimitiveValueString(CSerialObject::ms_UnassignedStr);
  663.             } else {
  664.                 size_t size = memberInfo->GetTypeInfo()->GetSize();
  665.                 if (size <= sizeof(long)) {
  666.                     char* tmp = static_cast<char*>(
  667.                         memberInfo->GetItemPtr(classPtr));
  668.                     for (; size != 0; --size, ++tmp) {
  669.                         *tmp = CSerialObject::ms_UnassignedByte;
  670.                     }
  671.                 }
  672.             }
  673.         }
  674.     }
  675. #endif
  676. }
  677. void
  678. CMemberInfoFunctions::ReadMissingOptionalMember(CObjectIStream& /*in*/,
  679.                                                 const CMemberInfo* memberInfo,
  680.                                                 TObjectPtr classPtr)
  681. {
  682.     _ASSERT(memberInfo->Optional());
  683.     memberInfo->GetTypeInfo()->SetDefault(memberInfo->GetItemPtr(classPtr));
  684. }
  685. void
  686. CMemberInfoFunctions::ReadMissingWithSetFlagMember(CObjectIStream& /*in*/,
  687.                                                    const CMemberInfo* memberInfo,
  688.                                                    TObjectPtr classPtr)
  689. {
  690.     _ASSERT(!memberInfo->CanBeDelayed());
  691.     _ASSERT(memberInfo->HaveSetFlag());
  692.     if ( memberInfo->UpdateSetFlagNo(classPtr) ) {
  693.         memberInfo->GetTypeInfo()->SetDefault(memberInfo->GetItemPtr(classPtr));
  694.     }
  695. }
  696. void CMemberInfoFunctions::WriteSimpleMember(CObjectOStream& out,
  697.                                              const CMemberInfo* memberInfo,
  698.                                              TConstObjectPtr classPtr)
  699. {
  700.     _ASSERT(!memberInfo->CanBeDelayed());
  701.     _ASSERT(!memberInfo->Optional());
  702.     out.WriteClassMember(memberInfo->GetId(),
  703.                          memberInfo->GetTypeInfo(),
  704.                          memberInfo->GetItemPtr(classPtr));
  705. }
  706. void CMemberInfoFunctions::WriteOptionalMember(CObjectOStream& out,
  707.                                                const CMemberInfo* memberInfo,
  708.                                                TConstObjectPtr classPtr)
  709. {
  710.     _ASSERT(!memberInfo->CanBeDelayed());
  711.     _ASSERT(memberInfo->Optional());
  712.     TTypeInfo memberType = memberInfo->GetTypeInfo();
  713.     TConstObjectPtr memberPtr = memberInfo->GetItemPtr(classPtr);
  714.     if ( memberType->IsDefault(memberPtr) )
  715.         return;
  716.     out.WriteClassMember(memberInfo->GetId(), memberType, memberPtr);
  717. }
  718. void CMemberInfoFunctions::WriteWithDefaultMember(CObjectOStream& out,
  719.                                                   const CMemberInfo* memberInfo,
  720.                                                   TConstObjectPtr classPtr)
  721. {
  722.     _ASSERT(!memberInfo->CanBeDelayed());
  723.     _ASSERT(memberInfo->GetDefault());
  724.     TTypeInfo memberType = memberInfo->GetTypeInfo();
  725.     TConstObjectPtr memberPtr = memberInfo->GetItemPtr(classPtr);
  726.     if ( memberType->Equals(memberPtr, memberInfo->GetDefault()) )
  727.         return;
  728.     out.WriteClassMember(memberInfo->GetId(), memberType, memberPtr);
  729. }
  730. void CMemberInfoFunctions::WriteWithSetFlagMember(CObjectOStream& out,
  731.                                                   const CMemberInfo* memberInfo,
  732.                                                   TConstObjectPtr classPtr)
  733. {
  734.     _ASSERT(!memberInfo->CanBeDelayed());
  735.     _ASSERT(memberInfo->HaveSetFlag());
  736.     if ( memberInfo->GetSetFlagNo(classPtr) ) {
  737.         if (memberInfo->Optional()) {
  738.             return;
  739.         }
  740.         ESerialVerifyData verify = out.GetVerifyData();
  741.         if (verify == eSerialVerifyData_Yes) {
  742.             out.ThrowError(CObjectOStream::fUnassigned,
  743.                 string("Unassigned member: ")+memberInfo->GetId().GetName());
  744.         } else if (verify == eSerialVerifyData_No) {
  745.             return;
  746.         }
  747.     }
  748. #ifdef _DEBUG
  749.     if (memberInfo->GetSetFlag(classPtr) == CMemberInfo::eSetMaybe &&
  750.         memberInfo->GetTypeInfo()->GetTypeFamily() == eTypeFamilyPrimitive) {
  751.         bool do_err_post = false;
  752.         CConstObjectInfo objinfo(memberInfo->GetItemPtr(classPtr),
  753.                                  memberInfo->GetTypeInfo());
  754.         if (objinfo.GetPrimitiveValueType() == ePrimitiveValueString) {
  755.             string tmp;
  756.             objinfo.GetPrimitiveValueString(tmp);
  757.             do_err_post = (tmp == CSerialObject::ms_UnassignedStr);
  758.         } else {
  759.             size_t size = memberInfo->GetTypeInfo()->GetSize();
  760.             const char* tmp = static_cast<const char*>(
  761.                 memberInfo->GetItemPtr(classPtr));
  762.             for (; size != 0 && *tmp == CSerialObject::ms_UnassignedByte; --size, ++tmp)
  763.                 ;
  764.             do_err_post = (size == 0);
  765.         }
  766.         if (do_err_post) {
  767.             ERR_POST(Error << "CObjectOStream: at "<< out.GetPosition()<<
  768.                      ": Member ""<< memberInfo->GetId().GetName()<<
  769.                      "" seems to be unassigned");
  770.         }
  771.     }
  772. #endif
  773.     out.WriteClassMember(memberInfo->GetId(),
  774.                          memberInfo->GetTypeInfo(),
  775.                          memberInfo->GetItemPtr(classPtr));
  776. }
  777. void CMemberInfoFunctions::WriteLongMember(CObjectOStream& out,
  778.                                            const CMemberInfo* memberInfo,
  779.                                            TConstObjectPtr classPtr)
  780. {
  781.     bool haveSetFlag = memberInfo->HaveSetFlag();
  782.     if ( haveSetFlag && memberInfo->GetSetFlagNo(classPtr) ) {
  783.         // not set -> skip this member
  784.         return;
  785.     }
  786.     
  787.     if ( memberInfo->CanBeDelayed() ) {
  788.         const CDelayBuffer& buffer = memberInfo->GetDelayBuffer(classPtr);
  789.         if ( buffer ) {
  790.             if ( out.WriteClassMember(memberInfo->GetId(), buffer) )
  791.                 return;
  792.             // cannot write delayed buffer -> proceed after update
  793.             const_cast<CDelayBuffer&>(buffer).Update();
  794.         }
  795.     }
  796.     
  797.     TTypeInfo memberType = memberInfo->GetTypeInfo();
  798.     TConstObjectPtr memberPtr = memberInfo->GetItemPtr(classPtr);
  799.     if ( !haveSetFlag && memberInfo->Optional() ) {
  800.         TConstObjectPtr defaultPtr = memberInfo->GetDefault();
  801.         if ( !defaultPtr ) {
  802.             if ( memberType->IsDefault(memberPtr) )
  803.                 return; // DEFAULT
  804.         }
  805.         else {
  806.             if ( memberType->Equals(memberPtr, defaultPtr) )
  807.                 return; // OPTIONAL
  808.         }
  809.     }
  810.     
  811.     out.WriteClassMember(memberInfo->GetId(), memberType, memberPtr);
  812. }
  813. void CMemberInfoFunctions::CopySimpleMember(CObjectStreamCopier& copier,
  814.                                             const CMemberInfo* memberInfo)
  815. {
  816.     copier.CopyObject(memberInfo->GetTypeInfo());
  817. }
  818. void CMemberInfoFunctions::CopyMissingSimpleMember(CObjectStreamCopier& copier,
  819.                                                    const CMemberInfo* memberInfo)
  820. {
  821.     _ASSERT(!memberInfo->Optional());
  822.     copier.ExpectedMember(memberInfo);
  823. }
  824. void CMemberInfoFunctions::CopyMissingOptionalMember(CObjectStreamCopier& /*copier*/,
  825.                                                      const CMemberInfo* _DEBUG_ARG(memberInfo))
  826. {
  827.     _ASSERT(memberInfo->Optional());
  828. }
  829. void CMemberInfoFunctions::SkipSimpleMember(CObjectIStream& in,
  830.                                             const CMemberInfo* memberInfo)
  831. {
  832.     in.SkipObject(memberInfo->GetTypeInfo());
  833. }
  834. void CMemberInfoFunctions::SkipMissingSimpleMember(CObjectIStream& in,
  835.                                                    const CMemberInfo* memberInfo)
  836. {
  837.     _ASSERT(!memberInfo->Optional());
  838.     in.ExpectedMember(memberInfo);
  839. }
  840. void CMemberInfoFunctions::SkipMissingOptionalMember(CObjectIStream& /*in*/,
  841.                                                      const CMemberInfo* _DEBUG_ARG(memberInfo))
  842. {
  843.     _ASSERT(memberInfo->Optional());
  844. }
  845. void CMemberInfoFunctions::ReadHookedMember(CObjectIStream& stream,
  846.                                             const CMemberInfo* memberInfo,
  847.                                             TObjectPtr classPtr)
  848. {
  849.     CReadClassMemberHook* hook =
  850.         memberInfo->m_ReadHookData.GetHook(stream.m_ClassMemberHookKey);
  851.     if ( !hook ) {
  852.         hook = memberInfo->m_ReadHookData.GetPathHook(stream);
  853.     }
  854.     if ( hook ) {
  855.         CObjectInfo object(classPtr, memberInfo->GetClassType());
  856.         TMemberIndex index = memberInfo->GetIndex();
  857.         CObjectInfo::CMemberIterator member(object, index);
  858.         _ASSERT(member.Valid());
  859.         if (memberInfo->HaveSetFlag()) {
  860.             memberInfo->UpdateSetFlagYes(classPtr);
  861.         }
  862.         hook->ReadClassMember(stream, member);
  863.     }
  864.     else
  865.         memberInfo->DefaultReadMember(stream, classPtr);
  866. }
  867. void CMemberInfoFunctions::ReadMissingHookedMember(CObjectIStream& stream,
  868.                                                    const CMemberInfo* memberInfo,
  869.                                                    TObjectPtr classPtr)
  870. {
  871.     CReadClassMemberHook* hook =
  872.         memberInfo->m_ReadHookData.GetHook(stream.m_ClassMemberHookKey);
  873.     if ( !hook ) {
  874.         hook = memberInfo->m_ReadHookData.GetPathHook(stream);
  875.     }
  876.     if ( hook ) {
  877.         memberInfo->GetTypeInfo()->
  878.             SetDefault(memberInfo->GetItemPtr(classPtr));
  879.         CObjectInfo object(classPtr, memberInfo->GetClassType());
  880.         TMemberIndex index = memberInfo->GetIndex();
  881.         CObjectInfo::CMemberIterator member(object, index);
  882.         _ASSERT(member.Valid());
  883.         hook->ReadMissingClassMember(stream, member);
  884.     }
  885.     else
  886.         memberInfo->DefaultReadMissingMember(stream, classPtr);
  887. }
  888. void CMemberInfoFunctions::WriteHookedMember(CObjectOStream& stream,
  889.                                              const CMemberInfo* memberInfo,
  890.                                              TConstObjectPtr classPtr)
  891. {
  892.     CWriteClassMemberHook* hook =
  893.         memberInfo->m_WriteHookData.GetHook(stream.m_ClassMemberHookKey);
  894.     if ( !hook ) {
  895.         hook = memberInfo->m_WriteHookData.GetPathHook(stream);
  896.     }
  897.     if ( hook ) {
  898.         CConstObjectInfo object(classPtr, memberInfo->GetClassType());
  899.         TMemberIndex index = memberInfo->GetIndex();
  900.         CConstObjectInfo::CMemberIterator member(object, index);
  901.         _ASSERT(member.Valid());
  902.         hook->WriteClassMember(stream, member);
  903.     }
  904.     else
  905.         memberInfo->DefaultWriteMember(stream, classPtr);
  906. }
  907. void CMemberInfoFunctions::SkipHookedMember(CObjectIStream& stream,
  908.                                             const CMemberInfo* memberInfo)
  909. {
  910.     CSkipClassMemberHook* hook =
  911.         memberInfo->m_SkipHookData.GetHook(stream.m_ClassMemberSkipHookKey);
  912.     if ( !hook ) {
  913.         hook = memberInfo->m_SkipHookData.GetPathHook(stream);
  914.     }
  915.     if ( hook ) {
  916.         CObjectTypeInfo type(memberInfo->GetClassType());
  917.         TMemberIndex index = memberInfo->GetIndex();
  918.         CObjectTypeInfo::CMemberIterator member(type, index);
  919.         _ASSERT(member.Valid());
  920.         hook->SkipClassMember(stream, member);
  921.     }
  922.     else
  923.         memberInfo->DefaultSkipMember(stream);
  924. }
  925. void CMemberInfoFunctions::SkipMissingHookedMember(CObjectIStream& stream,
  926.                                                    const CMemberInfo* memberInfo)
  927. {
  928.     CSkipClassMemberHook* hook =
  929.         memberInfo->m_SkipHookData.GetHook(stream.m_ClassMemberSkipHookKey);
  930.     if ( !hook ) {
  931.         hook = memberInfo->m_SkipHookData.GetPathHook(stream);
  932.     }
  933.     if ( hook ) {
  934.         CObjectTypeInfo type(memberInfo->GetClassType());
  935.         TMemberIndex index = memberInfo->GetIndex();
  936.         CObjectTypeInfo::CMemberIterator member(type, index);
  937.         _ASSERT(member.Valid());
  938.         hook->SkipMissingClassMember(stream, member);
  939.     }
  940.     else
  941.         memberInfo->DefaultSkipMissingMember(stream);
  942. }
  943. void CMemberInfoFunctions::CopyHookedMember(CObjectStreamCopier& stream,
  944.                                             const CMemberInfo* memberInfo)
  945. {
  946.     CCopyClassMemberHook* hook =
  947.         memberInfo->m_CopyHookData.GetHook(stream.m_ClassMemberHookKey);
  948.     if ( !hook ) {
  949.         hook = memberInfo->m_CopyHookData.GetPathHook(stream.In());
  950.     }
  951.     if ( hook ) {
  952.         CObjectTypeInfo type(memberInfo->GetClassType());
  953.         TMemberIndex index = memberInfo->GetIndex();
  954.         CObjectTypeInfo::CMemberIterator member(type, index);
  955.         _ASSERT(member.Valid());
  956.         hook->CopyClassMember(stream, member);
  957.     }
  958.     else
  959.         memberInfo->DefaultCopyMember(stream);
  960. }
  961. void CMemberInfoFunctions::CopyMissingHookedMember(CObjectStreamCopier& stream,
  962.                                                    const CMemberInfo* memberInfo)
  963. {
  964.     CCopyClassMemberHook* hook =
  965.         memberInfo->m_CopyHookData.GetHook(stream.m_ClassMemberHookKey);
  966.     if ( !hook ) {
  967.         hook = memberInfo->m_CopyHookData.GetPathHook(stream.In());
  968.     }
  969.     if ( hook ) {
  970.         CObjectTypeInfo type(memberInfo->GetClassType());
  971.         TMemberIndex index = memberInfo->GetIndex();
  972.         CObjectTypeInfo::CMemberIterator member(type, index);
  973.         _ASSERT(member.Valid());
  974.         hook->CopyMissingClassMember(stream, member);
  975.     }
  976.     else
  977.         memberInfo->DefaultCopyMissingMember(stream);
  978. }
  979. void CMemberInfoFunctions::ReadParentClass(CObjectIStream& in,
  980.                                            const CMemberInfo* memberInfo,
  981.                                            TObjectPtr objectPtr)
  982. {
  983.     _ASSERT(!memberInfo->CanBeDelayed());
  984.     _ASSERT(!memberInfo->HaveSetFlag());
  985.     in.ReadObject(memberInfo->GetItemPtr(objectPtr),
  986.                   memberInfo->GetTypeInfo());
  987. }
  988. void CMemberInfoFunctions::ReadMissingParentClass(CObjectIStream& in,
  989.                                                   const CMemberInfo* memberInfo,
  990.                                                   TObjectPtr /*objectPtr*/)
  991. {
  992.     _ASSERT(!memberInfo->Optional());
  993.     in.ExpectedMember(memberInfo);
  994. }
  995. void CMemberInfoFunctions::WriteParentClass(CObjectOStream& out,
  996.                                             const CMemberInfo* memberInfo,
  997.                                             TConstObjectPtr objectPtr)
  998. {
  999.     _ASSERT(!memberInfo->CanBeDelayed());
  1000.     _ASSERT(!memberInfo->Optional());
  1001.     out.WriteClassMember(memberInfo->GetId(),
  1002.                          memberInfo->GetTypeInfo(),
  1003.                          memberInfo->GetItemPtr(objectPtr));
  1004. }
  1005. void CMemberInfoFunctions::CopyParentClass(CObjectStreamCopier& copier,
  1006.                                            const CMemberInfo* memberInfo)
  1007. {
  1008.     copier.CopyObject(memberInfo->GetTypeInfo());
  1009. }
  1010. void CMemberInfoFunctions::CopyMissingParentClass(CObjectStreamCopier& copier,
  1011.                                                   const CMemberInfo* memberInfo)
  1012. {
  1013.     _ASSERT(!memberInfo->Optional());
  1014.     copier.ExpectedMember(memberInfo);
  1015. }
  1016. void CMemberInfoFunctions::SkipParentClass(CObjectIStream& in,
  1017.                                            const CMemberInfo* memberInfo)
  1018. {
  1019.     in.SkipObject(memberInfo->GetTypeInfo());
  1020. }
  1021. void CMemberInfoFunctions::SkipMissingParentClass(CObjectIStream& in,
  1022.                                                   const CMemberInfo* memberInfo)
  1023. {
  1024.     _ASSERT(!memberInfo->Optional());
  1025.     in.ExpectedMember(memberInfo);
  1026. }
  1027. END_NCBI_SCOPE
  1028. /*
  1029. * $Log: member.cpp,v $
  1030. * Revision 1000.3  2004/06/01 19:40:26  gouriano
  1031. * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.38
  1032. *
  1033. * Revision 1.38  2004/05/17 21:03:02  gorelenk
  1034. * Added include of PCH ncbi_pch.hpp
  1035. *
  1036. * Revision 1.37  2004/01/22 20:45:41  gouriano
  1037. * Corrected reading of class members with possibly empty contents (bool,enum)
  1038. *
  1039. * Revision 1.36  2004/01/05 14:25:20  gouriano
  1040. * Added possibility to set serialization hooks by stack path
  1041. *
  1042. * Revision 1.35  2003/11/13 14:07:37  gouriano
  1043. * Elaborated data verification on read/write/get to enable skipping mandatory class data members
  1044. *
  1045. * Revision 1.34  2003/10/01 14:40:12  vasilche
  1046. * Fixed CanGet() for members wihout 'set' flag.
  1047. *
  1048. * Revision 1.33  2003/09/16 14:48:35  gouriano
  1049. * Enhanced AnyContent objects to support XML namespaces and attribute info items.
  1050. *
  1051. * Revision 1.32  2003/08/26 19:25:58  gouriano
  1052. * added possibility to discard a member of an STL container
  1053. * (from a read hook)
  1054. *
  1055. * Revision 1.31  2003/08/14 20:03:58  vasilche
  1056. * Avoid memory reallocation when reading over preallocated object.
  1057. * Simplified CContainerTypeInfo iterators interface.
  1058. *
  1059. * Revision 1.30  2003/07/29 18:47:47  vasilche
  1060. * Fixed thread safeness of object stream hooks.
  1061. *
  1062. * Revision 1.29  2003/06/24 20:57:36  gouriano
  1063. * corrected code generation and serialization of non-empty unnamed containers (XML)
  1064. *
  1065. * Revision 1.28  2003/05/06 16:23:42  gouriano
  1066. * write unassigned mandatory member when assignment verification is off
  1067. *
  1068. * Revision 1.27  2003/04/29 18:30:36  gouriano
  1069. * object data member initialization verification
  1070. *
  1071. * Revision 1.26  2003/04/10 20:13:39  vakatov
  1072. * Rollback the "uninitialized member" verification -- it still needs to
  1073. * be worked upon...
  1074. *
  1075. * Revision 1.24  2002/11/14 20:57:22  gouriano
  1076. * modified constructor to use CClassTypeInfoBase,
  1077. * added Attlist and Notag flags
  1078. *
  1079. * Revision 1.23  2002/09/25 19:37:36  gouriano
  1080. * added the possibility of having no tag prefix in XML I/O streams
  1081. *
  1082. * Revision 1.22  2002/09/09 18:14:02  grichenk
  1083. * Added CObjectHookGuard class.
  1084. * Added methods to be used by hooks for data
  1085. * reading and skipping.
  1086. *
  1087. * Revision 1.21  2001/07/25 19:14:24  grichenk
  1088. * Implemented functions for reading/writing parent classes
  1089. *
  1090. * Revision 1.20  2001/05/22 13:44:47  grichenk
  1091. * CMemberInfoFunctions::GetWithSetFlagMember() -- do not change SetFlag
  1092. *
  1093. * Revision 1.19  2001/05/17 15:07:06  lavr
  1094. * Typos corrected
  1095. *
  1096. * Revision 1.18  2000/10/20 15:51:38  vasilche
  1097. * Fixed data error processing.
  1098. * Added interface for constructing container objects directly into output stream.
  1099. * object.hpp, object.inl and object.cpp were split to
  1100. * objectinfo.*, objecttype.*, objectiter.* and objectio.*.
  1101. *
  1102. * Revision 1.17  2000/10/17 18:45:33  vasilche
  1103. * Added possibility to turn off object cross reference detection in
  1104. * CObjectIStream and CObjectOStream.
  1105. *
  1106. * Revision 1.16  2000/10/13 20:22:55  vasilche
  1107. * Fixed warnings on 64 bit compilers.
  1108. * Fixed missing typename in templates.
  1109. *
  1110. * Revision 1.15  2000/10/03 17:22:42  vasilche
  1111. * Reduced header dependency.
  1112. * Reduced size of debug libraries on WorkShop by 3 times.
  1113. * Fixed tag allocation for parent classes.
  1114. * Fixed CObject allocation/deallocation in streams.
  1115. * Moved instantiation of several templates in separate source file.
  1116. *
  1117. * Revision 1.14  2000/09/29 16:18:22  vasilche
  1118. * Fixed binary format encoding/decoding on 64 bit compulers.
  1119. * Implemented CWeakMap<> for automatic cleaning map entries.
  1120. * Added cleaning local hooks via CWeakMap<>.
  1121. * Renamed ReadTypeName -> ReadFileHeader, ENoTypeName -> ENoFileHeader.
  1122. * Added some user interface methods to CObjectIStream, CObjectOStream and
  1123. * CObjectStreamCopier.
  1124. *
  1125. * Revision 1.13  2000/09/26 18:09:48  vasilche
  1126. * Fixed some warnings.
  1127. *
  1128. * Revision 1.12  2000/09/26 17:38:21  vasilche
  1129. * Fixed incomplete choiceptr implementation.
  1130. * Removed temporary comments.
  1131. *
  1132. * Revision 1.11  2000/09/22 20:01:19  vasilche
  1133. * Forgot to uncomment some code.
  1134. *
  1135. * Revision 1.10  2000/09/19 14:10:25  vasilche
  1136. * Added files to MSVC project
  1137. * Updated shell scripts to use new datattool path on MSVC
  1138. * Fixed internal compiler error on MSVC
  1139. *
  1140. * Revision 1.9  2000/09/18 20:00:22  vasilche
  1141. * Separated CVariantInfo and CMemberInfo.
  1142. * Implemented copy hooks.
  1143. * All hooks now are stored in CTypeInfo/CMemberInfo/CVariantInfo.
  1144. * Most type specific functions now are implemented via function pointers instead of virtual functions.
  1145. *
  1146. * Revision 1.8  2000/06/07 19:45:58  vasilche
  1147. * Some code cleaning.
  1148. * Macros renaming in more clear way.
  1149. * BEGIN_NAMED_*_INFO, ADD_*_MEMBER, ADD_NAMED_*_MEMBER.
  1150. *
  1151. * Revision 1.7  2000/02/01 21:47:22  vasilche
  1152. * Added CGeneratedChoiceTypeInfo for generated choice classes.
  1153. * Added buffering to CObjectIStreamAsn.
  1154. * Removed CMemberInfo subclasses.
  1155. * Added support for DEFAULT/OPTIONAL members.
  1156. *
  1157. * Revision 1.6  1999/09/14 18:54:17  vasilche
  1158. * Fixed bugs detected by gcc & egcs.
  1159. * Removed unneeded includes.
  1160. *
  1161. * Revision 1.5  1999/09/01 17:38:12  vasilche
  1162. * Fixed vector<char> implementation.
  1163. * Added explicit naming of class info.
  1164. * Moved IMPLICIT attribute from member info to class info.
  1165. *
  1166. * Revision 1.4  1999/08/31 17:50:08  vasilche
  1167. * Implemented several macros for specific data types.
  1168. * Added implicit members.
  1169. * Added multimap and set.
  1170. *
  1171. * Revision 1.3  1999/08/13 15:53:50  vasilche
  1172. * C++ analog of asntool: datatool
  1173. *
  1174. * Revision 1.2  1999/07/01 17:55:28  vasilche
  1175. * Implemented ASN.1 binary write.
  1176. *
  1177. * Revision 1.1  1999/06/30 16:04:50  vasilche
  1178. * Added support for old ASN.1 structures.
  1179. *
  1180. * ===========================================================================
  1181. */