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

Go to the SVN repository for this file.

1 /* $Id: continfo.cpp 66826 2015-03-26 17:05:21Z vasilche $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Eugene Vasilchenko
27 *
28 * File Description:
29 * !!! PUT YOUR DESCRIPTION HERE !!!
30 */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbistd.hpp>
34 #include <corelib/ncbiutil.hpp>
35 #include <serial/impl/continfo.hpp>
36 #include <serial/objistr.hpp>
37 #include <serial/objostr.hpp>
38 #include <serial/objcopy.hpp>
39 #include <serial/serialutil.hpp>
40 #include <serial/error_codes.hpp>
41 
42 
43 #define NCBI_USE_ERRCODE_X Serial_TypeInfo
44 
46 
48  TTypeInfo elementType,
49  bool randomOrder)
51  m_ElementType(elementType), m_RandomOrder(randomOrder)
52 {
54 }
55 
57  const CTypeRef& elementType,
58  bool randomOrder)
60  m_ElementType(elementType), m_RandomOrder(randomOrder)
61 {
63 }
64 
66  TTypeInfo elementType,
67  bool randomOrder)
69  m_ElementType(elementType), m_RandomOrder(randomOrder)
70 {
72 }
73 
75  const CTypeRef& elementType,
76  bool randomOrder)
78  m_ElementType(elementType), m_RandomOrder(randomOrder)
79 {
81 }
82 
83 CContainerTypeInfo::CContainerTypeInfo(size_t size, const string& name,
84  TTypeInfo elementType,
85  bool randomOrder)
87  m_ElementType(elementType), m_RandomOrder(randomOrder)
88 {
90 }
91 
92 CContainerTypeInfo::CContainerTypeInfo(size_t size, const string& name,
93  const CTypeRef& elementType,
94  bool randomOrder)
96  m_ElementType(elementType), m_RandomOrder(randomOrder)
97 {
99 }
100 
102 {
103 public:
104  NCBI_NORETURN
105  static void Throw(const char* message)
106  {
107  NCBI_THROW(CSerialException,eFail, message);
108  }
110  {
111  Throw("cannot create iterator");
112  return false;
113  }
115  {
116  Throw("cannot create iterator");
117  return false;
118  }
119  static TObjectPtr AddElement(const CContainerTypeInfo* /*containerType*/,
120  TObjectPtr /*containerPtr*/,
121  TConstObjectPtr /*elementPtr*/,
123  {
124  Throw("illegal call");
125  return 0;
126  }
127 
128  static TObjectPtr AddElementIn(const CContainerTypeInfo* /*containerType*/,
129  TObjectPtr /*containerPtr*/,
130  CObjectIStream& /*in*/)
131  {
132  Throw("illegal call");
133  return 0;
134  }
135 
137  {
138  Throw("illegal call");
139  return 0;
140  }
141 };
142 
144 {
155 }
156 
157 void CContainerTypeInfo::SetAddElementFunctions(TAddElement addElement,
158  TAddElementIn addElementIn)
159 {
160  m_AddElement = addElement;
161  m_AddElementIn = addElementIn;
162 }
163 
164 void CContainerTypeInfo::SetCountFunctions(TGetElementCount getElementCount,
165  TReserveElements reserveElements)
166 {
167  m_GetElementCount = getElementCount;
168  m_ReserveElements = reserveElements;
169 }
170 
172  TReleaseIteratorConst release,
173  TCopyIteratorConst copy,
174  TNextElementConst next,
175  TGetElementPtrConst get)
176 {
178  m_ReleaseIteratorConst = release;
181  m_GetElementPtrConst = get;
182 }
183 
185  TReleaseIterator release,
186  TCopyIterator copy,
187  TNextElement next,
188  TGetElementPtr get,
189  TEraseElement erase,
190  TEraseAllElements erase_all)
191 {
193  m_ReleaseIterator = release;
196  m_GetElementPtr = get;
197  m_EraseElement = erase;
198  m_EraseAllElements = erase_all;
199 }
200 
203 {
205 }
206 
208  ESerialRecursionMode how) const
209 {
210  if (how == eShallowChildless) {
211  SetDefault(dst); // clear destination container
212  return;
213  }
214  CIterator idst;
215  CConstIterator isrc;
216  bool old_element = InitIterator(idst,dst);
217  if ( InitIterator(isrc, src) ) {
218  TTypeInfo elementType = GetElementType();
219  do {
220  TConstObjectPtr elementPtr = GetElementPtr(isrc);
221  if (old_element) {
222  elementType->Assign(GetElementPtr(idst), elementPtr, how);
223  old_element = NextElement(idst);
224  } else {
225  AddElement(dst, elementPtr, how);
226  }
227  } while ( NextElement(isrc) );
228  }
229  if (old_element) {
230  EraseAllElements(idst);
231  }
232 }
233 
235  ESerialRecursionMode how) const
236 {
237  if (how == eShallowChildless) {
238  return true;
239  }
240  TTypeInfo elementType = GetElementType();
241  CConstIterator i1, i2;
242  if ( InitIterator(i1, object1) ) {
243  if ( !InitIterator(i2, object2) )
244  return false;
245  if ( !elementType->Equals(GetElementPtr(i1),
246  GetElementPtr(i2), how) )
247  return false;
248  while ( NextElement(i1) ) {
249  if ( !NextElement(i2) )
250  return false;
251  if ( !elementType->Equals(GetElementPtr(i1),
252  GetElementPtr(i2), how) )
253  return false;
254  }
255  return !NextElement(i2);
256  }
257  else {
258  return !InitIterator(i2, object2);
259  }
260 }
261 
263  TTypeInfo objectType,
264  TObjectPtr objectPtr)
265 {
266  const CContainerTypeInfo* containerType =
268 
269  in.ReadContainer(containerType, objectPtr);
270 }
271 
273  TTypeInfo objectType,
274  TConstObjectPtr objectPtr)
275 {
276  const CContainerTypeInfo* containerType =
278 
279  out.WriteContainer(containerType, objectPtr);
280 }
281 
283  TTypeInfo objectType)
284 {
285  const CContainerTypeInfo* containerType =
287 
288  copier.CopyContainer(containerType);
289 }
290 
292  TTypeInfo objectType)
293 {
294  const CContainerTypeInfo* containerType =
296 
297  in.SkipContainer(containerType);
298 }
299 
static bool InitIterator(CContainerTypeInfo::CIterator &)
Definition: continfo.cpp:114
static bool InitIteratorConst(CContainerTypeInfo::CConstIterator &)
Definition: continfo.cpp:109
static size_t GetElementCount(const CContainerTypeInfo *, TConstObjectPtr)
Definition: continfo.cpp:136
static TObjectPtr AddElement(const CContainerTypeInfo *, TObjectPtr, TConstObjectPtr, ESerialRecursionMode)
Definition: continfo.cpp:119
static void Throw(const char *message)
Definition: continfo.cpp:105
static TObjectPtr AddElementIn(const CContainerTypeInfo *, TObjectPtr, CObjectIStream &)
Definition: continfo.cpp:128
CObjectIStream –.
Definition: objistr.hpp:93
CObjectOStream –.
Definition: objostr.hpp:83
CObjectStreamCopier –.
Definition: objcopy.hpp:71
Root class for all serialization exceptions.
Definition: exception.hpp:50
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
static void DLIST_NAME() init(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:40
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:56
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
ESerialRecursionMode
How to assign and compare child sub-objects of serial objects.
Definition: serialdef.hpp:191
void * TObjectPtr
Definition: serialdef.hpp:55
const void * TConstObjectPtr
Definition: serialdef.hpp:59
static const TObjectType * SafeCast(TTypeInfo type)
Definition: serialutil.hpp:76
@ eShallowChildless
Set sub-object pointers to 0.
Definition: serialdef.hpp:194
@ eTypeFamilyContainer
Definition: serialdef.hpp:142
void CopyContainer(const CContainerTypeInfo *containerType)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
void SetWriteFunction(TTypeWriteFunction func)
Definition: typeinfo.cpp:487
virtual void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how=eRecursive) const override
Set object to copy of another one.
Definition: continfo.cpp:207
TReleaseIteratorConst m_ReleaseIteratorConst
Definition: continfo.hpp:193
virtual bool Equals(TConstObjectPtr object1, TConstObjectPtr object2, ESerialRecursionMode how=eRecursive) const override
Check if both objects contain the same values.
Definition: continfo.cpp:234
virtual EMayContainType GetMayContainType(TTypeInfo type) const override
Definition: continfo.cpp:202
CContainerTypeInfo(size_t size, TTypeInfo elementType, bool randomOrder)
Definition: continfo.cpp:47
virtual CTypeInfo * SetTag(CAsnBinaryDefs::TLongTag tag, CAsnBinaryDefs::ETagClass tagclass=CAsnBinaryDefs::eUniversal, CAsnBinaryDefs::ETagType tagtype=CAsnBinaryDefs::eAutomatic)
Definition: typeinfo.cpp:172
TNextElement m_NextElement
Definition: continfo.hpp:201
TCopyIterator m_CopyIterator
Definition: continfo.hpp:200
TAddElement m_AddElement
Definition: continfo.hpp:206
TGetElementPtr m_GetElementPtr
Definition: continfo.hpp:202
TObjectPtr AddElement(TObjectPtr containerPtr, TConstObjectPtr elementPtr, ESerialRecursionMode how=eRecursive) const
void InitContainerTypeInfoFunctions(void)
Definition: continfo.cpp:143
TCopyIteratorConst m_CopyIteratorConst
Definition: continfo.hpp:194
TAddElementIn m_AddElementIn
Definition: continfo.hpp:207
TInitIteratorConst m_InitIteratorConst
Definition: continfo.hpp:192
void SetConstIteratorFunctions(TInitIteratorConst, TReleaseIteratorConst, TCopyIteratorConst, TNextElementConst, TGetElementPtrConst)
Definition: continfo.cpp:171
TEraseAllElements m_EraseAllElements
Definition: continfo.hpp:204
virtual void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode how=eRecursive) const =0
Set object to copy of another one.
TReleaseIterator m_ReleaseIterator
Definition: continfo.hpp:199
TGetElementCount m_GetElementCount
Definition: continfo.hpp:209
void SetSkipFunction(TTypeSkipFunction func)
Definition: typeinfo.cpp:497
TNextElementConst m_NextElementConst
Definition: continfo.hpp:195
void SetCountFunctions(TGetElementCount, TReserveElements=0)
Definition: continfo.cpp:164
TReserveElements m_ReserveElements
Definition: continfo.hpp:210
TConstObjectPtr GetElementPtr(const CConstIterator &it) const
TInitIterator m_InitIterator
Definition: continfo.hpp:198
bool InitIterator(CConstIterator &it, TConstObjectPtr containerPtr) const
void SetAddElementFunctions(TAddElement, TAddElementIn)
Definition: continfo.cpp:157
static void SkipContainer(CObjectIStream &in, TTypeInfo objectType)
Definition: continfo.cpp:291
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
EMayContainType IsOrMayContainType(TTypeInfo type) const
TEraseElement m_EraseElement
Definition: continfo.hpp:203
void SetCopyFunction(TTypeCopyFunction func)
Definition: typeinfo.cpp:492
virtual void SetDefault(TObjectPtr dst) const =0
Set object to default value.
static void ReadContainer(CObjectIStream &in, TTypeInfo objectType, TObjectPtr objectPtr)
Definition: continfo.cpp:262
TTypeInfo GetElementType(void) const
TGetElementPtrConst m_GetElementPtrConst
Definition: continfo.hpp:196
static void WriteContainer(CObjectOStream &out, TTypeInfo objectType, TConstObjectPtr objectPtr)
Definition: continfo.cpp:272
void SetIteratorFunctions(TInitIterator, TReleaseIterator, TCopyIterator, TNextElement, TGetElementPtr, TEraseElement, TEraseAllElements)
Definition: continfo.cpp:184
static void CopyContainer(CObjectStreamCopier &copier, TTypeInfo objectType)
Definition: continfo.cpp:282
void SetReadFunction(TTypeReadFunction func)
Definition: typeinfo.cpp:477
Definition of all error codes used in serial libraries (xser.lib, xcser.lib).
const struct ncbi::grid::netcache::search::fields::SIZE size
Useful/utility classes and methods.
std::istream & in(std::istream &in_, double &x_)
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
Definition: type.c:6
Modified on Wed May 22 11:28:27 2024 by modify_doxy.py rev. 669887