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

Go to the SVN repository for this file.

1 #ifndef MEMBER__HPP
2 #define MEMBER__HPP
3 
4 /* $Id: member.hpp 99791 2023-05-10 18:00:42Z vasilche $
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/serialutil.hpp>
37 #include <serial/impl/item.hpp>
38 #include <serial/impl/hookdata.hpp>
39 #include <serial/impl/hookfunc.hpp>
40 #include <serial/typeinfo.hpp>
41 
42 
43 /** @addtogroup FieldsComplex
44  *
45  * @{
46  */
47 
48 
50 
51 class CClassTypeInfoBase;
52 
53 class CObjectIStream;
54 class CObjectOStream;
56 
61 
62 class CDelayBuffer;
63 
65 
67 {
68  typedef CItemInfo CParent;
69 public:
70  typedef TConstObjectPtr (*TMemberGetConst)(const CMemberInfo* memberInfo,
71  TConstObjectPtr classPtr);
72  typedef TObjectPtr (*TMemberGet)(const CMemberInfo* memberInfo,
73  TObjectPtr classPtr);
74 
75  CMemberInfo(const CClassTypeInfoBase* classType, const CMemberId& id,
77  CMemberInfo(const CClassTypeInfoBase* classType, const CMemberId& id,
79  CMemberInfo(const CClassTypeInfoBase* classType, const char* id,
81  CMemberInfo(const CClassTypeInfoBase* classType, const char* id,
83 
84  const CClassTypeInfoBase* GetClassType(void) const;
85 
86  bool Optional(void) const;
87  CMemberInfo* SetOptional(void);
88  bool Nillable(void) const;
89  CMemberInfo* SetNillable(void);
90  CMemberInfo* SetNoPrefix(void);
91  CMemberInfo* SetAttlist(void);
92  CMemberInfo* SetNotag(void);
93  CMemberInfo* SetAnyContent(void);
94  CMemberInfo* SetCompressed(void);
95  CMemberInfo* SetNsQualified(bool qualified);
96 
98  CMemberInfo* SetDefault(TConstObjectPtr def);
99  CMemberInfo* SetElementDefault(TConstObjectPtr def);
100 
101  bool HaveSetFlag(void) const;
102  CMemberInfo* SetSetFlag(const bool* setFlag);
103  CMemberInfo* SetSetFlag(const Uint4* setFlag);
104  CMemberInfo* SetOptional(const bool* setFlag);
105 
106  enum ESetFlag {
107  eSetNo = 0,
108  eSetMaybe = 1,
109  eSetYes = 3
110  };
111 
112  /// return current value of 'setFlag'
114 
115  /// true if 'setFlag' is not eSetNo
116  bool GetSetFlagYes(TConstObjectPtr object) const;
117  /// true if 'setFlag' is eSetNo
118  bool GetSetFlagNo(TConstObjectPtr object) const;
119 
120  /// set value of 'setFlag'
121  void UpdateSetFlag(TObjectPtr object, ESetFlag value) const;
122  /// set value of 'setFlag' from object of the same type (if necessary)
123  void UpdateSetFlag(TObjectPtr object, TConstObjectPtr src) const;
124  /// set 'setFlag' to eSetYes
125  void UpdateSetFlagYes(TObjectPtr object) const;
126  /// set 'setFlag' to eSetMaybe
127  void UpdateSetFlagMaybe(TObjectPtr object) const;
128  /// set 'setFlag' to eSetNo and return true if previous value wasn't eSetNo
129  bool UpdateSetFlagNo(TObjectPtr object) const;
130  bool CompareSetFlags(TConstObjectPtr object1,
131  TConstObjectPtr object2) const;
132 
133  bool CanBeDelayed(void) const;
134  CMemberInfo* SetDelayBuffer(CDelayBuffer* buffer);
137 
138  void SetParentClass(void);
139 
140  // I/O
141  void ReadMember(CObjectIStream& in, TObjectPtr classPtr) const;
144  void CopyMember(CObjectStreamCopier& copier) const;
148 
151 
152  // hooks
153  void SetGlobalReadHook(CReadClassMemberHook* hook);
155  void ResetGlobalReadHook(void);
156  void ResetLocalReadHook(CObjectIStream& in);
157  void SetPathReadHook(CObjectIStream* in, const string& path,
158  CReadClassMemberHook* hook);
159 
160  void SetGlobalWriteHook(CWriteClassMemberHook* hook);
162  void ResetGlobalWriteHook(void);
163  void ResetLocalWriteHook(CObjectOStream& out);
164  void SetPathWriteHook(CObjectOStream* out, const string& path,
165  CWriteClassMemberHook* hook);
166 
168  void ResetLocalSkipHook(CObjectIStream& in);
169  void SetPathSkipHook(CObjectIStream* in, const string& path,
170  CSkipClassMemberHook* hook);
171 
172  void SetGlobalCopyHook(CCopyClassMemberHook* hook);
174  CCopyClassMemberHook* hook);
175  void ResetGlobalCopyHook(void);
176  void ResetLocalCopyHook(CObjectStreamCopier& copier);
177  void SetPathCopyHook(CObjectStreamCopier* copier, const string& path,
178  CCopyClassMemberHook* hook);
179 
180  // default I/O (without hooks)
182  TObjectPtr classPtr) const;
184  TObjectPtr classPtr) const;
186  TConstObjectPtr classPtr) const;
191 
192  virtual void UpdateDelayedBuffer(CObjectIStream& in,
193  TObjectPtr classPtr) const override;
194 
195 private:
196  // Create parent class object
197  TObjectPtr CreateClass(void) const;
198 
199  // containing class type info
201  // default value
203  // offset of 'SET' flag inside object
206  // offset of delay buffer inside object
208 
209  TMemberGetConst m_GetConstFunction;
210  TMemberGet m_GetFunction;
211 
216 
217  void SetReadFunction(TMemberReadFunction func);
218  void SetReadMissingFunction(TMemberReadFunction func);
219  void SetWriteFunction(TMemberWriteFunction func);
220  void SetCopyFunction(TMemberCopyFunction func);
221  void SetCopyMissingFunction(TMemberCopyFunction func);
222  void SetSkipFunction(TMemberSkipFunction func);
223  void SetSkipMissingFunction(TMemberSkipFunction func);
224 
225  virtual void UpdateFunctions(void) override;
226 
227  friend class CMemberInfoFunctions;
228 };
229 
230 /* @} */
231 
232 
233 #include <serial/impl/member.inl>
234 
236 
237 #endif /* MEMBER__HPP */
Copy hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:266
CDelayBuffer.
Definition: delaybuf.hpp:58
CObjectIStream –.
Definition: objistr.hpp:93
CObjectOStream –.
Definition: objostr.hpp:83
CObjectStreamCopier –.
Definition: objcopy.hpp:71
Read hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:78
Skip hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:223
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
Write hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:175
char value[7]
Definition: config.c:431
Include a standard set of the NCBI C++ Toolkit most basic headers.
std::ofstream out("events_result.xml")
main entry point for tests
virtual void UpdateDelayedBuffer(CObjectIStream &in, TObjectPtr classPtr) const =0
Uint4 m_BitSetMask
Definition: member.hpp:205
bool Optional(void) const
const CClassTypeInfoBase * GetClassType(void) const
void UpdateSetFlag(TObjectPtr object, TConstObjectPtr src) const
set value of 'setFlag' from object of the same type (if necessary)
void DefaultReadMissingMember(CObjectIStream &in, TObjectPtr classPtr) const
CHookPairData< CCopyClassMemberHook, TMemberCopyFunction > m_CopyHookData
Definition: member.hpp:215
TMemberGetConst m_GetConstFunction
Definition: member.hpp:209
CItemInfo CParent
Definition: member.hpp:68
bool UpdateSetFlagNo(TObjectPtr object) const
set 'setFlag' to eSetNo and return true if previous value wasn't eSetNo
bool GetSetFlagNo(TConstObjectPtr object) const
true if 'setFlag' is eSetNo
TConstObjectPtr GetDefault(void) const
void WriteMember(CObjectOStream &out, TConstObjectPtr classPtr) const
TMemberGet m_GetFunction
Definition: member.hpp:210
void SkipMember(CObjectIStream &in) const
TConstObjectPtr m_Default
Definition: member.hpp:202
void DefaultCopyMember(CObjectStreamCopier &copier) const
TObjectPtr GetMemberPtr(TObjectPtr classPtr) const
void DefaultSkipMissingMember(CObjectIStream &in) const
void UpdateSetFlagYes(TObjectPtr object) const
set 'setFlag' to eSetYes
void UpdateSetFlagMaybe(TObjectPtr object) const
set 'setFlag' to eSetMaybe
CHookData< CWriteClassMemberHook, TMemberWriteFunction > m_WriteHookData
Definition: member.hpp:213
void CopyMissingMember(CObjectStreamCopier &copier) const
bool Nillable(void) const
virtual void UpdateFunctions(void)=0
TPointerOffsetType m_DelayOffset
Definition: member.hpp:207
CDelayBuffer & GetDelayBuffer(TObjectPtr object) const
const CDelayBuffer & GetDelayBuffer(TConstObjectPtr object) const
void CopyMember(CObjectStreamCopier &copier) const
CHookPairData< CReadClassMemberHook, TMemberReadFunction > m_ReadHookData
Definition: member.hpp:212
ESetFlag GetSetFlag(TConstObjectPtr object) const
return current value of 'setFlag'
const CClassTypeInfoBase * m_ClassType
Definition: member.hpp:200
void UpdateSetFlag(TObjectPtr object, ESetFlag value) const
set value of 'setFlag'
TConstObjectPtr GetMemberPtr(TConstObjectPtr classPtr) const
TPointerOffsetType m_SetFlagOffset
Definition: member.hpp:204
void SkipMissingMember(CObjectIStream &in) const
bool CanBeDelayed(void) const
void ReadMissingMember(CObjectIStream &in, TObjectPtr classPtr) const
bool HaveSetFlag(void) const
CHookPairData< CSkipClassMemberHook, TMemberSkipFunction > m_SkipHookData
Definition: member.hpp:214
void DefaultSkipMember(CObjectIStream &in) const
void DefaultWriteMember(CObjectOStream &out, TConstObjectPtr classPtr) const
void DefaultCopyMissingMember(CObjectStreamCopier &copier) const
void ReadMember(CObjectIStream &in, TObjectPtr classPtr) const
void DefaultReadMember(CObjectIStream &in, TObjectPtr classPtr) const
bool GetSetFlagYes(TConstObjectPtr object) const
true if 'setFlag' is not eSetNo
void * TObjectPtr
Definition: serialdef.hpp:55
const void * TConstObjectPtr
Definition: serialdef.hpp:59
ssize_t TPointerOffsetType
Definition: serialdef.hpp:241
void(* TMemberReadFunction)(CObjectIStream &in, const CMemberInfo *memberInfo, TObjectPtr classPtr)
Definition: hookfunc.hpp:65
void(* TMemberWriteFunction)(CObjectOStream &out, const CMemberInfo *memberInfo, TConstObjectPtr classPtr)
Definition: hookfunc.hpp:68
void(* TMemberSkipFunction)(CObjectIStream &in, const CMemberInfo *memberInfo)
Definition: hookfunc.hpp:73
void(* TMemberCopyFunction)(CObjectStreamCopier &copier, const CMemberInfo *memberInfo)
Definition: hookfunc.hpp:71
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1435
std::istream & in(std::istream &in_, double &x_)
void SetLocalCopyHook(const CObjectTypeInfo &obj_type_info, CObjectStreamCopier &copier, _Func _func)
void SetLocalSkipHook(const CObjectTypeInfo &obj_type_info, CObjectIStream &istr, _Func _func)
void SetLocalWriteHook(const CObjectTypeInfo &obj_type_info, CObjectOStream &ostr, _Func _func)
void SetLocalReadHook(const CObjectTypeInfo &obj_type_info, CObjectIStream &ostr, _Func _func)
static pcre_uint8 * buffer
Definition: pcretest.c:1051
int offset
Definition: replacements.h:160
Definition: type.c:6
Modified on Wed Feb 28 07:11:19 2024 by modify_doxy.py rev. 669887