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

Go to the SVN repository for this file.

1 #include <ncbi_pch.hpp>
4 #include <serial/objcopy.hpp>
5 #include <serial/objectio.hpp>
6 #include <serial/objistr.hpp>
7 #include <serial/objostr.hpp>
8 #include <serial/serial.hpp>
9 
12 
13 
14 class CDemoHook : public CCopyObjectHook
15 {
16 public:
17  virtual void CopyObject(CObjectStreamCopier& copier,
18  const CObjectTypeInfo& passed_info)
19  {
20  cout << copier.In().GetStackPath() << endl;
21 #if 1
22  DefaultCopy(copier, passed_info);
23 
24 #else
25 #if 1
26 // or skip the object
27  copier.In().SkipObject(passed_info.GetTypeInfo());
28 #endif
29 #if 0
30 // or read object
31  CSeq_annot annot;
32  copier.In().ReadObject(&annot, CSeq_annot::GetTypeInfo());
33  cout << MSerial_AsnText << annot << endl;
34 // and maybe write it as well
35  copier.Out().WriteObject(&annot, CSeq_annot::GetTypeInfo());
36 #endif
37 #if 0
38 // or read object and write it
39  CObjectInfo oi(passed_info.GetTypeInfo());
40  copier.In().ReadObject(oi);
41  copier.Out().WriteObject(oi);
42 #endif
43 
44  // typeinfo of the object (Seq-annot)
45  TTypeInfo ti = passed_info.GetTypeInfo();
46 #endif
47  }
48 };
49 
50 
51 int main(int argc, char** argv)
52 {
53  unique_ptr<CObjectIStream> in(CObjectIStream::Open(eSerial_AsnText, "seq-entry-sample.asn"));
54  unique_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, "seq-entry-sample_output.asn"));
55  CObjectStreamCopier copier(*in, *out);
56 
58  .SetLocalCopyHook(copier, new CDemoHook());
59 
60  copier.Copy(CType<CSeq_entry>());
61 
62  return 0;
63 }
Copy hook for a standalone object.
Definition: objhook.hpp:254
virtual void CopyObject(CObjectStreamCopier &copier, const CObjectTypeInfo &passed_info)
CObjectInfo –.
Definition: objectinfo.hpp:597
CObjectStreamCopier –.
Definition: objcopy.hpp:71
CObjectTypeInfo –.
Definition: objectinfo.hpp:94
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
std::ofstream out("events_result.xml")
main entry point for tests
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
void ReadObject(const CObjectInfo &object)
Read child object.
Definition: objistr.cpp:1097
void SkipObject(const CObjectTypeInfo &objectType)
Skip child object.
Definition: objistr.cpp:1102
const string & GetStackPath(void) const
Definition: objstack.cpp:263
static CObjectOStream * Open(ESerialDataFormat format, CNcbiOstream &outStream, bool deleteOutStream)
Create serial object writer and attach it to an output stream.
Definition: objostr.cpp:126
void WriteObject(const CConstObjectInfo &object)
Definition: objostr.cpp:566
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
CObjectIStream & In(void) const
void DefaultCopy(CObjectStreamCopier &copier, const CObjectTypeInfo &type)
Definition: objhook.cpp:243
void SetLocalCopyHook(CObjectStreamCopier &stream, CCopyObjectHook *hook) const
Set local (for the specified stream) copy hook.
Definition: objectinfo.cpp:437
CObjectOStream & Out(void) const
void Copy(const CObjectTypeInfo &type)
Copy data.
Definition: objcopy.cpp:74
int main(int argc, char **argv)
USING_SCOPE(ncbi::objects)
USING_NCBI_SCOPE
std::istream & in(std::istream &in_, double &x_)
Modified on Wed Apr 17 13:09:19 2024 by modify_doxy.py rev. 669887