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

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: serialimpl.hpp,v $
  4.  * PRODUCTION Revision 1000.3  2004/04/12 17:15:44  gouriano
  5.  * PRODUCTION PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.47
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. #ifndef SERIALIMPL__HPP
  10. #define SERIALIMPL__HPP
  11. /*  $Id: serialimpl.hpp,v 1000.3 2004/04/12 17:15:44 gouriano Exp $
  12. * ===========================================================================
  13. *
  14. *                            PUBLIC DOMAIN NOTICE
  15. *               National Center for Biotechnology Information
  16. *
  17. *  This software/database is a "United States Government Work" under the
  18. *  terms of the United States Copyright Act.  It was written as part of
  19. *  the author's official duties as a United States Government employee and
  20. *  thus cannot be copyrighted.  This software/database is freely available
  21. *  to the public for use. The National Library of Medicine and the U.S.
  22. *  Government have not placed any restriction on its use or reproduction.
  23. *
  24. *  Although all reasonable efforts have been taken to ensure the accuracy
  25. *  and reliability of the software and data, the NLM and the U.S.
  26. *  Government do not and cannot warrant the performance or results that
  27. *  may be obtained by using this software or data. The NLM and the U.S.
  28. *  Government disclaim all warranties, express or implied, including
  29. *  warranties of performance, merchantability or fitness for any particular
  30. *  purpose.
  31. *
  32. *  Please cite the author in any work or product based on this material.
  33. *
  34. * ===========================================================================
  35. *
  36. * Author: Eugene Vasilchenko
  37. *
  38. * File Description:
  39. *   File to be included in modules implementing GetTypeInfo methods.
  40. *
  41. */
  42. #include <corelib/ncbistd.hpp>
  43. #include <corelib/ncbiobj.hpp>
  44. #include <corelib/ncbithr.hpp>
  45. #include <serial/typeinfo.hpp>
  46. #include <serial/stdtypes.hpp>
  47. #include <serial/stltypes.hpp>
  48. #include <serial/ptrinfo.hpp>
  49. #include <serial/enumerated.hpp>
  50. #include <serial/classinfo.hpp>
  51. #include <serial/choice.hpp>
  52. #include <serial/choiceptr.hpp>
  53. #include <serial/autoptrinfo.hpp>
  54. #include <serial/serialbase.hpp>
  55. #include <serial/exception.hpp>
  56. #include <serial/classinfohelper.hpp>
  57. /** @addtogroup GenClassSupport
  58.  *
  59.  * @{
  60.  */
  61. struct valnode;
  62. BEGIN_NCBI_SCOPE
  63. // forward declaration
  64. class CMemberInfo;
  65. class CClassTypeInfoBase;
  66. class CClassTypeInfo;
  67. class CChoiceTypeInfo;
  68. class CDelayBufferData;
  69. //
  70. // define type info getter for standard classes
  71. template<typename T>
  72. inline
  73. TTypeInfoGetter GetStdTypeInfoGetter(const T* )
  74. {
  75.     return &CStdTypeInfo<T>::GetTypeInfo;
  76. }
  77. // some compilers cannot resolve overloading by
  78. // (char* const*) and (const char* const*) in template
  79. // so we'll add explicit implementations:
  80. inline
  81. TTypeInfoGetter GetStdTypeInfoGetter(char* const* )
  82. {
  83.     return &CStdTypeInfo<char*>::GetTypeInfo;
  84. }
  85. inline
  86. TTypeInfoGetter GetStdTypeInfoGetter(const char* const* )
  87. {
  88.     return &CStdTypeInfo<const char*>::GetTypeInfo;
  89. }
  90. // macros used in ADD_*_MEMBER macros to specify complex type
  91. // example: ADD_MEMBER(member, STL_set, (STD, (string)))
  92. #define SERIAL_TYPE(TypeMacro) NCBI_NAME2(SERIAL_TYPE_,TypeMacro)
  93. #define SERIAL_REF(TypeMacro) NCBI_NAME2(SERIAL_REF_,TypeMacro)
  94. #define SERIAL_TYPE_CLASS(ClassName) ClassName
  95. #define SERIAL_REF_CLASS(ClassName) &ClassName::GetTypeInfo
  96. #define SERIAL_TYPE_STD(CType) CType
  97. #define SERIAL_REF_STD(CType) &NCBI_NS_NCBI::CStdTypeInfo<CType>::GetTypeInfo
  98. #define SERIAL_TYPE_StringStore() NCBI_NS_STD::string
  99. #define SERIAL_REF_StringStore() 
  100.     &NCBI_NS_NCBI::CStdTypeInfo<string>::GetTypeInfoStringStore
  101. #define SERIAL_TYPE_null() bool
  102. #define SERIAL_REF_null() 
  103.     &NCBI_NS_NCBI::CStdTypeInfo<bool>::GetTypeInfoNullBool
  104. #define SERIAL_TYPE_ENUM(CType, EnumName) CType
  105. #define SERIAL_REF_ENUM(CType, EnumName) 
  106.     NCBI_NS_NCBI::CreateEnumeratedTypeInfo(CType(0), ENUM_METHOD_NAME(EnumName)())
  107. #define SERIAL_TYPE_ENUM_IN(CType, CppContext, EnumName) CppContext CType
  108. #define SERIAL_REF_ENUM_IN(CType, CppContext, EnumName) 
  109.     NCBI_NS_NCBI::CreateEnumeratedTypeInfo(CppContext CType(0), CppContext ENUM_METHOD_NAME(EnumName)())
  110. #define SERIAL_TYPE_POINTER(TypeMacro,TypeMacroArgs) 
  111.     SERIAL_TYPE(TypeMacro)TypeMacroArgs*
  112. #define SERIAL_REF_POINTER(TypeMacro,TypeMacroArgs) 
  113.     &NCBI_NS_NCBI::CPointerTypeInfo::GetTypeInfo, SERIAL_REF(TypeMacro)TypeMacroArgs
  114. #define SERIAL_TYPE_STL_multiset(TypeMacro,TypeMacroArgs) 
  115.     NCBI_NS_STD::multiset<SERIAL_TYPE(TypeMacro)TypeMacroArgs >
  116. #define SERIAL_REF_STL_multiset(TypeMacro,TypeMacroArgs) 
  117.     &NCBI_NS_NCBI::CStlClassInfo_multiset<SERIAL_TYPE(TypeMacro)TypeMacroArgs >::GetTypeInfo, SERIAL_REF(TypeMacro)TypeMacroArgs
  118. #define SERIAL_TYPE_STL_set(TypeMacro,TypeMacroArgs) 
  119.     NCBI_NS_STD::set<SERIAL_TYPE(TypeMacro)TypeMacroArgs >
  120. #define SERIAL_REF_STL_set(TypeMacro,TypeMacroArgs) 
  121.     &NCBI_NS_NCBI::CStlClassInfo_set<SERIAL_TYPE(TypeMacro)TypeMacroArgs >::GetTypeInfo, SERIAL_REF(TypeMacro)TypeMacroArgs
  122. #define SERIAL_TYPE_STL_multimap(KeyTypeMacro,KeyTypeMacroArgs,ValueTypeMacro,ValueTypeMacroArgs) 
  123.     NCBI_NS_STD::multimap<SERIAL_TYPE(KeyTypeMacro)KeyTypeMacroArgs,SERIAL_TYPE(ValueTypeMacro)ValueTypeMacroArgs >
  124. #define SERIAL_REF_STL_multimap(KeyTypeMacro,KeyTypeMacroArgs,ValueTypeMacro,ValueTypeMacroArgs) 
  125.     CTypeRef(&NCBI_NS_NCBI::CStlClassInfo_multimap<SERIAL_TYPE(KeyTypeMacro)KeyTypeMacroArgs,SERIAL_TYPE(ValueTypeMacro)ValueTypeMacroArgs >::GetTypeInfo, SERIAL_REF(KeyTypeMacro)KeyTypeMacroArgs,SERIAL_REF(ValueTypeMacro)ValueTypeMacroArgs)
  126. #define SERIAL_TYPE_STL_map(KeyTypeMacro,KeyTypeMacroArgs,ValueTypeMacro,ValueTypeMacroArgs) 
  127.     NCBI_NS_STD::map<SERIAL_TYPE(KeyTypeMacro)KeyTypeMacroArgs,SERIAL_TYPE(ValueTypeMacro)ValueTypeMacroArgs >
  128. #define SERIAL_REF_STL_map(KeyTypeMacro,KeyTypeMacroArgs,ValueTypeMacro,ValueTypeMacroArgs) 
  129.     CTypeRef(&NCBI_NS_NCBI::CStlClassInfo_map<SERIAL_TYPE(KeyTypeMacro)KeyTypeMacroArgs,SERIAL_TYPE(ValueTypeMacro)ValueTypeMacroArgs >::GetTypeInfo, SERIAL_REF(KeyTypeMacro)KeyTypeMacroArgs,SERIAL_REF(ValueTypeMacro)ValueTypeMacroArgs)
  130. #define SERIAL_TYPE_STL_list(TypeMacro,TypeMacroArgs) 
  131.     NCBI_NS_STD::list<SERIAL_TYPE(TypeMacro)TypeMacroArgs >
  132. #define SERIAL_REF_STL_list(TypeMacro,TypeMacroArgs) 
  133.     &NCBI_NS_NCBI::CStlClassInfo_list<SERIAL_TYPE(TypeMacro)TypeMacroArgs >::GetTypeInfo, SERIAL_REF(TypeMacro)TypeMacroArgs
  134. #define SERIAL_TYPE_STL_list_set(TypeMacro,TypeMacroArgs) 
  135.     NCBI_NS_STD::list<SERIAL_TYPE(TypeMacro)TypeMacroArgs >
  136. #define SERIAL_REF_STL_list_set(TypeMacro,TypeMacroArgs) 
  137.     &NCBI_NS_NCBI::CStlClassInfo_list<SERIAL_TYPE(TypeMacro)TypeMacroArgs >::GetSetTypeInfo, SERIAL_REF(TypeMacro)TypeMacroArgs
  138. #define SERIAL_TYPE_STL_vector(TypeMacro,TypeMacroArgs) 
  139.     NCBI_NS_STD::vector<SERIAL_TYPE(TypeMacro)TypeMacroArgs >
  140. #define SERIAL_REF_STL_vector(TypeMacro,TypeMacroArgs) 
  141.     &NCBI_NS_NCBI::CStlClassInfo_vector<SERIAL_TYPE(TypeMacro)TypeMacroArgs >::GetTypeInfo, SERIAL_REF(TypeMacro)TypeMacroArgs
  142. #define SERIAL_TYPE_STL_vector_set(TypeMacro,TypeMacroArgs) 
  143.     NCBI_NS_STD::vector<SERIAL_TYPE(TypeMacro)TypeMacroArgs >
  144. #define SERIAL_REF_STL_vector_set(TypeMacro,TypeMacroArgs) 
  145.     &NCBI_NS_NCBI::CStlClassInfo_vector<SERIAL_TYPE(TypeMacro)TypeMacroArgs >::GetSetTypeInfo, SERIAL_REF(TypeMacro)TypeMacroArgs
  146. #define SERIAL_TYPE_STL_CHAR_vector(CharType) NCBI_NS_STD::vector<CharType>
  147. #define SERIAL_REF_STL_CHAR_vector(CharType) 
  148.     &NCBI_NS_NCBI::CStdTypeInfo< SERIAL_TYPE(STL_CHAR_vector)(CharType) >::GetTypeInfo
  149. #define SERIAL_TYPE_STL_auto_ptr(TypeMacro,TypeMacroArgs) 
  150.     NCBI_NS_STD::auto_ptr<SERIAL_TYPE(TypeMacro)TypeMacroArgs >
  151. #define SERIAL_REF_STL_auto_ptr(TypeMacro,TypeMacroArgs) 
  152.     &NCBI_NS_NCBI::CStlClassInfo_auto_ptr<SERIAL_TYPE(TypeMacro)TypeMacroArgs >::GetTypeInfo, SERIAL_REF(TypeMacro)TypeMacroArgs
  153. #define SERIAL_TYPE_STL_AutoPtr(TypeMacro,TypeMacroArgs) 
  154.     NCBI_NS_NCBI::AutoPtr<SERIAL_TYPE(TypeMacro)TypeMacroArgs >
  155. #define SERIAL_REF_STL_AutoPtr(TypeMacro,TypeMacroArgs) 
  156.     &NCBI_NS_NCBI::CAutoPtrTypeInfo<SERIAL_TYPE(TypeMacro)TypeMacroArgs >::GetTypeInfo, SERIAL_REF(TypeMacro)TypeMacroArgs
  157. #define SERIAL_TYPE_STL_CRef(TypeMacro,TypeMacroArgs) 
  158.     NCBI_NS_NCBI::CRef<SERIAL_TYPE(TypeMacro)TypeMacroArgs >
  159. #define SERIAL_REF_STL_CRef(TypeMacro,TypeMacroArgs) 
  160.     &NCBI_NS_NCBI::CRefTypeInfo<SERIAL_TYPE(TypeMacro)TypeMacroArgs >::GetTypeInfo, SERIAL_REF(TypeMacro)TypeMacroArgs
  161. #define SERIAL_TYPE_STL_CConstRef(TypeMacro,TypeMacroArgs) 
  162.     NCBI_NS_NCBI::CConstRef<SERIAL_TYPE(TypeMacro)TypeMacroArgs >
  163. #define SERIAL_REF_STL_CConstRef(TypeMacro,TypeMacroArgs) 
  164.     &NCBI_NS_NCBI::CConstRefTypeInfo<SERIAL_TYPE(TypeMacro)TypeMacroArgs >::GetTypeInfo, SERIAL_REF(TypeMacro)TypeMacroArgs
  165. #define SERIAL_TYPE_CHOICE(TypeMacro,TypeMacroArgs) 
  166.     SERIAL_TYPE(TypeMacro)TypeMacroArgs
  167. #define SERIAL_REF_CHOICE(TypeMacro,TypeMacroArgs) 
  168.     &NCBI_NS_NCBI::CChoicePointerTypeInfo::GetTypeInfo, 
  169.     SERIAL_REF(TypeMacro)TypeMacroArgs
  170. //#define SERIAL_TYPE_CHOICERef(ClassName) NCBI_NS_NCBI::CRef<ClassName>
  171. //#define SERIAL_REF_CHOICERef(ClassName) &ClassName::GetChoiceRefTypeInfo
  172. #define SERIAL_TYPE_CHOICERef(TypeMacro,TypeMacroArgs) 
  173.     NCBI_NS_NCBI::CRef<SERIAL_TYPE(TypeMacro)TypeMacroArgs >
  174. #define SERIAL_REF_CHOICERef(TypeMacro,TypeMacroArgs) 
  175.     &NCBI_NS_NCBI::CChoicePointerTypeInfo::GetTypeInfo, 
  176.     SERIAL_REF(TypeMacro)TypeMacroArgs
  177. template<typename T>
  178. struct Check
  179. {
  180.     static const void* Ptr(const T* member)
  181.         {
  182.             return member;
  183.         }
  184.     static const void* PtrPtr(T*const* member)
  185.         {
  186.             return member;
  187.         }
  188.     static const void* ObjectPtrPtr(T*const* member)
  189.         {
  190.             return member;
  191.         }
  192.     static const void* ObjectPtrPtr(CSerialObject*const* member)
  193.         {
  194.             return member;
  195.         }
  196. private:
  197.     Check(void);
  198.     ~Check(void);
  199.     Check(const Check<T>&);
  200.     Check<T>& operator=(const Check<T>&);
  201. };
  202. // Functions preventing memory leaks due to undestroyed type info objects
  203. NCBI_XSERIAL_EXPORT
  204. void RegisterEnumTypeValuesObject(CEnumeratedTypeValues* object);
  205. NCBI_XSERIAL_EXPORT
  206. void RegisterTypeInfoObject(CTypeInfo* object);
  207. template<typename T>
  208. inline
  209. TTypeInfo EnumTypeInfo(const T* member, const CEnumeratedTypeValues* enumInfo)
  210. {
  211.     return CreateEnumeratedTypeInfo(*member, enumInfo);
  212. }
  213. NCBI_XSERIAL_EXPORT SSystemMutex& GetTypeInfoMutex(void);
  214. // internal macros for implementing BEGIN_*_INFO and ADD_*_MEMBER
  215. #define DECLARE_BASE_OBJECT(ClassName) ClassName* base = 0
  216. #define BASE_OBJECT() static_cast<const CClass_Base*>(base)
  217. #define MEMBER_PTR(MemberName) &BASE_OBJECT()->MemberName
  218. #define CLASS_PTR(ClassName) static_cast<const ClassName*>(BASE_OBJECT())
  219. #define BEGIN_BASE_TYPE_INFO(ClassName,BaseClassName,Method,InfoType,Code) 
  220. const NCBI_NS_NCBI::CTypeInfo* Method(void) 
  221.     typedef ClassName CClass; 
  222.     typedef BaseClassName CClass_Base; 
  223.     static InfoType* volatile s_info = 0; 
  224.     InfoType* info = s_info; 
  225.     if ( !info ) { 
  226.         NCBI_NS_NCBI::CMutexGuard GUARD(NCBI_NS_NCBI::GetTypeInfoMutex()); 
  227.         info = s_info; 
  228.         if ( !info ) { 
  229.             DECLARE_BASE_OBJECT(CClass); 
  230.             info = Code; 
  231.             NCBI_NS_NCBI::RegisterTypeInfoObject(info);
  232. #define BEGIN_TYPE_INFO(ClassName, Method, InfoType, Code) 
  233.     BEGIN_BASE_TYPE_INFO(ClassName, ClassName, Method, InfoType, Code)
  234.     
  235. #define END_TYPE_INFO 
  236.             s_info = info; 
  237.         } 
  238.     } 
  239.     return info; 
  240. }
  241. // macros for specifying differents members
  242. #define SERIAL_MEMBER(MemberName,TypeMacro,TypeMacroArgs) 
  243.     NCBI_NS_NCBI::Check<SERIAL_TYPE(TypeMacro)TypeMacroArgs >::Ptr(MEMBER_PTR(MemberName)), SERIAL_REF(TypeMacro)TypeMacroArgs
  244. #define SERIAL_STD_MEMBER(MemberName) 
  245.     MEMBER_PTR(MemberName),NCBI_NS_NCBI::GetStdTypeInfoGetter(MEMBER_PTR(MemberName))
  246. #define SERIAL_CLASS_MEMBER(MemberName) 
  247.     MEMBER_PTR(MemberName),&MEMBER_PTR(MemberName).GetTypeInfo
  248. #define SERIAL_ENUM_MEMBER(MemberName,EnumName) 
  249.     MEMBER_PTR(MemberName), NCBI_NS_NCBI::EnumTypeInfo(MEMBER_PTR(MemberName), ENUM_METHOD_NAME(EnumName)())
  250. #define SERIAL_ENUM_IN_MEMBER(MemberName,CppContext,EnumName) 
  251.     MEMBER_PTR(MemberName), NCBI_NS_NCBI::EnumTypeInfo(MEMBER_PTR(MemberName),CppContext ENUM_METHOD_NAME(EnumName)())
  252. #define SERIAL_REF_MEMBER(MemberName,ClassName) 
  253.     SERIAL_MEMBER(MemberName,STL_CRef,(CLASS,(ClassName)))
  254. #define SERIAL_PTR_CHOICE_VARIANT(MemberName,TypeMacro,TypeMacroArgs) 
  255.     NCBI_NS_NCBI::Check<SERIAL_TYPE(TypeMacro)TypeMacroArgs >::PtrPtr(MEMBER_PTR(MemberName)), SERIAL_REF(TypeMacro)TypeMacroArgs
  256. #define SERIAL_REF_CHOICE_VARIANT(MemberName,ClassName) 
  257.     NCBI_NS_NCBI::Check<SERIAL_TYPE(CLASS)(ClassName)>::ObjectPtrPtr(MEMBER_PTR(MemberName)), SERIAL_REF(CLASS)(ClassName)
  258. #define SERIAL_BASE_CLASS(ClassName) 
  259.     CLASS_PTR(ClassName),&(CLASS_PTR(ClassName)->GetTypeInfo)
  260. // ADD_NAMED_*_MEMBER macros    
  261. #define ADD_NAMED_NULL_MEMBER(MemberAlias,TypeMacro,TypeMacroArgs) 
  262.     NCBI_NS_NCBI::AddMember(info,MemberAlias, 
  263.                             0,SERIAL_REF(TypeMacro)TypeMacroArgs)
  264. #define ADD_NAMED_MEMBER(MemberAlias,MemberName,TypeMacro,TypeMacroArgs) 
  265.     NCBI_NS_NCBI::AddMember(info,MemberAlias, 
  266.                             SERIAL_MEMBER(MemberName,TypeMacro,TypeMacroArgs))
  267. #define ADD_NAMED_STD_MEMBER(MemberAlias,MemberName) 
  268.     NCBI_NS_NCBI::AddMember(info,MemberAlias, 
  269.                             SERIAL_STD_MEMBER(MemberName))
  270. #define ADD_NAMED_CLASS_MEMBER(MemberAlias,MemberName) 
  271.     NCBI_NS_NCBI::AddMember(info,MemberAlias, 
  272.                             SERIAL_CLASS_MEMBER(MemberName))
  273. #define ADD_NAMED_ENUM_MEMBER(MemberAlias,MemberName,EnumName) 
  274.     NCBI_NS_NCBI::AddMember(info,MemberAlias, 
  275.                             SERIAL_ENUM_MEMBER(MemberName,EnumName))
  276. #define ADD_NAMED_ENUM_IN_MEMBER(MemberAlias,MemberName,CppContext,EnumName) 
  277.     NCBI_NS_NCBI::AddMember(info,MemberAlias, 
  278.                   SERIAL_ENUM_IN_MEMBER(MemberName,CppContext,EnumName))
  279. #define ADD_NAMED_REF_MEMBER(MemberAlias,MemberName,ClassName) 
  280.     NCBI_NS_NCBI::AddMember(info,MemberAlias, 
  281.                             SERIAL_REF_MEMBER(MemberName,ClassName))
  282. #define ADD_NAMED_BASE_CLASS(MemberAlias,ClassName) 
  283.     NCBI_NS_NCBI::AddMember(info,MemberAlias, 
  284.                             SERIAL_BASE_CLASS(ClassName))
  285. // ADD_*_MEMBER macros    
  286. #define ADD_MEMBER(MemberName,TypeMacro,TypeMacroArgs) 
  287.     ADD_NAMED_MEMBER(#MemberName,MemberName,TypeMacro,TypeMacroArgs)
  288. #define ADD_STD_MEMBER(MemberName) 
  289.     ADD_NAMED_STD_MEMBER(#MemberName,MemberName)
  290. #define ADD_CLASS_MEMBER(MemberName) 
  291.     ADD_NAMED_CLASS_MEMBER(#MemberName,MemberName)
  292. #define ADD_ENUM_MEMBER(MemberName,EnumName) 
  293.     ADD_NAMED_ENUM_MEMBER(#MemberName,MemberName,EnumName)
  294. #define ADD_ENUM_IN_MEMBER(MemberName,CppContext,EnumName) 
  295.     ADD_NAMED_ENUM_MEMBER(#MemberName,MemberName,CppContext,EnumName)
  296. #define ADD_REF_MEMBER(MemberName,ClassName) 
  297.     ADD_NAMED_REF_MEMBER(#MemberName,MemberName,ClassName)
  298. // ADD_NAMED_*_CHOICE_VARIANT macros    
  299. #define ADD_NAMED_NULL_CHOICE_VARIANT(MemberAlias,TypeMacro,TypeMacroArgs) 
  300.     NCBI_NS_NCBI::AddVariant(info,MemberAlias, 
  301.         0,SERIAL_REF(TypeMacro)TypeMacroArgs)
  302. #define ADD_NAMED_CHOICE_VARIANT(MemberAlias,MemberName,TypeMacro,TypeMacroArgs) 
  303.     NCBI_NS_NCBI::AddVariant(info,MemberAlias, 
  304.         SERIAL_MEMBER(MemberName,TypeMacro,TypeMacroArgs))
  305. #define ADD_NAMED_STD_CHOICE_VARIANT(MemberAlias,MemberName) 
  306.     NCBI_NS_NCBI::AddVariant(info,MemberAlias, 
  307.         SERIAL_STD_MEMBER(MemberName))
  308. #define ADD_NAMED_ENUM_CHOICE_VARIANT(MemberAlias,MemberName,EnumName) 
  309.     NCBI_NS_NCBI::AddVariant(info,MemberAlias, 
  310.         SERIAL_ENUM_MEMBER(MemberName,EnumName))
  311. #define ADD_NAMED_ENUM_IN_CHOICE_VARIANT(MemberAlias,MemberName,CppContext,EnumName) 
  312.     NCBI_NS_NCBI::AddVariant(info,MemberAlias, 
  313.         SERIAL_ENUM_IN_MEMBER(MemberName,CppContext,EnumName))
  314. #define ADD_NAMED_PTR_CHOICE_VARIANT(MemberAlias,MemberName,TypeMacro,TypeMacroArgs) 
  315.     NCBI_NS_NCBI::AddVariant(info,MemberAlias, 
  316.         SERIAL_PTR_CHOICE_VARIANT(MemberName,TypeMacro,TypeMacroArgs))->SetPointer()
  317. #define ADD_NAMED_REF_CHOICE_VARIANT(MemberAlias,MemberName,ClassName) 
  318.     NCBI_NS_NCBI::AddVariant(info,MemberAlias, 
  319.         SERIAL_REF_CHOICE_VARIANT(MemberName,ClassName))->SetObjectPointer()
  320. // ADD_*_CHOICE_VARIANT macros
  321. #define ADD_CHOICE_VARIANT(MemberName,TypeMacro,TypeMacroArgs) 
  322.     ADD_NAMED_CHOICE_VARIANT(#MemberName,MemberName,TypeMacro,TypeMacroArgs)
  323. #define ADD_STD_CHOICE_VARIANT(MemberName) 
  324.     ADD_NAMED_STD_CHOICE_VARIANT(#MemberName,MemberName)
  325. #define ADD_ENUM_CHOICE_VARIANT(MemberName,EnumName) 
  326.     ADD_NAMED_ENUM_CHOICE_VARIANT(#MemberName,MemberName,EnumName)
  327. #define ADD_ENUM_IN_CHOICE_VARIANT(MemberName,CppContext,EnumName) 
  328.     ADD_NAMED_ENUM_IN_CHOICE_VARIANT(#MemberName,MemberName,CppContext,EnumName)
  329. #define ADD_PTR_CHOICE_VARIANT(MemberName,TypeMacro,TypeMacroArgs) 
  330.     ADD_NAMED_PTR_CHOICE_VARIANT(#MemberName,MemberName,TypeMacro,TypeMacroArgs)
  331. #define ADD_REF_CHOICE_VARIANT(MemberName,ClassName) 
  332.     ADD_NAMED_REF_CHOICE_VARIANT(#MemberName,MemberName,ClassName)
  333. // type info definition macros
  334. #define BEGIN_NAMED_CLASS_INFO(ClassAlias,ClassName) 
  335.     BEGIN_TYPE_INFO(ClassName, 
  336.         ClassName::GetTypeInfo, 
  337.         NCBI_NS_NCBI::CClassTypeInfo, 
  338.         NCBI_NS_NCBI::CClassInfoHelper<CClass>::CreateClassInfo(ClassAlias))
  339. #define BEGIN_CLASS_INFO(ClassName) 
  340.     BEGIN_NAMED_CLASS_INFO(#ClassName, ClassName)
  341. #define BEGIN_NAMED_BASE_CLASS_INFO(ClassAlias,ClassName) 
  342.     BEGIN_BASE_TYPE_INFO(ClassName, NCBI_NAME2(ClassName,_Base), 
  343.         NCBI_NAME2(ClassName,_Base)::GetTypeInfo, 
  344.         NCBI_NS_NCBI::CClassTypeInfo, 
  345.         NCBI_NS_NCBI::CClassInfoHelper<CClass>::CreateClassInfo(ClassAlias))
  346. #define BEGIN_BASE_CLASS_INFO(ClassName) 
  347.     BEGIN_NAMED_BASE_CLASS_INFO(#ClassName, ClassName)
  348. #define SET_CLASS_IMPLICIT() info->SetImplicit()
  349. #define BEGIN_NAMED_IMPLICIT_CLASS_INFO(ClassAlias,ClassName) 
  350.     BEGIN_NAMED_CLASS_INFO(ClassAlias,ClassName); SET_CLASS_IMPLICIT();
  351. #define BEGIN_IMPLICIT_CLASS_INFO(ClassName) 
  352.     BEGIN_CLASS_INFO(ClassName); SET_CLASS_IMPLICIT();
  353. #define BEGIN_NAMED_BASE_IMPLICIT_CLASS_INFO(ClassAlias,ClassName) 
  354.     BEGIN_NAMED_BASE_CLASS_INFO(ClassAlias,ClassName); SET_CLASS_IMPLICIT();
  355. #define BEGIN_BASE_IMPLICIT_CLASS_INFO(ClassName) 
  356.     BEGIN_BASE_CLASS_INFO(ClassName); SET_CLASS_IMPLICIT();
  357. #define SET_CLASS_MODULE(ModuleName) 
  358.     NCBI_NS_NCBI::SetModuleName(info, ModuleName)
  359. #define END_CLASS_INFO END_TYPE_INFO
  360. #define BEGIN_NAMED_ABSTRACT_CLASS_INFO(ClassAlias,ClassName) 
  361.     BEGIN_TYPE_INFO(ClassName, 
  362.         ClassName::GetTypeInfo, 
  363.         NCBI_NS_NCBI::CClassTypeInfo, 
  364.         NCBI_NS_NCBI::CClassInfoHelper<CClass>::CreateAbstractClassInfo(ClassAlias))
  365. #define BEGIN_ABSTRACT_CLASS_INFO(ClassName) 
  366.     BEGIN_NAMED_ABSTRACT_CLASS_INFO(#ClassName, ClassName)
  367. #define BEGIN_NAMED_ABSTRACT_BASE_CLASS_INFO(ClassAlias,ClassName) 
  368.     BEGIN_BASE_TYPE_INFO(ClassName, NCBI_NAME2(ClassName,_Base), 
  369.         NCBI_NAME2(ClassName,_Base)::GetTypeInfo, 
  370.         NCBI_NS_NCBI::CClassTypeInfo, 
  371.         NCBI_NS_NCBI::CClassInfoHelper<CClass>::CreateAbstractClassInfo(ClassAlias))
  372. #define END_ABSTRACT_CLASS_INFO END_TYPE_INFO
  373. #define BEGIN_NAMED_DERIVED_CLASS_INFO(ClassAlias,ClassName,ParentClassName) 
  374.     BEGIN_NAMED_CLASS_INFO(ClassAlias,ClassName) 
  375.     SET_PARENT_CLASS(ParentClassName);
  376. #define BEGIN_DERIVED_CLASS_INFO(ClassName,ParentClassName) 
  377.     BEGIN_NAMED_DERIVED_CLASS_INFO(#ClassName, ClassName, ParentClassName)
  378. #define END_DERIVED_CLASS_INFO END_TYPE_INFO
  379. #define BEGIN_NAMED_CHOICE_INFO(ClassAlias,ClassName) 
  380.     BEGIN_TYPE_INFO(ClassName, 
  381.         ClassName::GetTypeInfo, 
  382.         NCBI_NS_NCBI::CChoiceTypeInfo, 
  383.         NCBI_NS_NCBI::CClassInfoHelper<CClass>::CreateChoiceInfo(ClassAlias))
  384. #define BEGIN_CHOICE_INFO(ClassName) 
  385.     BEGIN_NAMED_CHOICE_INFO(#ClassName, ClassName)
  386. #define BEGIN_NAMED_BASE_CHOICE_INFO(ClassAlias,ClassName) 
  387.     BEGIN_BASE_TYPE_INFO(ClassName, NCBI_NAME2(ClassName,_Base), 
  388.         NCBI_NAME2(ClassName,_Base)::GetTypeInfo, 
  389.         NCBI_NS_NCBI::CChoiceTypeInfo, 
  390.         NCBI_NS_NCBI::CClassInfoHelper<CClass>::CreateChoiceInfo(ClassAlias))
  391. #define BEGIN_BASE_CHOICE_INFO(ClassName) 
  392.     BEGIN_NAMED_BASE_CHOICE_INFO(#ClassName, ClassName)
  393. #define SET_CHOICE_MODULE(ModuleName) 
  394.     NCBI_NS_NCBI::SetModuleName(info, ModuleName)
  395. #define SET_CHOICE_DELAYED() 
  396.     info->SetSelectDelay(&NCBI_NS_NCBI::CClassInfoHelper<CClass>::SelectDelayBuffer)
  397. #define END_CHOICE_INFO END_TYPE_INFO
  398. // sub class definition
  399. #define SET_PARENT_CLASS(ParentClassName) 
  400.     info->SetParentClass(ParentClassName::GetTypeInfo())
  401. #define ADD_NAMED_SUB_CLASS(SubClassAlias, SubClassName) 
  402.     info->AddSubClass(SubClassAlias, &SubClassName::GetTypeInfo)
  403. #define ADD_SUB_CLASS(SubClassName) 
  404.     ADD_NAMED_SUB_CLASS(#SubClassName, SubClassName)
  405. #define ADD_NAMED_NULL_SUB_CLASS(ClassAlias) 
  406.     info->AddSubClassNull(ClassAlias)
  407. #define ADD_NULL_SUB_CLASS(ClassAlias) 
  408.     ADD_NAMED_NULL_SUB_CLASS("NULL")
  409. // enum definition macros
  410. #define BEGIN_ENUM_INFO_METHOD(MethodName, EnumAlias, EnumName, IsInteger) 
  411. const NCBI_NS_NCBI::CEnumeratedTypeValues* MethodName(void) 
  412.     static NCBI_NS_NCBI::CEnumeratedTypeValues* volatile s_enumInfo = 0; 
  413.     NCBI_NS_NCBI::CEnumeratedTypeValues* enumInfo = s_enumInfo; 
  414.     if ( !enumInfo ) { 
  415.         NCBI_NS_NCBI::CMutexGuard GUARD(NCBI_NS_NCBI::GetTypeInfoMutex()); 
  416.         enumInfo = s_enumInfo; 
  417.         if ( !enumInfo ) { 
  418.             enumInfo = new NCBI_NS_NCBI::CEnumeratedTypeValues(EnumAlias, IsInteger); 
  419.             NCBI_NS_NCBI::RegisterEnumTypeValuesObject(enumInfo); 
  420.             EnumName enumValue;
  421. #define END_ENUM_INFO_METHOD 
  422.             s_enumInfo = enumInfo; 
  423.         } 
  424.     } 
  425.     return enumInfo; 
  426. }
  427. #define BEGIN_NAMED_ENUM_IN_INFO(EnumAlias, CppContext, EnumName, IsInteger) 
  428.     BEGIN_ENUM_INFO_METHOD(CppContext ENUM_METHOD_NAME(EnumName), EnumAlias, EnumName, IsInteger)
  429. #define BEGIN_NAMED_ENUM_INFO(EnumAlias, EnumName, IsInteger) 
  430.     BEGIN_ENUM_INFO_METHOD(ENUM_METHOD_NAME(EnumName), EnumAlias, EnumName, IsInteger)
  431. #define BEGIN_ENUM_IN_INFO(CppContext, EnumName, IsInteger) 
  432.     BEGIN_NAMED_ENUM_IN_INFO(#EnumName, CppContext, EnumName, IsInteger)
  433. #define BEGIN_ENUM_INFO(EnumName, IsInteger) 
  434.     BEGIN_NAMED_ENUM_INFO(#EnumName, EnumName, IsInteger)
  435. #define SET_ENUM_MODULE(ModuleName) 
  436.     NCBI_NS_NCBI::SetModuleName(enumInfo, ModuleName)
  437. #define ADD_ENUM_VALUE(EnumValueName, EnumValueValue) 
  438.     enumInfo->AddValue(EnumValueName, enumValue = EnumValueValue)
  439. #define END_ENUM_IN_INFO END_ENUM_INFO_METHOD
  440. #define END_ENUM_INFO END_ENUM_INFO_METHOD
  441. // alias definition macros
  442. #define SERIAL_ALIAS(RefType) 
  443.     NCBI_NAME2(SERIAL_REF_, RefType)
  444. #define ALIASED_TYPE_INFO(RefType, RefCode) 
  445.     NCBI_NAME2(RefType, RefCode)
  446. #define BEGIN_ALIAS_INFO_METHOD(AliasName,ClassName,BaseClassName,SerialRef,Code) 
  447. const NCBI_NS_NCBI::CTypeInfo* BaseClassName::GetTypeInfo(void) 
  448.     static NCBI_NS_NCBI::CAliasTypeInfo* volatile s_info = 0; 
  449.     NCBI_NS_NCBI::CAliasTypeInfo* info = s_info; 
  450.     if ( !info ) { 
  451.         NCBI_NS_NCBI::CMutexGuard GUARD(NCBI_NS_NCBI::GetTypeInfoMutex()); 
  452.         info = s_info; 
  453.         if ( !info ) { 
  454.             typedef ClassName CClass; 
  455.             typedef BaseClassName CClass_Base; 
  456.             DECLARE_BASE_OBJECT(ClassName); 
  457.             typedef NCBI_NS_NCBI::TTypeInfo (*TGetter)(void); 
  458.             TGetter getter = SerialRef Code; 
  459.             info = new NCBI_NS_NCBI::CAliasTypeInfo(AliasName, getter()); 
  460.             NCBI_NS_NCBI::RegisterTypeInfoObject(info);
  461. #define BEGIN_ALIAS_INFO(AliasName,ClassName,RefType,RefCode) 
  462.     BEGIN_ALIAS_INFO_METHOD(AliasName, ClassName, 
  463.     NCBI_NAME2(ClassName,_Base), 
  464.     SERIAL_ALIAS(RefType), RefCode)
  465. #define SET_STD_ALIAS_DATA_PTR 
  466.     info->SetDataOffset(GetDataPtr(BASE_OBJECT()))
  467. #define SET_CLASS_ALIAS_DATA_PTR 
  468.     info->SetDataOffset(NCBI_NS_NCBI::TPointerOffsetType(BASE_OBJECT()))
  469. #define END_ALIAS_INFO 
  470.             s_info = info; 
  471.         } 
  472.     } 
  473.     return info; 
  474. }
  475. #define SET_ALIAS_MODULE(ModuleName) 
  476.     NCBI_NS_NCBI::SetModuleName(info, ModuleName)
  477. NCBI_XSERIAL_EXPORT
  478. void SetModuleName(CTypeInfo* info, const char* name);
  479. NCBI_XSERIAL_EXPORT
  480. void SetModuleName(CEnumeratedTypeValues* info, const char* name);
  481. // internal methods
  482. // add member
  483. NCBI_XSERIAL_EXPORT
  484. CMemberInfo* AddMember(CClassTypeInfoBase* info, const char* name,
  485.                        const void* member,
  486.                        TTypeInfo t);
  487. NCBI_XSERIAL_EXPORT
  488. CMemberInfo* AddMember(CClassTypeInfoBase* info, const char* name,
  489.                        const void* member,
  490.                        TTypeInfoGetter f);
  491. NCBI_XSERIAL_EXPORT
  492. CMemberInfo* AddMember(CClassTypeInfoBase* info, const char* name,
  493.                        const void* member,
  494.                        const CTypeRef& r);
  495. NCBI_XSERIAL_EXPORT
  496. CMemberInfo* AddMember(CClassTypeInfoBase* info, const char* name,
  497.                        const void* member,
  498.                        TTypeInfoGetter1 f1,
  499.                        TTypeInfo t);
  500. NCBI_XSERIAL_EXPORT
  501. CMemberInfo* AddMember(CClassTypeInfoBase* info, const char* name,
  502.                        const void* member,
  503.                        TTypeInfoGetter1 f1,
  504.                        TTypeInfoGetter f);
  505. NCBI_XSERIAL_EXPORT
  506. CMemberInfo* AddMember(CClassTypeInfoBase* info, const char* name,
  507.                        const void* member,
  508.                        TTypeInfoGetter1 f1,
  509.                        const CTypeRef& r);
  510. NCBI_XSERIAL_EXPORT
  511. CMemberInfo* AddMember(CClassTypeInfoBase* info, const char* name,
  512.                        const void* member,
  513.                        TTypeInfoGetter1 f2,
  514.                        TTypeInfoGetter1 f1,
  515.                        TTypeInfo t);
  516. NCBI_XSERIAL_EXPORT
  517. CMemberInfo* AddMember(CClassTypeInfoBase* info, const char* name,
  518.                        const void* member,
  519.                        TTypeInfoGetter1 f2,
  520.                        TTypeInfoGetter1 f1,
  521.                        TTypeInfoGetter f);
  522. NCBI_XSERIAL_EXPORT
  523. CMemberInfo* AddMember(CClassTypeInfoBase* info, const char* name,
  524.                        const void* member,
  525.                        TTypeInfoGetter1 f2,
  526.                        TTypeInfoGetter1 f1,
  527.                        const CTypeRef& r);
  528. NCBI_XSERIAL_EXPORT
  529. CMemberInfo* AddMember(CClassTypeInfoBase* info, const char* name,
  530.                        const void* member,
  531.                        TTypeInfoGetter1 f3,
  532.                        TTypeInfoGetter1 f2,
  533.                        TTypeInfoGetter1 f1,
  534.                        TTypeInfo t);
  535. NCBI_XSERIAL_EXPORT
  536. CMemberInfo* AddMember(CClassTypeInfoBase* info, const char* name,
  537.                        const void* member,
  538.                        TTypeInfoGetter1 f3,
  539.                        TTypeInfoGetter1 f2,
  540.                        TTypeInfoGetter1 f1,
  541.                        TTypeInfoGetter f);
  542. NCBI_XSERIAL_EXPORT
  543. CMemberInfo* AddMember(CClassTypeInfoBase* info, const char* name,
  544.                        const void* member,
  545.                        TTypeInfoGetter1 f3,
  546.                        TTypeInfoGetter1 f2,
  547.                        TTypeInfoGetter1 f1,
  548.                        const CTypeRef& r);
  549. NCBI_XSERIAL_EXPORT
  550. CMemberInfo* AddMember(CClassTypeInfoBase* info, const char* name,
  551.                        const void* member,
  552.                        TTypeInfoGetter1 f4,
  553.                        TTypeInfoGetter1 f3,
  554.                        TTypeInfoGetter1 f2,
  555.                        TTypeInfoGetter1 f1,
  556.                        TTypeInfo t);
  557. NCBI_XSERIAL_EXPORT
  558. CMemberInfo* AddMember(CClassTypeInfoBase* info, const char* name,
  559.                        const void* member,
  560.                        TTypeInfoGetter1 f4,
  561.                        TTypeInfoGetter1 f3,
  562.                        TTypeInfoGetter1 f2,
  563.                        TTypeInfoGetter1 f1,
  564.                        TTypeInfoGetter f);
  565. NCBI_XSERIAL_EXPORT
  566. CMemberInfo* AddMember(CClassTypeInfoBase* info, const char* name,
  567.                        const void* member,
  568.                        TTypeInfoGetter1 f4,
  569.                        TTypeInfoGetter1 f3,
  570.                        TTypeInfoGetter1 f2,
  571.                        TTypeInfoGetter1 f1,
  572.                        const CTypeRef& r);
  573. // add variant
  574. NCBI_XSERIAL_EXPORT
  575. CVariantInfo* AddVariant(CChoiceTypeInfo* info, const char* name,
  576.                        const void* member,
  577.                        TTypeInfo t);
  578. NCBI_XSERIAL_EXPORT
  579. CVariantInfo* AddVariant(CChoiceTypeInfo* info, const char* name,
  580.                        const void* member,
  581.                        TTypeInfoGetter f);
  582. NCBI_XSERIAL_EXPORT
  583. CVariantInfo* AddVariant(CChoiceTypeInfo* info, const char* name,
  584.                        const void* member,
  585.                        const CTypeRef& r);
  586. NCBI_XSERIAL_EXPORT
  587. CVariantInfo* AddVariant(CChoiceTypeInfo* info, const char* name,
  588.                        const void* member,
  589.                        TTypeInfoGetter1 f1,
  590.                        TTypeInfo t);
  591. NCBI_XSERIAL_EXPORT
  592. CVariantInfo* AddVariant(CChoiceTypeInfo* info, const char* name,
  593.                        const void* member,
  594.                        TTypeInfoGetter1 f1,
  595.                        TTypeInfoGetter f);
  596. NCBI_XSERIAL_EXPORT
  597. CVariantInfo* AddVariant(CChoiceTypeInfo* info, const char* name,
  598.                        const void* member,
  599.                        TTypeInfoGetter1 f1,
  600.                        const CTypeRef& r);
  601. NCBI_XSERIAL_EXPORT
  602. CVariantInfo* AddVariant(CChoiceTypeInfo* info, const char* name,
  603.                        const void* member,
  604.                        TTypeInfoGetter1 f2,
  605.                        TTypeInfoGetter1 f1,
  606.                        TTypeInfo t);
  607. NCBI_XSERIAL_EXPORT
  608. CVariantInfo* AddVariant(CChoiceTypeInfo* info, const char* name,
  609.                        const void* member,
  610.                        TTypeInfoGetter1 f2,
  611.                        TTypeInfoGetter1 f1,
  612.                        TTypeInfoGetter f);
  613. NCBI_XSERIAL_EXPORT
  614. CVariantInfo* AddVariant(CChoiceTypeInfo* info, const char* name,
  615.                        const void* member,
  616.                        TTypeInfoGetter1 f2,
  617.                        TTypeInfoGetter1 f1,
  618.                        const CTypeRef& r);
  619. NCBI_XSERIAL_EXPORT
  620. CVariantInfo* AddVariant(CChoiceTypeInfo* info, const char* name,
  621.                        const void* member,
  622.                        TTypeInfoGetter1 f3,
  623.                        TTypeInfoGetter1 f2,
  624.                        TTypeInfoGetter1 f1,
  625.                        TTypeInfo t);
  626. NCBI_XSERIAL_EXPORT
  627. CVariantInfo* AddVariant(CChoiceTypeInfo* info, const char* name,
  628.                        const void* member,
  629.                        TTypeInfoGetter1 f3,
  630.                        TTypeInfoGetter1 f2,
  631.                        TTypeInfoGetter1 f1,
  632.                        TTypeInfoGetter f);
  633. NCBI_XSERIAL_EXPORT
  634. CVariantInfo* AddVariant(CChoiceTypeInfo* info, const char* name,
  635.                        const void* member,
  636.                        TTypeInfoGetter1 f3,
  637.                        TTypeInfoGetter1 f2,
  638.                        TTypeInfoGetter1 f1,
  639.                        const CTypeRef& r);
  640. NCBI_XSERIAL_EXPORT
  641. CVariantInfo* AddVariant(CChoiceTypeInfo* info, const char* name,
  642.                        const void* member,
  643.                        TTypeInfoGetter1 f4,
  644.                        TTypeInfoGetter1 f3,
  645.                        TTypeInfoGetter1 f2,
  646.                        TTypeInfoGetter1 f1,
  647.                        TTypeInfo t);
  648. NCBI_XSERIAL_EXPORT
  649. CVariantInfo* AddVariant(CChoiceTypeInfo* info, const char* name,
  650.                        const void* member,
  651.                        TTypeInfoGetter1 f4,
  652.                        TTypeInfoGetter1 f3,
  653.                        TTypeInfoGetter1 f2,
  654.                        TTypeInfoGetter1 f1,
  655.                        TTypeInfoGetter f);
  656. NCBI_XSERIAL_EXPORT
  657. CVariantInfo* AddVariant(CChoiceTypeInfo* info, const char* name,
  658.                        const void* member,
  659.                        TTypeInfoGetter1 f4,
  660.                        TTypeInfoGetter1 f3,
  661.                        TTypeInfoGetter1 f2,
  662.                        TTypeInfoGetter1 f1,
  663.                        const CTypeRef& r);
  664. // end of internal methods
  665. END_NCBI_SCOPE
  666. /* @} */
  667. #endif