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

Go to the SVN repository for this file.

1 #ifndef CONTINFO__HPP
2 #define CONTINFO__HPP
3 
4 /* $Id: continfo.hpp 79683 2017-10-03 13:21:50Z 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 <corelib/ncbiutil.hpp>
37 #include <serial/typeinfo.hpp>
38 #include <serial/impl/typeref.hpp>
39 #include <memory>
40 
41 
42 /** @addtogroup TypeInfoCPP
43  *
44  * @{
45  */
46 
47 
49 
52 
54 {
55  typedef CTypeInfo CParent;
56 public:
57  CContainerTypeInfo(size_t size,
58  TTypeInfo elementType, bool randomOrder);
59  CContainerTypeInfo(size_t size,
60  const CTypeRef& elementType, bool randomOrder);
61  CContainerTypeInfo(size_t size, const char* name,
62  TTypeInfo elementType, bool randomOrder);
63  CContainerTypeInfo(size_t size, const char* name,
64  const CTypeRef& elementType, bool randomOrder);
65  CContainerTypeInfo(size_t size, const string& name,
66  TTypeInfo elementType, bool randomOrder);
67  CContainerTypeInfo(size_t size, const string& name,
68  const CTypeRef& elementType, bool randomOrder);
69 
71 
72  bool RandomElementsOrder(void) const;
73 
74  virtual EMayContainType GetMayContainType(TTypeInfo type) const override;
75 
76  virtual void Assign(TObjectPtr dst, TConstObjectPtr src,
77  ESerialRecursionMode how = eRecursive) const override;
78  virtual bool Equals(TConstObjectPtr object1, TConstObjectPtr object2,
79  ESerialRecursionMode how = eRecursive) const override;
80 
81  // iterators methods (private)
83  {
84  public:
87 
89 
92  void Reset(void);
93 
97  };
98 
99  class CIterator
100  {
101  public:
102  CIterator(void);
103  ~CIterator(void);
104 
106 
109  void Reset(void);
110 
114  };
115 
116  bool InitIterator(CConstIterator& it, TConstObjectPtr containerPtr) const;
118  void CopyIterator(CConstIterator& dst, const CConstIterator& src) const;
119  bool NextElement(CConstIterator& it) const;
121 
122  bool InitIterator(CIterator& it, TObjectPtr containerPtr) const;
123  void ReleaseIterator(CIterator& it) const;
124  void CopyIterator(CIterator& dst, const CIterator& src) const;
125  bool NextElement(CIterator& it) const;
127  bool EraseElement(CIterator& it) const;
128  void EraseAllElements(CIterator& it) const;
129 
131  ESerialRecursionMode how = eRecursive) const;
133 
134  // corresponding to size() and reserve() respectively
135  size_t GetElementCount(TConstObjectPtr containerPtr) const;
136  void ReserveElements(TObjectPtr containerPtr, size_t new_count) const;
137  typedef bool (*TInitIteratorConst)(CConstIterator&);
138  typedef void (*TReleaseIteratorConst)(CConstIterator&);
139  typedef void (*TCopyIteratorConst)(CConstIterator&, const CConstIterator&);
140  typedef bool (*TNextElementConst)(CConstIterator&);
141  typedef TConstObjectPtr (*TGetElementPtrConst)(const CConstIterator&);
142 
143  typedef bool (*TInitIterator)(CIterator&);
144  typedef void (*TReleaseIterator)(CIterator&);
145  typedef void (*TCopyIterator)(CIterator&, const CIterator&);
146  typedef bool (*TNextElement)(CIterator&);
147  typedef TObjectPtr (*TGetElementPtr)(const CIterator&);
148  typedef bool (*TEraseElement)(CIterator&);
149  typedef void (*TEraseAllElements)(CIterator&);
150 
151  typedef TObjectPtr (*TAddElement)(const CContainerTypeInfo* cType,
152  TObjectPtr cPtr, TConstObjectPtr ePtr,
154  typedef TObjectPtr (*TAddElementIn)(const CContainerTypeInfo* cType,
155  TObjectPtr cPtr, CObjectIStream& in);
156 
157  typedef size_t (*TGetElementCount)(const CContainerTypeInfo* cType,
158  TConstObjectPtr containerPtr);
159  typedef void (*TReserveElements)(const CContainerTypeInfo* cType,
160  TObjectPtr cPtr, size_t new_count);
161 
162  void SetConstIteratorFunctions(TInitIteratorConst, TReleaseIteratorConst,
163  TCopyIteratorConst, TNextElementConst,
164  TGetElementPtrConst);
165  void SetIteratorFunctions(TInitIterator, TReleaseIterator,
166  TCopyIterator, TNextElement,
167  TGetElementPtr,
168  TEraseElement, TEraseAllElements);
169  void SetAddElementFunctions(TAddElement, TAddElementIn);
170  void SetCountFunctions(TGetElementCount, TReserveElements = 0);
171 
172 protected:
173  static void ReadContainer(CObjectIStream& in,
174  TTypeInfo objectType,
175  TObjectPtr objectPtr);
176  static void WriteContainer(CObjectOStream& out,
177  TTypeInfo objectType,
178  TConstObjectPtr objectPtr);
179  static void SkipContainer(CObjectIStream& in,
180  TTypeInfo objectType);
181  static void CopyContainer(CObjectStreamCopier& copier,
182  TTypeInfo objectType);
183 
184 protected:
187 
188 private:
189  void InitContainerTypeInfoFunctions(void);
190 
191  // iterator functions
192  TInitIteratorConst m_InitIteratorConst;
193  TReleaseIteratorConst m_ReleaseIteratorConst;
194  TCopyIteratorConst m_CopyIteratorConst;
195  TNextElementConst m_NextElementConst;
196  TGetElementPtrConst m_GetElementPtrConst;
197 
198  TInitIterator m_InitIterator;
199  TReleaseIterator m_ReleaseIterator;
200  TCopyIterator m_CopyIterator;
201  TNextElement m_NextElement;
202  TGetElementPtr m_GetElementPtr;
203  TEraseElement m_EraseElement;
204  TEraseAllElements m_EraseAllElements;
205 
206  TAddElement m_AddElement;
207  TAddElementIn m_AddElementIn;
208 
209  TGetElementCount m_GetElementCount;
210  TReserveElements m_ReserveElements;
211 };
212 
214 {
215 public:
217 
220  const CContainerTypeInfo* containerType);
222 
225 
226  void Init(TConstObjectPtr containerPtr,
227  const CContainerTypeInfo* containerType);
228 
230 
231  bool Valid(void) const;
232  TMemberIndex GetIndex(void) const;
233  void Next(void);
234 
235  pair<TConstObjectPtr, TTypeInfo> Get(void) const;
236 
237  size_t GetElementCount(void) const;
238 
239 private:
243 };
244 
246 {
247 public:
249 
252  const CContainerTypeInfo* containerType);
255  void Init(TObjectPtr containerPtr,
256  const CContainerTypeInfo* containerType);
257 
259 
260  bool Valid(void) const;
261  TMemberIndex GetIndex(void) const;
262  void Next(void);
263  void Erase(void);
264  void EraseAll(void);
265 
266  pair<TObjectPtr, TTypeInfo> Get(void) const;
267 
268 private:
272 };
273 
274 
275 /* @} */
276 
277 
278 #include <serial/impl/continfo.inl>
279 
281 
282 #endif /* CONTINFO__HPP */
CNcbiOstream & WriteContainer(CNcbiOstream &os, const TCont &cont)
Write a container to a stream.
Definition: cgi_serial.hpp:216
CNcbiIstream & ReadContainer(CNcbiIstream &is, TCont &cont)
Read a container from a stream.
Definition: cgi_serial.hpp:234
CObjectIStream –.
Definition: objistr.hpp:93
CObjectOStream –.
Definition: objostr.hpp:83
CObjectStreamCopier –.
Definition: objcopy.hpp:71
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
#define bool
Definition: bool.h:34
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
const void * TConstObjectPtr
Definition: serialdef.hpp:59
@ 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
bool InitIterator(CIterator &it, TObjectPtr containerPtr) const
TReleaseIteratorConst m_ReleaseIteratorConst
Definition: continfo.hpp:193
TObjectPtr GetContainerPtr(void) const
CContainerTypeInfo::CIterator TIterator
Definition: continfo.hpp:248
void ReleaseIterator(CConstIterator &it) const
CContainerElementIterator(TObjectPtr containerPtr, const CContainerTypeInfo *containerType)
TObjectPtr AddElement(TObjectPtr containerPtr, CObjectIStream &in) const
CConstContainerElementIterator(TConstObjectPtr containerPtr, const CContainerTypeInfo *containerType)
TNextElement m_NextElement
Definition: continfo.hpp:201
bool EraseElement(CIterator &it) const
TCopyIterator m_CopyIterator
Definition: continfo.hpp:200
TAddElement m_AddElement
Definition: continfo.hpp:206
bool RandomElementsOrder(void) const
TGetElementPtr m_GetElementPtr
Definition: continfo.hpp:202
NCBI_NS_NCBI::TObjectPtr TObjectPtr
Definition: continfo.hpp:105
void Init(TObjectPtr containerPtr, const CContainerTypeInfo *containerType)
TObjectPtr AddElement(TObjectPtr containerPtr, TConstObjectPtr elementPtr, ESerialRecursionMode how=eRecursive) const
const CContainerTypeInfo * m_ContainerType
Definition: continfo.hpp:111
const CContainerTypeInfo * GetContainerType(void) const
virtual EMayContainType GetMayContainType(TTypeInfo type) const
Definition: typeinfo.cpp:320
TCopyIteratorConst m_CopyIteratorConst
Definition: continfo.hpp:194
TObjectPtr GetContainerPtr(void) const
NCBI_NS_NCBI::TConstObjectPtr TObjectPtr
Definition: continfo.hpp:88
size_t GetElementCount(TConstObjectPtr containerPtr) const
bool Valid(void) const
void CopyIterator(CIterator &dst, const CIterator &src) const
void ReserveElements(TObjectPtr containerPtr, size_t new_count) const
CTypeRef m_ElementType
Definition: continfo.hpp:185
TAddElementIn m_AddElementIn
Definition: continfo.hpp:207
const CContainerTypeInfo * GetContainerType(void) const
TInitIteratorConst m_InitIteratorConst
Definition: continfo.hpp:192
TMemberIndex GetIndex(void) const
TEraseAllElements m_EraseAllElements
Definition: continfo.hpp:204
TMemberIndex m_ElementIndex
Definition: continfo.hpp:271
virtual void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how=eRecursive) const =0
Set object to copy of another one.
CContainerElementIterator(const CContainerElementIterator &src)
void ReleaseIterator(CIterator &it) const
TReleaseIterator m_ReleaseIterator
Definition: continfo.hpp:199
TGetElementCount m_GetElementCount
Definition: continfo.hpp:209
TObjectPtr GetElementPtr(const CIterator &it) const
TNextElementConst m_NextElementConst
Definition: continfo.hpp:195
TReserveElements m_ReserveElements
Definition: continfo.hpp:210
CConstContainerElementIterator(const CConstContainerElementIterator &src)
void CopyIterator(CConstIterator &dst, const CConstIterator &src) const
TConstObjectPtr GetElementPtr(const CConstIterator &it) const
TInitIterator m_InitIterator
Definition: continfo.hpp:198
const CContainerTypeInfo * m_ContainerType
Definition: continfo.hpp:94
pair< TConstObjectPtr, TTypeInfo > Get(void) const
bool InitIterator(CConstIterator &it, TConstObjectPtr containerPtr) const
pair< TObjectPtr, TTypeInfo > Get(void) const
CConstContainerElementIterator & operator=(const CConstContainerElementIterator &src)
virtual bool Equals(TConstObjectPtr object1, TConstObjectPtr object2, ESerialRecursionMode how=eRecursive) const =0
Check if both objects contain the same values.
bool NextElement(CConstIterator &it) const
void EraseAllElements(CIterator &it) const
CTypeInfo CParent
Definition: continfo.hpp:55
TEraseElement m_EraseElement
Definition: continfo.hpp:203
TTypeInfo GetElementType(void) const
size_t GetElementCount(void) const
CContainerTypeInfo::CConstIterator TIterator
Definition: continfo.hpp:216
CContainerElementIterator & operator=(const CContainerElementIterator &src)
void Init(TConstObjectPtr containerPtr, const CContainerTypeInfo *containerType)
TTypeInfo GetElementType(void) const
TGetElementPtrConst m_GetElementPtrConst
Definition: continfo.hpp:196
TTypeInfo GetElementType(void) const
bool NextElement(CIterator &it) const
TMemberIndex GetIndex(void) const
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1435
const struct ncbi::grid::netcache::search::fields::SIZE size
Useful/utility classes and methods.
std::istream & in(std::istream &in_, double &x_)
void CopyContainer(const C1 &src, C2 &dst)
Definition: type.c:6
Modified on Sun Jul 21 04:15:21 2024 by modify_doxy.py rev. 669887