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

Go to the SVN repository for this file.

1 #ifndef SERIAL__HPP
2 #define SERIAL__HPP
3 
4 /* $Id: serial.hpp 95976 2022-01-25 18:11:46Z vakatov $
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 * Serialization classes.
33 */
34 
35 #include <serial/impl/typeref.hpp>
36 
37 
38 /** @addtogroup GenClassSupport
39  *
40  * @{
41  */
42 
43 
45 
46 class CObjectOStream;
47 class CObjectIStream;
48 
51 
52 // define type info getter for classes
53 template<class Class>
54 inline TTypeInfoGetter GetTypeInfoGetter(const Class* object);
55 
56 
57 // define type info getter for pointers
58 template<typename T>
59 inline
60 CTypeRef GetPtrTypeRef(const T* const* /*object*/)
61 {
62  const T* p = 0;
64 }
65 
66 // define type info getter for user classes
67 template<class Class>
68 inline
70 {
71  return &Class::GetTypeInfo;
72 }
73 
74 template<typename T>
75 inline
77 {
78  return GetTypeInfoGetter(object);
79 }
80 
82 void Write(CObjectOStream& out, TConstObjectPtr object, const CTypeRef& type);
83 
85 void Read(CObjectIStream& in, TObjectPtr object, const CTypeRef& type);
86 
89 
92 
93 // reader/writer
94 template<typename T>
95 inline
97 {
98  Write(out, &object,object.GetThisTypeInfo());
99  return out;
100 }
101 
102 template<typename T>
103 inline
105 {
106  Read(in,&object,object.GetThisTypeInfo());
107  return in;
108 }
109 
110 template<typename T>
111 inline
113 {
114  return Write(out, object);
115 }
116 
117 template<typename T>
118 inline
120 {
121  return Read(in, object);
122 }
123 
124 
125 /* @} */
126 
127 
129 
130 #endif /* SERIAL__HPP */
CObjectIStream –.
Definition: objistr.hpp:93
CObjectOStream –.
Definition: objostr.hpp:83
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
#define T(s)
Definition: common.h:230
std::ofstream out("events_result.xml")
main entry point for tests
void * TObjectPtr
Definition: serialdef.hpp:55
TTypeInfo CPointerTypeInfoGetTypeInfo(TTypeInfo type)
Definition: serial.cpp:50
TTypeInfoGetter GetTypeRef(const T *object)
Definition: serial.hpp:76
TTypeInfo(* TTypeInfoGetter)(void)
Definition: serialdef.hpp:63
CObjectIStream & operator>>(CObjectIStream &in, T &object)
Definition: serial.hpp:119
const void * TConstObjectPtr
Definition: serialdef.hpp:59
TTypeInfoGetter GetTypeInfoGetter(const Class *object)
Definition: serial.hpp:69
void Read(CObjectIStream &in, TObjectPtr object, const CTypeRef &type)
Definition: serial.cpp:60
CObjectOStream & operator<<(CObjectOStream &out, const T &object)
Definition: serial.hpp:112
void Write(CObjectOStream &out, TConstObjectPtr object, const CTypeRef &type)
Definition: serial.cpp:55
CTypeRef GetPtrTypeRef(const T *const *)
Definition: serial.hpp:60
#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_)
Definition: type.c:6
Modified on Fri Sep 20 14:58:10 2024 by modify_doxy.py rev. 669887