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

Go to the SVN repository for this file.

1 /* $Id: stltypes.cpp 84832 2018-12-17 14:45:09Z gouriano $
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 
33 #include <ncbi_pch.hpp>
35 #include <serial/serialimpl.hpp>
36 #include <serial/exception.hpp>
39 #include <serial/impl/typemap.hpp>
41 
42 
44 
55 
57 {
58  return s_TypeMap_auto_ptr->GetTypeInfo(arg, f);
59 }
60 
62 {
63  return s_TypeMap_CRef->GetTypeInfo(arg, f);
64 }
65 
67 {
68  return s_TypeMap_CConstRef->GetTypeInfo(arg, f);
69 }
70 
72 {
73  return s_TypeMap_AutoPtr->GetTypeInfo(arg, f);
74 }
75 
77 {
78  return s_TypeMap_list->GetTypeInfo(arg, f);
79 }
80 
82 {
83  return s_TypeMapSet_list->GetTypeInfo(arg, f);
84 }
85 
87 {
88  return s_TypeMap_vector->GetTypeInfo(arg, f);
89 }
90 
92 {
93  return s_TypeMapSet_vector->GetTypeInfo(arg, f);
94 }
95 
97 {
98  return s_TypeMap_set->GetTypeInfo(arg, f);
99 }
100 
102 {
103  return s_TypeMap_multiset->GetTypeInfo(arg, f);
104 }
105 
108 {
109  return f(arg1, arg2);
110 }
111 
114 {
115  return f(arg1, arg2);
116 }
117 
120 {
121  if ( !storage ) {
123  if ( !storage ) {
124  storage = f(arg);
125  }
126  }
127  return storage;
128 }
129 
131  TTypeInfo arg1, TTypeInfo arg2,
133 {
134  if ( !storage ) {
136  if ( !storage ) {
137  storage = f(arg1, arg2);
138  }
139  }
140  return storage;
141 }
142 
144 {
145  NCBI_THROW(CSerialException,eFail, "cannot get pointer to element of set");
146 }
147 
149 {
150  NCBI_THROW(CSerialException,eFail, "duplicate element of unique container");
151 }
152 
154  TTypeInfo type, bool randomOrder,
155  const string& name)
156  : CParent(size, name, type, randomOrder)
157 {
158 }
159 
161  TTypeInfo type, bool randomOrder)
162  : CParent(size, type, randomOrder)
163 {
164 }
165 
167  const CTypeRef& type, bool randomOrder)
168  : CParent(size, type, randomOrder)
169 {
170 }
171 
173 {
174  m_DataId = id;
175 }
176 
178 {
179  return m_IsDefault(objectPtr);
180 }
181 
183 {
184  m_SetDefault(objectPtr);
185 }
186 
187 void CStlOneArgTemplate::SetMemFunctions(TTypeCreate create,
188  TIsDefaultFunction isDefault,
189  TSetDefaultFunction setDefault)
190 {
191  SetCreateFunction(create);
192  m_IsDefault = isDefault;
193  m_SetDefault = setDefault;
194 }
195 
197  TTypeInfo keyType,
198  TPointerOffsetType keyOffset,
199  TTypeInfo valueType,
200  TPointerOffsetType valueOffset,
201  bool randomOrder)
202  : CParent(size, CTypeRef(&CreateElementTypeInfo, this), randomOrder),
203  m_KeyType(keyType), m_KeyOffset(keyOffset),
204  m_ValueType(valueType), m_ValueOffset(valueOffset)
205 {
206 }
207 
209  const CTypeRef& keyType,
210  TPointerOffsetType keyOffset,
211  const CTypeRef& valueType,
212  TPointerOffsetType valueOffset,
213  bool randomOrder)
214  : CParent(size, CTypeRef(&CreateElementTypeInfo, this), randomOrder),
215  m_KeyType(keyType), m_KeyOffset(keyOffset),
216  m_ValueType(valueType), m_ValueOffset(valueOffset)
217 {
218 }
219 
221 {
222  m_KeyId = id;
223 }
224 
226 {
227  m_ValueId = id;
228 }
229 
231 {
232  const CStlTwoArgsTemplate* mapType =
234  CClassTypeInfo* classInfo =
236  classInfo->SetRandomOrder(false);
237  classInfo->AddMember(mapType->GetKeyId(),
238  TConstObjectPtr(mapType->m_KeyOffset),
239  mapType->m_KeyType.Get());
240  classInfo->AddMember(mapType->GetValueId(),
241  TConstObjectPtr(mapType->m_ValueOffset),
242  mapType->m_ValueType.Get());
243  classInfo->AssignItemsTags();
244  return classInfo;
245 }
246 
CSafeStatic<>::
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
#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
void * TObjectPtr
Definition: serialdef.hpp:55
const void * TConstObjectPtr
Definition: serialdef.hpp:59
TTypeInfo Get(void) const
CTypeInfo *(* TTypeInfoCreator1)(TTypeInfo)
Definition: serialdef.hpp:67
static CClassTypeInfo * CreateAbstractClassInfo(const char *name)
CTypeInfo *(* TTypeInfoCreator2)(TTypeInfo, TTypeInfo)
Definition: serialdef.hpp:68
ssize_t TPointerOffsetType
Definition: serialdef.hpp:241
#define XSERIAL_TYPEINFO_WRITELOCK
Definition: serialimpl.hpp:277
static const TObjectType * SafeCast(TTypeInfo type)
Definition: serialutil.hpp:76
#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 TTypeInfo Get_CRef(TTypeInfo arg, TTypeInfoCreator1 f)
Definition: stltypes.cpp:61
static TTypeInfo GetInfo(TTypeInfo &storage, TTypeInfo arg, TTypeInfoCreator1 f)
Definition: stltypes.cpp:118
CMemberInfo * AddMember(const char *memberId, const void *memberPtr, const CTypeRef &memberType)
Definition: classinfob.cpp:99
void SetKeyId(const CMemberId &id)
Definition: stltypes.cpp:220
static TTypeInfo GetSet_vector(TTypeInfo arg, TTypeInfoCreator1 f)
Definition: stltypes.cpp:91
static TTypeInfo Get_map(TTypeInfo arg1, TTypeInfo arg2, TTypeInfoCreator2 f)
Definition: stltypes.cpp:106
TIsDefaultFunction m_IsDefault
TSetDefaultFunction m_SetDefault
static TTypeInfo GetSet_list(TTypeInfo arg, TTypeInfoCreator1 f)
Definition: stltypes.cpp:81
static TTypeInfo Get_AutoPtr(TTypeInfo arg, TTypeInfoCreator1 f)
Definition: stltypes.cpp:71
void AssignItemsTags(void)
Definition: classinfob.cpp:121
static TTypeInfo CreateElementTypeInfo(TTypeInfo info)
Definition: stltypes.cpp:230
static TTypeInfo Get_set(TTypeInfo arg, TTypeInfoCreator1 f)
Definition: stltypes.cpp:96
static TTypeInfo Get_multiset(TTypeInfo arg, TTypeInfoCreator1 f)
Definition: stltypes.cpp:101
static TTypeInfo Get_auto_ptr(TTypeInfo arg, TTypeInfoCreator1 f)
Definition: stltypes.cpp:56
static void CannotGetElementOfSet(void)
Definition: stltypes.cpp:143
CStlOneArgTemplate(size_t size, TTypeInfo dataType, bool randomOrder, const string &name)
Definition: stltypes.cpp:153
static TTypeInfo Get_CConstRef(TTypeInfo arg, TTypeInfoCreator1 f)
Definition: stltypes.cpp:66
const CMemberId & GetValueId(void) const
TPointerOffsetType m_ValueOffset
void SetCreateFunction(TTypeCreate func)
Definition: typeinfo.cpp:355
virtual bool IsDefault(TConstObjectPtr objectPtr) const override
Check, whether the object contains default value.
Definition: stltypes.cpp:177
TPointerOffsetType m_KeyOffset
void SetDataId(const CMemberId &id)
Definition: stltypes.cpp:172
static void ThrowDuplicateElementError(void)
Definition: stltypes.cpp:148
CStlTwoArgsTemplate(size_t size, TTypeInfo keyType, TPointerOffsetType keyOffset, TTypeInfo valueType, TPointerOffsetType valueOffset, bool randomOrder)
Definition: stltypes.cpp:196
CClassTypeInfo * SetRandomOrder(bool random=true)
Definition: classinfo.cpp:91
static TTypeInfo Get_multimap(TTypeInfo arg1, TTypeInfo arg2, TTypeInfoCreator2 f)
Definition: stltypes.cpp:112
static TTypeInfo Get_vector(TTypeInfo arg, TTypeInfoCreator1 f)
Definition: stltypes.cpp:86
void SetMemFunctions(TTypeCreate create, TIsDefaultFunction isDefault, TSetDefaultFunction setDefault)
Definition: stltypes.cpp:187
const CMemberId & GetKeyId(void) const
virtual void SetDefault(TObjectPtr objectPtr) const override
Set object to default value.
Definition: stltypes.cpp:182
void SetValueId(const CMemberId &id)
Definition: stltypes.cpp:225
static TTypeInfo Get_list(TTypeInfo arg, TTypeInfoCreator1 f)
Definition: stltypes.cpp:76
const struct ncbi::grid::netcache::search::fields::SIZE size
Static variables safety - create on demand, destroy on application termination.
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
static CSafeStatic< CTypeInfoMap > s_TypeMap_auto_ptr
Definition: stltypes.cpp:45
static CSafeStatic< CTypeInfoMap > s_TypeMap_CConstRef
Definition: stltypes.cpp:47
static CSafeStatic< CTypeInfoMap > s_TypeMap_set
Definition: stltypes.cpp:53
static CSafeStatic< CTypeInfoMap > s_TypeMap_CRef
Definition: stltypes.cpp:46
static CSafeStatic< CTypeInfoMap > s_TypeMap_AutoPtr
Definition: stltypes.cpp:48
static CSafeStatic< CTypeInfoMap > s_TypeMap_vector
Definition: stltypes.cpp:51
static CSafeStatic< CTypeInfoMap > s_TypeMapSet_list
Definition: stltypes.cpp:50
static CSafeStatic< CTypeInfoMap > s_TypeMap_multiset
Definition: stltypes.cpp:54
static CSafeStatic< CTypeInfoMap > s_TypeMap_list
Definition: stltypes.cpp:49
static CSafeStatic< CTypeInfoMap > s_TypeMapSet_vector
Definition: stltypes.cpp:52
Definition: type.c:6
Modified on Sun Mar 03 03:17:17 2024 by modify_doxy.py rev. 669887