NCBI C++ ToolKit
classinfohelper.hpp

Search Toolkit Book for infohelper_8hpp_source

Go to the documentation of this file.
1 #ifndef CLASSINFOHELPER__HPP
2 #define CLASSINFOHELPER__HPP
3 
4 /* $Id: classinfohelper.hpp 92353 2021-01-11 20:47:16Z 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>
36 #include <serial/serialbase.hpp>
38 #include <typeinfo>
39 
40 
41 /** @addtogroup GenClassSupport
42  *
43  * @{
44  */
45 
46 
48 
49 class CClassTypeInfoBase;
50 class CClassTypeInfo;
51 class CChoiceTypeInfo;
52 
53 // these methods are external to avoid inclusion of big headers
55 {
56 protected:
57  typedef const type_info* (*TGetTypeIdFunction)(TConstObjectPtr object);
59  typedef TMemberIndex (*TWhichFunction)(const CChoiceTypeInfo* choiceType,
60  TConstObjectPtr choicePtr);
61  typedef void (*TResetFunction)(const CChoiceTypeInfo* choiceType,
62  TObjectPtr choicePtr);
63  typedef void (*TSelectFunction)(const CChoiceTypeInfo* choiceType,
64  TObjectPtr choicePtr,
65  TMemberIndex index,
66  CObjectMemoryPool* memPool);
67  typedef void (*TSelectDelayFunction)(TObjectPtr object,
68  TMemberIndex index);
69 
70  static CChoiceTypeInfo* CreateChoiceInfo(const char* name, size_t size,
71  const void* nonCObject,
72  TCreateFunction createFunc,
73  const type_info& ti,
74  TWhichFunction whichFunc,
75  TSelectFunction selectFunc,
76  TResetFunction resetFunc);
77  static CChoiceTypeInfo* CreateChoiceInfo(const char* name, size_t size,
78  const CObject* cObject,
79  TCreateFunction createFunc,
80  const type_info& ti,
81  TWhichFunction whichFunc,
82  TSelectFunction selectFunc,
83  TResetFunction resetFunc);
84 
85  static CClassTypeInfo* CreateClassInfo(const char* name, size_t size,
86  const void* nonCObject,
87  TCreateFunction createFunc,
88  const type_info& id,
89  TGetTypeIdFunction func);
90  static CClassTypeInfo* CreateClassInfo(const char* name, size_t size,
91  const CObject* cObject,
92  TCreateFunction createFunc,
93  const type_info& id,
94  TGetTypeIdFunction func);
95 #if HAVE_NCBI_C
97 #endif
98 };
99 
100 #if HAVE_NCBI_C
102 {
103 public:
104  static CChoiceTypeInfo* CreateAsnChoiceInfo(const char* name);
105  static CClassTypeInfo* CreateAsnStructInfo(const char* name, size_t size,
106  const type_info& id);
107 };
108 #endif
109 
110 // template collecting all helper methods for generated classes
111 template<class C>
113 {
115 public:
116  typedef C CClassType;
117 
118  static CClassType& Get(void* object)
119  {
120  return *static_cast<CClassType*>(object);
121  }
122  static const CClassType& Get(const void* object)
123  {
124  return *static_cast<const CClassType*>(object);
125  }
126 
127  static void* Create(TTypeInfo /*typeInfo*/,
128  CObjectMemoryPool* /*memPool*/)
129  {
130  return new CClassType();
131  }
132  static void* CreateCObject(TTypeInfo /*typeInfo*/,
133  CObjectMemoryPool* memPool)
134  {
135  return new(memPool) CClassType();
136  }
137 
138 
139  static const type_info* GetTypeId(const void* object)
140  {
141  const CClassType& x = Get(object);
142  return &typeid(x);
143  }
144 
149  };
150 
151  static TMemberIndex WhichChoice(const CChoiceTypeInfo* choiceType,
152  const void* choicePtr)
153  {
154  return choiceType->Which(choicePtr) + eGeneratedChoiceToMemberIndex;
155  }
156  static void ResetChoice(const CChoiceTypeInfo* choiceType,
157  void* choicePtr)
158  {
159  if ( WhichChoice(choiceType, choicePtr) != kEmptyChoice )
160  Get(choicePtr).Reset();
161  }
162  static void SelectChoice(const CChoiceTypeInfo* choiceType,
163  void* choicePtr,
164  TMemberIndex index,
165  CObjectMemoryPool* memPool)
166  {
167  typedef typename CClassType::E_Choice E_Choice;
168  if (WhichChoice(choiceType,choicePtr) != index) {
169  Get(choicePtr).Select(E_Choice(index + eMemberIndexToGeneratedChoice), NCBI_NS_NCBI::eDoResetVariant, memPool);
170  }
171  }
172  static void SelectDelayBuffer(const CChoiceTypeInfo* /*choiceType*/,
173  void* choicePtr,
174  TMemberIndex index)
175  {
176  typedef typename CClassType::E_Choice E_Choice;
177  Get(choicePtr).SelectDelayBuffer(E_Choice(index + eMemberIndexToGeneratedChoice));
178  }
179 
180  static void SetReadWriteMethods(NCBI_NS_NCBI::CClassTypeInfo* info)
181  {
182  const CClassType* object = 0;
183  NCBISERSetPreRead(object, info);
184  NCBISERSetPostRead(object, info);
185  NCBISERSetPreWrite(object, info);
186  NCBISERSetPostWrite(object, info);
187  }
188  static void SetReadWriteMethods(NCBI_NS_NCBI::CChoiceTypeInfo* info)
189  {
190  const CClassType* object = 0;
191  NCBISERSetPreRead(object, info);
192  NCBISERSetPostRead(object, info);
193  NCBISERSetPreWrite(object, info);
194  NCBISERSetPostWrite(object, info);
195  }
196  static void SetReadWriteMemberMethods(NCBI_NS_NCBI::CClassTypeInfo* info)
197  {
198  const CClassType* object = 0;
201  }
202  static void SetReadWriteVariantMethods(NCBI_NS_NCBI::CChoiceTypeInfo* info)
203  {
204  const CClassType* object = 0;
207  info->AdjustChoiceTypeInfoFunctions();
208  }
209 
210  static CClassTypeInfo* CreateAbstractClassInfo(const char* name)
211  {
212  const CClassType* object = 0;
214  CParent::CreateClassInfo(name, sizeof(CClassType),
216  typeid(CClassType), &GetTypeId);
218  return info;
219  }
220 
221  static CClassTypeInfo* CreateClassInfo(const char* name)
222  {
223  const CClassType* object = 0;
224  CClassTypeInfo* info = CreateClassInfo(name, object);
226  return info;
227  }
228 
229  static CChoiceTypeInfo* CreateChoiceInfo(const char* name)
230  {
231  const CClassType* object = 0;
232  CChoiceTypeInfo* info = CreateChoiceInfo(name, object);
234  return info;
235  }
236 #ifdef HAVE_NCBI_C
237  static CClassTypeInfo* CreateAsnStructInfo(const char* name)
238  {
240  sizeof(CClassType),
241  typeid(CClassType));
242  }
243  static CChoiceTypeInfo* CreateAsnChoiceInfo(const char* name)
244  {
246  }
247 #endif
248 
249 private:
250  static CClassTypeInfo* CreateClassInfo(const char* name,
251  const void* nonCObject)
252  {
253  return CParent::CreateClassInfo(name, sizeof(CClassType),
254  nonCObject, &Create,
255  typeid(CClassType), &GetTypeId);
256  }
257  static CClassTypeInfo* CreateClassInfo(const char* name,
258  const CObject* cObject)
259  {
260  return CParent::CreateClassInfo(name, sizeof(CClassType),
261  cObject, &CreateCObject,
262  typeid(CClassType), &GetTypeId);
263  }
264  static CChoiceTypeInfo* CreateChoiceInfo(const char* name,
265  const void* nonCObject)
266  {
267  return CParent::CreateChoiceInfo(name, sizeof(CClassType),
268  nonCObject, &Create,
269  typeid(CClassType),
270  &WhichChoice,
272  }
273  static CChoiceTypeInfo* CreateChoiceInfo(const char* name,
274  const CObject* cObject)
275  {
276  return CParent::CreateChoiceInfo(name, sizeof(CClassType),
277  cObject, &CreateCObject,
278  typeid(CClassType),
279  &WhichChoice,
281  }
282 };
283 
284 
285 /* @} */
286 
287 
289 
290 #endif /* CLASSINFOHELPER__HPP */
CObject –.
Definition: ncbiobj.hpp:180
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.
#define C(s)
Definition: common.h:231
static CClassTypeInfo * CreateAsnStructInfo(const char *name, size_t size, const type_info &id)
Definition: serialasn.cpp:89
static CChoiceTypeInfo * CreateAsnChoiceInfo(const char *name)
Definition: serialasn.cpp:121
const TMemberIndex kEmptyChoice
Special value for marking empty choice.
Definition: serialdef.hpp:239
void NCBISERSetPreRead(const void *, CInfo *)
Definition: serialbase.hpp:899
static CClassTypeInfo * CreateAsnStructInfo(const char *name)
static TMemberIndex WhichChoice(const CChoiceTypeInfo *choiceType, const void *choicePtr)
static CChoiceTypeInfo * CreateChoiceInfo(const char *name, size_t size, const void *nonCObject, TCreateFunction createFunc, const type_info &ti, TWhichFunction whichFunc, TSelectFunction selectFunc, TResetFunction resetFunc)
Definition: serial.cpp:391
void NCBISERSetGlobalReadVariantHook(const void *, CInfo *)
Definition: serialbase.hpp:929
static void SelectDelayBuffer(const CChoiceTypeInfo *, void *choicePtr, TMemberIndex index)
void * TObjectPtr
Definition: serialdef.hpp:55
CClassInfoHelperBase CParent
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:230
void NCBISERSetPreWrite(const void *, CInfo *)
Definition: serialbase.hpp:911
static void SetReadWriteMethods(NCBI_NS_NCBI::CChoiceTypeInfo *info)
const void * TConstObjectPtr
Definition: serialdef.hpp:59
static void * Create(TTypeInfo, CObjectMemoryPool *)
static CClassTypeInfo * CreateClassInfo(const char *name, const CObject *cObject)
void NCBISERSetPostRead(const void *, CInfo *)
Definition: serialbase.hpp:905
static void SetReadWriteVariantMethods(NCBI_NS_NCBI::CChoiceTypeInfo *info)
void NCBISERSetPostWrite(const void *, CInfo *)
Definition: serialbase.hpp:917
void NCBISERSetGlobalReadMemberHook(const void *, CInfo *)
Definition: serialbase.hpp:923
static void * CreateCObject(TTypeInfo, CObjectMemoryPool *memPool)
static void ResetChoice(const CChoiceTypeInfo *choiceType, void *choicePtr)
static void SetReadWriteMemberMethods(NCBI_NS_NCBI::CClassTypeInfo *info)
static CClassTypeInfo * CreateClassInfo(const char *name, size_t size, const void *nonCObject, TCreateFunction createFunc, const type_info &id, TGetTypeIdFunction func)
Definition: serial.cpp:417
static const CClassType & Get(const void *object)
static CChoiceTypeInfo * CreateChoiceInfo(const char *name)
static CClassTypeInfo * CreateAbstractClassInfo(const char *name)
static const type_info * GetTypeId(const void *object)
static CClassTypeInfo * CreateClassInfo(const char *name, const void *nonCObject)
static void SelectChoice(const CChoiceTypeInfo *choiceType, void *choicePtr, TMemberIndex index, CObjectMemoryPool *memPool)
static CChoiceTypeInfo * CreateChoiceInfo(const char *name, const CObject *cObject)
static void SetReadWriteMethods(NCBI_NS_NCBI::CClassTypeInfo *info)
static CChoiceTypeInfo * CreateChoiceInfo(const char *name, const void *nonCObject)
static CClassType & Get(void *object)
static CChoiceTypeInfo * CreateAsnChoiceInfo(const char *name)
CTypeInfo::TTypeCreate TCreateFunction
static CClassTypeInfo * CreateClassInfo(const char *name)
@ eDoResetVariant
Definition: serialbase.hpp:77
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static TObjectPtr Create(TTypeInfo objectType, CObjectMemoryPool *memPool)
Definition: stdtypes.cpp:304
TMemberIndex Which(const void *object) const
Definition: choice.cpp:348
TObjectPtr(* TTypeCreate)(TTypeInfo objectType, CObjectMemoryPool *memoryPool)
Definition: typeinfo.hpp:86
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1435
static MDB_envinfo info
Definition: mdb_load.c:37
const struct ncbi::grid::netcache::search::fields::SIZE size
Modified on Thu May 23 12:35:23 2024 by modify_doxy.py rev. 669887