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

Go to the SVN repository for this file.

1 #include <ncbi_pch.hpp>
3 #include <serial/objistr.hpp>
4 #include <serial/objcopy.hpp>
5 #include <serial/serial.hpp>
6 
9 
10 
11 class CDemoHook : public CReadClassMemberHook
12 {
13 public:
14  virtual void ReadClassMember(CObjectIStream& strm, const CObjectInfoMI& passed_info)
15  {
16 #if 1
17  DefaultRead(strm, passed_info);
18 
19 #else
20 #if 1
21 // call DefaultRead to read member data, or DefaultSkip to skip it
22  DefaultSkip(strm, passed_info);
23 #endif
24 #if 0
25 // read the object into local buffer
26 // this data will be discarded when this function terminates
27 // so the class member of the object being read will be invalid
28  CObjectInfo obj(passed_info.GetMemberType());
29  strm.ReadObject(obj);
30  unique_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, "stdout", eSerial_StdWhenStd));
31  out->WriteObject(obj);
32 #endif
33 #if 0
34 // or copy it into stdout
35  unique_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, "stdout", eSerial_StdWhenStd));
36  CObjectStreamCopier copier(strm, *out);
37  copier.CopyObject(passed_info.GetMemberType().GetTypeInfo());
38 #endif
39 #if 0
40 // or read it into delay buffer
41  strm.StartDelayBuffer();
42  DefaultSkip(strm, passed_info);
43  CRef<CByteSource> data = strm.EndDelayBuffer();
44 #endif
45 
46 // get information about the member
47  // typeinfo of the parent class (Date-std)
48  CObjectTypeInfo oti = passed_info.GetClassType();
49  // typeinfo and data of the parent class
50  const CObjectInfo& oi = passed_info.GetClassObject();
51  // typeinfo of the member (Int4)
52  CObjectTypeInfo omti = passed_info.GetMemberType();
53  // typeinfo and data of the member
54  CObjectInfo om = passed_info.GetMember();
55  // index of the member in parent class
56  TMemberIndex mi = passed_info.GetMemberIndex();
57  // information about the member, including its name (year)
58  const CMemberInfo* minfo = passed_info.GetMemberInfo();
59 #endif
60  }
61 };
62 
63 
64 int main(int argc, char** argv)
65 {
66  const string asn = "Date-std ::= { year 1998, month 1, day 2, season \"winter\" }";
67  CNcbiIstrstream iss(asn);
68  unique_ptr<CObjectIStream> in(CObjectIStream::Open(eSerial_AsnText, iss));
69 
72  CDate_std my_date;
73  *in >> my_date;
74 
75  return 0;
76 }
virtual void ReadClassMember(CObjectIStream &strm, const CObjectInfoMI &passed_info)
This method will be called at approriate time when the object of requested type is to be read.
CObjectIStream –.
Definition: objistr.hpp:93
CObjectInfoMI –.
Definition: objectiter.hpp:432
CObjectInfo –.
Definition: objectinfo.hpp:597
CObjectStreamCopier –.
Definition: objcopy.hpp:71
CObjectTypeInfo –.
Definition: objectinfo.hpp:94
Read hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:78
std::ofstream out("events_result.xml")
main entry point for tests
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:230
@ eSerial_StdWhenStd
use std when filename is "stdin"/"stdout"
Definition: serialdef.hpp:130
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
void DefaultRead(CObjectIStream &in, const CObjectInfo &object)
Default read.
Definition: objhook.cpp:171
TMemberIndex GetMemberIndex(void) const
Get index of the member in the class.
const CMemberInfo * GetMemberInfo(void) const
void ReadObject(const CObjectInfo &object)
Read child object.
Definition: objistr.cpp:1097
CObjectTypeInfo GetMemberType(void) const
Get data type information.
CMemberIterator FindMember(const string &memberName) const
Find class member by its name.
static CObjectOStream * Open(ESerialDataFormat format, CNcbiOstream &outStream, bool deleteOutStream)
Create serial object writer and attach it to an output stream.
Definition: objostr.cpp:126
CObjectInfo GetMember(void) const
Get class member data.
const CObjectInfo & GetClassObject(void) const
Get containing class data.
CObjectTypeInfo GetClassType(void) const
Get containing class type.
TTypeInfo GetTypeInfo(void) const
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
void DefaultSkip(CObjectIStream &in, const CObjectTypeInfo &object)
Default skip.
Definition: objhook.cpp:177
void SetLocalReadHook(CObjectIStream &stream, CReadClassMemberHook *hook) const
Definition: objectiter.cpp:96
virtual void StartDelayBuffer(void)
Definition: objistr.cpp:1014
virtual CRef< CByteSource > EndDelayBuffer(void)
Definition: objistr.cpp:1019
void CopyObject(TTypeInfo type)
Copy object, omitting file header both in input and output streams.
int main(int argc, char **argv)
USING_SCOPE(ncbi::objects)
USING_NCBI_SCOPE
std::istream & in(std::istream &in_, double &x_)
CRef< objects::CObjectManager > om
Modified on Thu Nov 30 04:55:48 2023 by modify_doxy.py rev. 669887