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

Go to the SVN repository for this file.

1 #ifndef OBJTOOLS_READERS_OBJHOOK_LAMBDAS_HPP
2 #define OBJTOOLS_READERS_OBJHOOK_LAMBDAS_HPP
3 /* $Id: objhook_lambdas.hpp 93784 2021-05-20 20:05:48Z gotvyans $
4  * ===========================================================================
5  *
6  * PUBLIC DOMAIN NOTICE
7  * National Center for Biotechnology Information
8  *
9  * This software/database is a "United States Government Work" under the
10  * terms of the United States Copyright Act. It was written as part of
11  * the author's official duties as a United States Government employee and
12  * thus cannot be copyrighted. This software/database is freely available
13  * to the public for use. The National Library of Medicine and the U.S.
14  * Government have not placed any restriction on its use or reproduction.
15  *
16  * Although all reasonable efforts have been taken to ensure the accuracy
17  * and reliability of the software and data, the NLM and the U.S.
18  * Government do not and cannot warrant the performance or results that
19  * may be obtained by using this software or data. The NLM and the U.S.
20  * Government disclaim all warranties, express or implied, including
21  * warranties of performance, merchantability or fitness for any particular
22  * purpose.
23  *
24  * Please cite the author in any work or product based on this material.
25  *
26  * ===========================================================================
27  *
28  * Author: Sergiy Gotvyanskyy
29  *
30  * File Description: ASN.1 read/write/copy/skip hooks via lambda's
31  */
32 
33 #include <serial/objhook.hpp>
34 
36 
37 template<typename _T>
39 {
40 public:
41  CLambdaReadHook(_T _lambda) : m_lambda{ _lambda } {};
42  void ReadObject(CObjectIStream& in, const CObjectInfo& object) override
43  {
44  m_lambda(in, object);
45  }
46 
48 };
49 
50 template<typename _T>
52 {
53 public:
54  CLambaReadMemberHook(_T _lambda) : m_lambda{ _lambda } {};
55  void ReadClassMember(CObjectIStream& str, const CObjectInfoMI& obj) override
56  {
57  m_lambda(str, obj);
58  }
59 
61 };
62 
63 template<typename _T>
65 {
66 public:
67  CLambdaSkipHook(_T _lambda) : m_lambda{ _lambda } {};
68  void SkipObject(CObjectIStream& stream, const CObjectTypeInfo& type) override
69  {
70  m_lambda(stream, type);
71  }
72 
74 };
75 
76 template<typename _T>
78 {
79 public:
80  CLambaSkipMemberHook(_T _lambda) : m_lambda{ _lambda } {};
81  void SkipClassMember(CObjectIStream& stream, const CObjectTypeInfoMI& member) override
82  {
83  m_lambda(stream, member);
84  }
85 
87 };
88 
89 template<typename _T>
91 {
92 public:
93  CLambdaCopyHook(_T _lambda) : m_lambda{ _lambda } {};
94  void CopyObject(CObjectStreamCopier& copier, const CObjectTypeInfo& type) override
95  {
96  m_lambda(copier, type);
97  }
98 
100 };
101 
102 template<typename _T>
104 {
105 public:
106  CLambaCopyMemberHook(_T _lambda) : m_lambda{ _lambda } {};
107  void CopyClassMember(CObjectStreamCopier& copier, const CObjectTypeInfoMI& member) override
108  {
109  m_lambda(copier, member);
110  }
111 
113 };
114 
115 template<typename _T>
117 {
118 public:
119  CLambdaWriteHook(_T _lambda) : m_lambda{ _lambda } {};
120  void WriteObject(CObjectOStream& out, const CConstObjectInfo& object) override
121  {
122  m_lambda(out, object);
123  }
124 
126 };
127 
128 template<typename _T>
130 {
131 public:
132  CLambaWriteMemberHook(_T _lambda) : m_lambda{ _lambda } {};
133  void WriteClassMember(CObjectOStream& out, const CConstObjectInfoMI& member) override
134  {
135  m_lambda(out, member);
136  }
137 
139 };
140 
141 template<typename _Func>
142 void SetLocalReadHook(const CObjectTypeInfo& obj_type_info, CObjectIStream& ostr, _Func _func)
143 {
144  auto hook = Ref(new CLambdaReadHook<_Func>(_func));
145  obj_type_info.SetLocalReadHook(ostr, hook);
146 }
147 
148 template<typename _Func>
149 void SetLocalReadHook(TTypeInfo type_info, CObjectIStream& ostr, _Func _func)
150 {
151  SetLocalReadHook(CObjectTypeInfo(type_info), ostr, _func);
152 }
153 
154 template<typename _Func>
155 void SetLocalReadHook(const CObjectTypeInfoMI& member_info, CObjectIStream& istr, _Func _func)
156 {
157  auto hook = Ref(new CLambaReadMemberHook<_Func>(_func));
158  member_info.SetLocalReadHook(istr, hook);
159 }
160 
161 template<typename _Func>
162 void SetLocalSkipHook(const CObjectTypeInfo& obj_type_info, CObjectIStream& istr, _Func _func)
163 {
164  auto hook = Ref(new CLambdaSkipHook<_Func>(_func));
165  obj_type_info.SetLocalSkipHook(istr, hook);
166 }
167 
168 template<typename _Func>
169 void SetLocalSkipHook(TTypeInfo type_info, CObjectIStream& istr, _Func _func)
170 {
171  SetLocalSkipHook(CObjectTypeInfo(type_info), istr, _func);
172 }
173 
174 template<typename _Func>
175 void SetLocalSkipHook(const CObjectTypeInfoMI& member_info, CObjectIStream& istr, _Func _func)
176 {
177  auto hook = Ref(new CLambaSkipMemberHook<_Func>(_func));
178  member_info.SetLocalSkipHook(istr, hook);
179 }
180 
181 template<typename _Func>
182 void SetLocalCopyHook(const CObjectTypeInfo& obj_type_info, CObjectStreamCopier& copier, _Func _func)
183 {
184  auto hook = Ref(new CLambdaCopyHook<_Func>(_func));
185  obj_type_info.SetLocalCopyHook(copier, hook);
186 }
187 
188 template<typename _Func>
189 void SetLocalCopyHook(TTypeInfo type_info, CObjectStreamCopier& copier, _Func _func)
190 {
191  SetLocalCopyHook(CObjectTypeInfo(type_info), copier, _func);
192 }
193 
194 template<typename _Func>
195 void SetLocalCopyHook(const CObjectTypeInfoMI& member_info, CObjectStreamCopier& copier, _Func _func)
196 {
197  auto hook = Ref(new CLambaCopyMemberHook<_Func>(_func));
198  member_info.SetLocalCopyHook(copier, hook);
199 }
200 
201 template<typename _Func>
202 void SetLocalWriteHook(const CObjectTypeInfo& obj_type_info, CObjectOStream& ostr, _Func _func)
203 {
204  auto hook = Ref(new CLambdaWriteHook<_Func>(_func));
205  obj_type_info.SetLocalWriteHook(ostr, hook);
206 }
207 
208 template<typename _Func>
209 void SetLocalWriteHook(TTypeInfo type_info, CObjectOStream& ostr, _Func _func)
210 {
211  SetLocalWriteHook(CObjectTypeInfo(type_info), ostr, _func);
212 }
213 
214 template<typename _Func>
215 void SetLocalWriteHook(const CObjectTypeInfoMI& member_info, CObjectOStream& ostr, _Func _func)
216 {
217  auto hook = Ref(new CLambaWriteMemberHook<_Func>(_func));
218  member_info.SetLocalWriteHook(ostr, hook);
219 }
220 
222 
223 #endif
CConstObjectInfoMI –.
Definition: objectiter.hpp:397
CConstObjectInfo –.
Definition: objectinfo.hpp:421
Copy hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:266
Copy hook for a standalone object.
Definition: objhook.hpp:254
CLambaCopyMemberHook(_T _lambda)
void CopyClassMember(CObjectStreamCopier &copier, const CObjectTypeInfoMI &member) override
void ReadClassMember(CObjectIStream &str, const CObjectInfoMI &obj) override
This method will be called at approriate time when the object of requested type is to be read.
CLambaReadMemberHook(_T _lambda)
CLambaSkipMemberHook(_T _lambda)
void SkipClassMember(CObjectIStream &stream, const CObjectTypeInfoMI &member) override
void WriteClassMember(CObjectOStream &out, const CConstObjectInfoMI &member) override
CLambaWriteMemberHook(_T _lambda)
void CopyObject(CObjectStreamCopier &copier, const CObjectTypeInfo &type) override
CLambdaCopyHook(_T _lambda)
CLambdaReadHook(_T _lambda)
void ReadObject(CObjectIStream &in, const CObjectInfo &object) override
This method will be called at approriate time when the object of requested type is to be read.
CLambdaSkipHook(_T _lambda)
void SkipObject(CObjectIStream &stream, const CObjectTypeInfo &type) override
CLambdaWriteHook(_T _lambda)
void WriteObject(CObjectOStream &out, const CConstObjectInfo &object) override
This method will be called at approriate time when the object of requested type is to be written.
CObjectIStream –.
Definition: objistr.hpp:93
CObjectInfoMI –.
Definition: objectiter.hpp:432
CObjectInfo –.
Definition: objectinfo.hpp:597
CObjectOStream –.
Definition: objostr.hpp:83
CObjectStreamCopier –.
Definition: objcopy.hpp:71
CObjectTypeInfoMI –.
Definition: objectiter.hpp:246
CObjectTypeInfo –.
Definition: objectinfo.hpp:94
Read hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:78
Read hook for a standalone object.
Definition: objhook.hpp:59
Skip hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:223
Skip hook for a standalone object.
Definition: objhook.hpp:205
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
Write hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:175
Write hook for a standalone object.
Definition: objhook.hpp:161
std::ofstream out("events_result.xml")
main entry point for tests
static const char * str(char *buf, int n)
Definition: stats.c:84
void SetLocalReadHook(CObjectIStream &stream, CReadObjectHook *hook) const
Set local (for the specified stream) read hook.
Definition: objectinfo.cpp:366
void SetLocalSkipHook(CObjectIStream &stream, CSkipObjectHook *hook) const
Set local (for the specified stream) skip hook.
Definition: objectinfo.cpp:420
void SetLocalSkipHook(CObjectIStream &stream, CSkipClassMemberHook *hook) const
Definition: objectiter.cpp:150
void SetLocalCopyHook(CObjectStreamCopier &stream, CCopyObjectHook *hook) const
Set local (for the specified stream) copy hook.
Definition: objectinfo.cpp:437
void SetLocalReadHook(CObjectIStream &stream, CReadClassMemberHook *hook) const
Definition: objectiter.cpp:96
void SetLocalWriteHook(CObjectOStream &stream, CWriteObjectHook *hook) const
Set local (for the specified stream) write hook.
Definition: objectinfo.cpp:393
void SetLocalCopyHook(CObjectStreamCopier &stream, CCopyClassMemberHook *hook) const
Definition: objectiter.cpp:168
void SetLocalWriteHook(CObjectOStream &stream, CWriteClassMemberHook *hook) const
Definition: objectiter.cpp:123
CRef< C > Ref(C *object)
Helper functions to get CRef<> and CConstRef<> objects.
Definition: ncbiobj.hpp:2015
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
std::istream & in(std::istream &in_, double &x_)
void SetLocalCopyHook(const CObjectTypeInfo &obj_type_info, CObjectStreamCopier &copier, _Func _func)
void SetLocalSkipHook(const CObjectTypeInfo &obj_type_info, CObjectIStream &istr, _Func _func)
void SetLocalWriteHook(const CObjectTypeInfo &obj_type_info, CObjectOStream &ostr, _Func _func)
void SetLocalReadHook(const CObjectTypeInfo &obj_type_info, CObjectIStream &ostr, _Func _func)
Definition: type.c:6
Modified on Sun Apr 14 05:25:05 2024 by modify_doxy.py rev. 669887