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

Go to the SVN repository for this file.

1 #ifndef TIMETYPEINFO__HPP
2 #define TIMETYPEINFO__HPP
3 
4 /* $Id: timetypeinfo.hpp 79560 2017-09-20 17:04: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: Aleksey Grichenko
30 *
31 * File Description:
32 * TypeInfo and serialization functions for CTime class
33 */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbitime.hpp>
37 #include <serial/objcopy.hpp>
38 #include <serial/serial.hpp>
40 
41 
42 /** @addtogroup TypeInfoCPP
43  *
44  * @{
45  */
46 
47 
49 
50 const string kSerialTimeFormat = "M/D/Y h:m:s.S Z";
51 
53 {
54 public:
55  static CTime& Get(TObjectPtr object)
56  {
57  return CTypeConverter<CTime>::Get(object);
58  }
59  static const CTime& Get(TConstObjectPtr object)
60  {
61  return CTypeConverter<CTime>::Get(object);
62  }
63 
65  {
66  info->SetIOFunctions(&Read, &Write, &Copy, &Skip);
67  }
68 
70  {
71  info->SetMemFunctions(&Create,
73  &Equals, &Assign);
74  }
75 
76  static TObjectPtr Create(TTypeInfo /*typeInfo*/,
77  CObjectMemoryPool* /*memoryPool*/)
78  {
79  return new CTime();
80  }
81  static bool IsDefault(TConstObjectPtr objectPtr)
82  {
83  return Get(objectPtr).IsEmpty();
84  }
85  static void SetDefault(TObjectPtr objectPtr)
86  {
87  Get(objectPtr).Clear();
88  }
89 
90  static bool Equals(TConstObjectPtr obj1, TConstObjectPtr obj2,
92  {
93  return Get(obj1) == Get(obj2);
94  }
95  static void Assign(TObjectPtr dst, TConstObjectPtr src,
97  {
98  Get(dst) = Get(src);
99  }
100 
101  static void Read(CObjectIStream& in,
102  TTypeInfo , TObjectPtr objectPtr)
103  {
104  string s;
105  in.ReadStd(s);
107  Get(objectPtr) = tmp;
108  }
109  static void Write(CObjectOStream& out,
110  TTypeInfo , TConstObjectPtr objectPtr)
111  {
112  out.WriteStd(Get(objectPtr).AsString(kSerialTimeFormat));
113  }
114  static void Skip(CObjectIStream& in, TTypeInfo )
115  {
116  string s;
117  in.ReadStd(s);
119  }
120  static void Copy(CObjectStreamCopier& copier, TTypeInfo )
121  {
122  string s;
123  copier.In().ReadStd(s);
125  copier.Out().WriteStd(s);
126  }
127 };
128 
129 
131 {
132 public:
133  CTimeTypeInfo(void);
134  virtual void GetValueString(TConstObjectPtr objectPtr, string& value) const override;
135  virtual void SetValueString(TObjectPtr objectPtr, const string& value) const override;
136 private:
137 };
138 
139 
140 /* @} */
141 
142 
143 inline
145 {
146  typedef CTimeFunctions TFunctions;
147  SetMemFunctions(&TFunctions::Create,
148  &TFunctions::IsDefault, &TFunctions::SetDefault,
149  &TFunctions::Equals, &TFunctions::Assign);
151  &TFunctions::Copy, &TFunctions::Skip);
152 }
153 
154 
155 inline
157  string& value) const
158 {
159  value = CTimeFunctions::Get(object);
160 }
161 
162 
163 inline
165  const string& value) const
166 {
167  CTimeFunctions::Get(object) = value;
168 }
169 
170 
171 /** @addtogroup TypeInfoCPP
172  *
173  * @{
174  */
175 
176 
179 {
180 public:
181  static TTypeInfo GetTypeInfo(void);
182  static CTypeInfo* CreateTypeInfo(void);
183 };
184 
185 
186 /* @} */
187 
188 
189 inline
191 {
192  static TTypeInfo info = CreateTypeInfo();
193  return info;
194 }
195 
196 
197 inline
199 {
200  return new CTimeTypeInfo();
201 }
202 
203 
204 inline
206 {
208 }
209 
210 
212 
213 #endif /* TIMETYPEINFO__HPP */
CObjectIStream –.
Definition: objistr.hpp:93
CObjectOStream –.
Definition: objostr.hpp:83
CObjectStreamCopier –.
Definition: objcopy.hpp:71
CTime –.
Definition: ncbitime.hpp:296
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
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
ESerialRecursionMode
How to assign and compare child sub-objects of serial objects.
Definition: serialdef.hpp:191
static TObjectType & Get(TObjectPtr object)
Definition: serialutil.hpp:56
void * TObjectPtr
Definition: serialdef.hpp:55
TTypeInfo(* TTypeInfoGetter)(void)
Definition: serialdef.hpp:63
const void * TConstObjectPtr
Definition: serialdef.hpp:59
void Read(CObjectIStream &in, TObjectPtr object, const CTypeRef &type)
Definition: serial.cpp:60
void Write(CObjectOStream &out, TConstObjectPtr object, const CTypeRef &type)
Definition: serial.cpp:55
void WriteStd(const bool &data)
void ReadStd(bool &data)
CObjectIStream & In(void) const
CObjectOStream & Out(void) const
#define EMPTY_TEMPLATE
Definition: ncbistl.hpp:159
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
CTime & Clear(void)
Make the time "empty",.
Definition: ncbitime.cpp:1998
bool IsEmpty(void) const
Is time object empty (date and time)?
Definition: ncbitime.hpp:2378
static void Assign(TObjectPtr dst, TConstObjectPtr src, ESerialRecursionMode)
static bool IsDefault(TConstObjectPtr objectPtr)
static void SetIOFunctions(CPrimitiveTypeInfo *info)
void SetMemFunctions(TTypeCreate, TIsDefaultFunction, TSetDefaultFunction, TEqualsFunction, TAssignFunction)
Definition: stdtypes.cpp:353
TTypeInfoGetter GetStdTypeInfoGetter(const CTime *)
void SetIOFunctions(TTypeReadFunction, TTypeWriteFunction, TTypeCopyFunction, TTypeSkipFunction)
Definition: stdtypes.cpp:366
static CTime & Get(TObjectPtr object)
static void Skip(CObjectIStream &in, TTypeInfo)
static void SetDefault(TObjectPtr objectPtr)
static void SetMemFunctions(CPrimitiveTypeInfo *info)
const string kSerialTimeFormat
static TObjectPtr Create(TTypeInfo, CObjectMemoryPool *)
virtual void SetValueString(TObjectPtr objectPtr, const string &value) const override
virtual void GetValueString(TConstObjectPtr objectPtr, string &value) const override
static bool Equals(TConstObjectPtr obj1, TConstObjectPtr obj2, ESerialRecursionMode)
static const CTime & Get(TConstObjectPtr object)
static void Read(CObjectIStream &in, TTypeInfo, TObjectPtr objectPtr)
static void Copy(CObjectStreamCopier &copier, TTypeInfo)
static void Write(CObjectOStream &out, TTypeInfo, TConstObjectPtr objectPtr)
static MDB_envinfo info
Definition: mdb_load.c:37
static bool Equals(const CVariation::TPlacements &p1, const CVariation::TPlacements &p2)
Defines: CTimeFormat - storage class for time format.
std::istream & in(std::istream &in_, double &x_)
static char tmp[2048]
Definition: utf8.c:42
Modified on Thu Nov 30 04:56:31 2023 by modify_doxy.py rev. 669887