NCBI C++ ToolKit
choice.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CHOICE__HPP
2 #define CHOICE__HPP
3 
4 /* $Id: choice.hpp 80962 2018-01-25 17:43:38Z 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 
36 #include <serial/impl/variant.hpp>
37 
38 
39 /** @addtogroup TypeInfoCPP
40  *
41  * @{
42  */
43 
44 
46 
47 class CChoiceTypeInfoReader;
50 
52 
54 {
56 public:
57  typedef TMemberIndex (*TWhichFunction)(const CChoiceTypeInfo* choiceType,
58  TConstObjectPtr choicePtr);
59  typedef void (*TResetFunction)(const CChoiceTypeInfo* choiceType,
60  TObjectPtr choicePtr);
61  typedef void (*TSelectFunction)(const CChoiceTypeInfo* choiceType,
62  TObjectPtr choicePtr, TMemberIndex index,
63  CObjectMemoryPool* memPool);
64  typedef void (*TSelectDelayFunction)(const CChoiceTypeInfo* choiceType,
65  TObjectPtr choicePtr,
66  TMemberIndex index);
67  typedef TObjectPtr (*TGetDataFunction)(const CChoiceTypeInfo* choiceType,
68  TObjectPtr choicePtr,
69  TMemberIndex index);
70 
71  CChoiceTypeInfo(size_t size, const char* name,
72  const void* nonCObject, TTypeCreate createFunc,
73  const type_info& ti,
74  TWhichFunction whichFunc,
75  TSelectFunction selectFunc,
76  TResetFunction resetFunc);
77  CChoiceTypeInfo(size_t size, const char* name,
78  const CObject* cObject, TTypeCreate createFunc,
79  const type_info& ti,
80  TWhichFunction whichFunc,
81  TSelectFunction selectFunc,
82  TResetFunction resetFunc);
83  CChoiceTypeInfo(size_t size, const string& name,
84  const void* nonCObject, TTypeCreate createFunc,
85  const type_info& ti,
86  TWhichFunction whichFunc,
87  TSelectFunction selectFunc,
88  TResetFunction resetFunc);
89  CChoiceTypeInfo(size_t size, const string& name,
90  const CObject* cObject, TTypeCreate createFunc,
91  const type_info& ti,
92  TWhichFunction whichFunc,
93  TSelectFunction selectFunc,
94  TResetFunction resetFunc);
95 
96  const CItemsInfo& GetVariants(void) const;
98  const CVariantInfo* GetVariantInfo(const CIterator& i) const;
99  const CVariantInfo* GetVariantInfo(const CTempString& name) const;
100 
101  CVariantInfo* AddVariant(const char* variantId,
102  const void* variantPtr,
103  const CTypeRef& variantType);
104  CVariantInfo* AddVariant(const CMemberId& variantId,
105  const void* variantPtr,
106  const CTypeRef& variantType);
107 
108  virtual bool IsDefault(TConstObjectPtr object) const override;
109  virtual bool Equals(TConstObjectPtr obj1, TConstObjectPtr obj2,
110  ESerialRecursionMode how = eRecursive) const override;
111  virtual void SetDefault(TObjectPtr dst) const override;
112  virtual void Assign(TObjectPtr dst, TConstObjectPtr src,
113  ESerialRecursionMode how = eRecursive) const override;
114 
115  // iterators interface
117  void ResetIndex(TObjectPtr object) const;
118  void SetIndex(TObjectPtr object, TMemberIndex index,
119  CObjectMemoryPool* pool = 0) const;
120  void SetDelayIndex(TObjectPtr object, TMemberIndex index) const;
121 
124 
125  void SetGlobalHook(const CTempString& variant_names,
126  CReadChoiceVariantHook* hook);
127 
128  void AdjustChoiceTypeInfoFunctions(void);
129  bool MayBeEmpty(void) const {
130  return m_AllowEmpty;
131  }
132 
133  void SetSelectDelay(TSelectDelayFunction func);
134 
135  void SetSelectorInfo(const void* offset, size_t sz);
136  TMemberIndex Which(const void* object) const;
137 protected:
138  void CallUserOp_Assign(TObjectPtr dst, TConstObjectPtr src) const;
139 
141 
142 private:
143  void InitChoiceTypeInfoFunctions(void);
144 
145 protected:
146  TWhichFunction m_WhichFunction;
147  TResetFunction m_ResetFunction;
148  TSelectFunction m_SelectFunction;
149  TSelectDelayFunction m_SelectDelayFunction;
152  size_t m_WhichSize;
153 };
154 
155 
156 /* @} */
157 
158 
159 #include <serial/impl/choice.inl>
160 
162 
163 #endif /* CHOICE__HPP */
CObject –.
Definition: ncbiobj.hpp:180
Read hook for a choice variant (CHOICE)
Definition: objhook.hpp:117
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
int offset
Definition: replacements.h:160
ESerialRecursionMode
How to assign and compare child sub-objects of serial objects.
Definition: serialdef.hpp:191
void * TObjectPtr
Definition: serialdef.hpp:55
CVariantInfo * AddVariant(CChoiceTypeInfo *info, const char *name, const void *member, TTypeInfo t)
Definition: serial.cpp:265
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:230
const void * TConstObjectPtr
Definition: serialdef.hpp:59
ssize_t TPointerOffsetType
Definition: serialdef.hpp:241
@ 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
TWhichFunction m_WhichFunction
Definition: choice.hpp:146
TPointerOffsetType m_WhichOffset
Definition: choice.hpp:151
const CVariantInfo * GetVariantInfo(const CTempString &name) const
CClassTypeInfoBase CParent
Definition: choice.hpp:55
virtual bool IsDefault(TConstObjectPtr object) const =0
Check, whether the object contains default value.
TConstObjectPtr GetData(TConstObjectPtr object, TMemberIndex index) const
TSelectFunction m_SelectFunction
Definition: choice.hpp:148
TObjectPtr GetData(TObjectPtr object, TMemberIndex index) const
TResetFunction m_ResetFunction
Definition: choice.hpp:147
const CItemsInfo & GetVariants(void) const
bool MayBeEmpty(void) const
Definition: choice.hpp:129
TMemberIndex GetIndex(TConstObjectPtr object) const
const CVariantInfo * GetVariantInfo(const CIterator &i) const
const CVariantInfo * GetVariantInfo(TMemberIndex index) const
virtual void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how=eRecursive) const =0
Set object to copy of another one.
bool m_AllowEmpty
Definition: choice.hpp:150
virtual bool Equals(TConstObjectPtr object1, TConstObjectPtr object2, ESerialRecursionMode how=eRecursive) const =0
Check if both objects contain the same values.
TSelectDelayFunction m_SelectDelayFunction
Definition: choice.hpp:149
virtual void SetDefault(TObjectPtr dst) const =0
Set object to default value.
void ResetIndex(TObjectPtr object) const
size_t m_WhichSize
Definition: choice.hpp:152
void SetIndex(TObjectPtr object, TMemberIndex index, CObjectMemoryPool *pool=0) const
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1435
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
Modified on Fri Sep 20 14:58:20 2024 by modify_doxy.py rev. 669887