NCBI C++ ToolKit
classinfo.hpp

Search Toolkit Book for info_8hpp_source

Go to the documentation of this file.
1 #ifndef CLASSINFO__HPP
2 #define CLASSINFO__HPP
3 
4 /* $Id: classinfo.hpp 80811 2018-01-11 14:18:53Z gouriano $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Eugene Vasilchenko
30 *
31 * File Description:
32 * !!! PUT YOUR DESCRIPTION HERE !!!
33 */
34 
35 #include <corelib/ncbistd.hpp>
37 #include <serial/impl/member.hpp>
38 #include <list>
39 
40 
41 /** @addtogroup TypeInfoCPP
42  *
43  * @{
44  */
45 
46 
48 
49 class CObjectIStream;
50 class CObjectOStream;
51 class COObjectList;
52 class CMemberId;
53 class CMemberInfo;
55 class CObjectInfoMI;
57 
59 {
61 protected:
62  typedef const type_info* (*TGetTypeIdFunction)(TConstObjectPtr object);
63 
64  enum EClassType {
67  eImplicit
68  };
69 
70  friend class CClassInfoHelperBase;
71 
72  CClassTypeInfo(size_t size, const char* name,
73  const void* nonCObject, TTypeCreate createFunc,
74  const type_info& ti, TGetTypeIdFunction idFunc);
75  CClassTypeInfo(size_t size, const char* name,
76  const CObject* cObject, TTypeCreate createFunc,
77  const type_info& ti, TGetTypeIdFunction idFunc);
78  CClassTypeInfo(size_t size, const string& name,
79  const void* nonCObject, TTypeCreate createFunc,
80  const type_info& ti, TGetTypeIdFunction idFunc);
81  CClassTypeInfo(size_t size, const string& name,
82  const CObject* cObject, TTypeCreate createFunc,
83  const type_info& ti, TGetTypeIdFunction idFunc);
84 
85 public:
86  typedef list<pair<CMemberId, CTypeRef> > TSubClasses;
87 
88  const CItemsInfo& GetMembers(void) const;
89  const CMemberInfo* GetMemberInfo(TMemberIndex index) const;
90  const CMemberInfo* GetMemberInfo(const CIterator& i) const;
91  const CMemberInfo* GetMemberInfo(const CTempString& name) const;
92 
93  virtual bool IsDefault(TConstObjectPtr object) const override;
94  virtual bool Equals(TConstObjectPtr object1, TConstObjectPtr object2,
95  ESerialRecursionMode how = eRecursive) const override;
96  virtual void SetDefault(TObjectPtr dst) const override;
97  virtual void Assign(TObjectPtr dst, TConstObjectPtr src,
98  ESerialRecursionMode how = eRecursive) const override;
99 
100  bool RandomOrder(void) const;
101  CClassTypeInfo* SetRandomOrder(bool random = true);
102 
103  bool Implicit(void) const;
104  CClassTypeInfo* SetImplicit(void);
105  bool IsImplicitNonEmpty(void) const;
106 
107  void AddSubClass(const CMemberId& id, const CTypeRef& type);
108  void AddSubClass(const char* id, TTypeInfoGetter getter);
109  void AddSubClassNull(const CMemberId& id);
110  void AddSubClassNull(const char* id);
111  const TSubClasses* SubClasses(void) const;
112 
113  const CClassTypeInfo* GetParentClassInfo(void) const;
114  void SetParentClass(TTypeInfo parentClass);
115 
116  void SetGlobalHook(const CTempString& member_names,
117  CReadClassMemberHook* hook);
118 
119 public:
120 
121  // iterators interface
122  const type_info* GetCPlusPlusTypeInfo(TConstObjectPtr object) const;
123 
124 protected:
125  void AssignMemberDefault(TObjectPtr object, const CMemberInfo* info) const;
126  void AssignMemberDefault(TObjectPtr object, TMemberIndex index) const;
127 
128  virtual bool IsType(TTypeInfo typeInfo) const override;
129  virtual bool IsParentClassOf(const CClassTypeInfo* classInfo) const override;
130  virtual EMayContainType CalcMayContainType(TTypeInfo typeInfo) const override;
131 
132  virtual TTypeInfo GetRealTypeInfo(TConstObjectPtr object) const override;
133  void RegisterSubClasses(void) const;
134 
135 private:
136  void InitClassTypeInfo(void);
137 
139 
141  unique_ptr<TSubClasses> m_SubClasses;
142 
144 
145  const CMemberInfo* GetImplicitMember(void) const;
146 
147 private:
148  void UpdateFunctions(void);
149 
150  static void ReadClassSequential(CObjectIStream& in,
151  TTypeInfo objectType,
152  TObjectPtr objectPtr);
153  static void ReadClassRandom(CObjectIStream& in,
154  TTypeInfo objectType,
155  TObjectPtr objectPtr);
156  static void ReadImplicitMember(CObjectIStream& in,
157  TTypeInfo objectType,
158  TObjectPtr objectPtr);
159  static void WriteClassRandom(CObjectOStream& out,
160  TTypeInfo objectType,
161  TConstObjectPtr objectPtr);
162  static void WriteClassSequential(CObjectOStream& out,
163  TTypeInfo objectType,
164  TConstObjectPtr objectPtr);
165  static void WriteImplicitMember(CObjectOStream& out,
166  TTypeInfo objectType,
167  TConstObjectPtr objectPtr);
168  static void SkipClassSequential(CObjectIStream& in,
169  TTypeInfo objectType);
170  static void SkipClassRandom(CObjectIStream& in,
171  TTypeInfo objectType);
172  static void SkipImplicitMember(CObjectIStream& in,
173  TTypeInfo objectType);
174  static void CopyClassSequential(CObjectStreamCopier& copier,
175  TTypeInfo objectType);
176  static void CopyClassRandom(CObjectStreamCopier& copier,
177  TTypeInfo objectType);
178  static void CopyImplicitMember(CObjectStreamCopier& copier,
179  TTypeInfo objectType);
180 };
181 
182 
183 /* @} */
184 
185 
186 #include <serial/impl/classinfo.inl>
187 
189 
190 #endif /* CLASSINFO__HPP */
CObjectIStream –.
Definition: objistr.hpp:93
CObjectInfoMI –.
Definition: objectiter.hpp:432
CObjectOStream –.
Definition: objostr.hpp:83
CObjectStreamCopier –.
Definition: objcopy.hpp:71
CObject –.
Definition: ncbiobj.hpp:180
Read hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:78
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
Include a standard set of the NCBI C++ Toolkit most basic headers.
std::ofstream out("events_result.xml")
main entry point for tests
ESerialRecursionMode
How to assign and compare child sub-objects of serial objects.
Definition: serialdef.hpp:191
void * TObjectPtr
Definition: serialdef.hpp:55
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:230
TTypeInfo(* TTypeInfoGetter)(void)
Definition: serialdef.hpp:63
const void * TConstObjectPtr
Definition: serialdef.hpp:59
const type_info *(* TGetTypeIdFunction)(TConstObjectPtr object)
@ eRecursive
Recursively.
Definition: serialdef.hpp:192
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
const CClassTypeInfo * m_ParentClassInfo
Definition: classinfo.hpp:140
virtual TTypeInfo GetRealTypeInfo(TConstObjectPtr object) const
Definition: typeinfo.cpp:309
virtual bool IsDefault(TConstObjectPtr object) const =0
Check, whether the object contains default value.
bool RandomOrder(void) const
const CMemberInfo * GetMemberInfo(TMemberIndex index) const
bool Implicit(void) const
virtual void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how=eRecursive) const =0
Set object to copy of another one.
const TSubClasses * SubClasses(void) const
list< pair< CMemberId, CTypeRef > > TSubClasses
Definition: classinfo.hpp:86
CClassTypeInfoBase CParent
Definition: classinfo.hpp:60
virtual bool IsType(TTypeInfo type) const
Definition: typeinfo.cpp:314
const CMemberInfo * GetMemberInfo(const CTempString &name) const
const CMemberInfo * GetMemberInfo(const CIterator &i) const
const type_info * GetCPlusPlusTypeInfo(TConstObjectPtr object) const
EClassType m_ClassType
Definition: classinfo.hpp:138
virtual bool IsParentClassOf(const CClassTypeInfo *classInfo) const
Definition: typeinfo.cpp:330
virtual bool Equals(TConstObjectPtr object1, TConstObjectPtr object2, ESerialRecursionMode how=eRecursive) const =0
Check if both objects contain the same values.
const CItemsInfo & GetMembers(void) const
virtual void SetDefault(TObjectPtr dst) const =0
Set object to default value.
TGetTypeIdFunction m_GetTypeIdFunction
Definition: classinfo.hpp:143
unique_ptr< TSubClasses > m_SubClasses
Definition: classinfo.hpp:141
virtual EMayContainType CalcMayContainType(TTypeInfo typeInfo) const
Definition: classinfob.cpp:358
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1435
int i
static MDB_envinfo info
Definition: mdb_load.c:37
const struct ncbi::grid::netcache::search::fields::SIZE size
std::istream & in(std::istream &in_, double &x_)
Definition: type.c:6
Modified on Fri Sep 20 14:58:04 2024 by modify_doxy.py rev. 669887