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

Go to the SVN repository for this file.

1 #include <ncbi_pch.hpp>
2 #include <objects/seq/Bioseq.hpp>
5 #include <serial/objcopy.hpp>
6 #include <serial/objectio.hpp>
7 #include <serial/objistr.hpp>
8 #include <serial/objostr.hpp>
9 #include <serial/serial.hpp>
10 
13 
14 
16 {
17 public:
18  virtual void CopyClassMember(CObjectStreamCopier& copier,
19  const CObjectTypeInfoMI& passed_info)
20  {
21 #if 1
22  DefaultCopy(copier, passed_info);
23 
24 #else
25 #if 1
26 // or skip member in input stream:
27  copier.In().SkipObject(passed_info.GetMemberType());
28 #endif
29 #if 0
30 // or read CSeq_annot objects one by one
31  for ( CIStreamContainerIterator i(copier.In(), passed_info); i; ++i ) {
32  CSeq_annot annot;
33  i >> annot;
34  cout << MSerial_AsnText << annot << endl;
35  }
36 #endif
37 #if 0
38 // or read CSeq_annot objects one by one
39  for ( CIStreamContainerIterator i(copier.In(), passed_info); i; ++i ) {
40  CObjectInfo oi(CSeq_annot::GetTypeInfo());
41  i.ReadElement(oi);
42  cout << MSerial_AsnText << oi << endl;
43  }
44 #endif
45 #if 0
46 // or read CSeq_annot objects one by one and write them into output stream
47  COStreamContainer o(copier.Out(), passed_info);
48  for ( CIStreamContainerIterator i(copier.In(), passed_info); i; ++i ) {
49  CSeq_annot annot;
50  i >> annot;
51  o << annot;
52  cout << MSerial_AsnText << annot << endl;
53  }
54 #endif
55 #if 0
56 // or read the whole SET OF Seq-annot at once
57  CBioseq::TAnnot annot;
58  CObjectInfo oi(&annot, passed_info.GetMemberType().GetTypeInfo());
59  copier.In().ReadObject(oi);
60  // write them one by one
61  for( const auto& e: annot) {
62  cout << MSerial_AsnText << *e << endl;
63  }
64  copier.Out().WriteObject(oi);
65 #endif
66 #if 0
67 // or read the whole SET OF Seq-annot at once
68  CObjectInfo oi(passed_info.GetMemberType());
69  copier.In().ReadObject(oi);
70  copier.Out().WriteObject(oi);
71 #endif
72 
73 // get information about the member
74  // typeinfo of the parent class (Bioseq)
75  CObjectTypeInfo oti = passed_info.GetClassType();
76  // typeinfo of the member (SET OF Seq-annot)
77  CObjectTypeInfo omti = passed_info.GetMemberType();
78  // index of the member in parent class (4)
79  TMemberIndex mi = passed_info.GetMemberIndex();
80  // information about the member, including its name (annot)
81  const CMemberInfo* minfo = passed_info.GetMemberInfo();
82 #endif
83  }
84 };
85 
86 
87 int main(int argc, char** argv)
88 {
89  // read Seq-entry data
90  unique_ptr<CObjectIStream> in(CObjectIStream::Open(eSerial_AsnText, "seq-entry-sample.asn"));
91  unique_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, "seq-entry-sample_output.asn"));
92  CObjectStreamCopier copier(*in, *out);
93 
95  .FindMember("annot")
96  .SetLocalCopyHook(copier, new CDemoHook());
97 
98  copier.Copy(CType<CSeq_entry>());
99 
100  return 0;
101 }
Copy hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:266
virtual void CopyClassMember(CObjectStreamCopier &copier, const CObjectTypeInfoMI &passed_info)
Reading (iterating through) elements of containers (SET OF, SEQUENCE OF).
Definition: objectio.hpp:164
Writing containers (SET OF, SEQUENCE OF).
Definition: objectio.hpp:237
CObjectInfo –.
Definition: objectinfo.hpp:597
CObjectStreamCopier –.
Definition: objcopy.hpp:71
CObjectTypeInfoMI –.
Definition: objectiter.hpp:246
CObjectTypeInfo –.
Definition: objectinfo.hpp:94
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
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
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.
void SkipObject(const CObjectTypeInfo &objectType)
Skip child object.
Definition: objistr.cpp:1102
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
void WriteObject(const CConstObjectInfo &object)
Definition: objostr.cpp:566
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
CObjectIStream & In(void) const
void DefaultCopy(CObjectStreamCopier &copier, const CObjectTypeInfo &type)
Definition: objhook.cpp:243
CObjectOStream & Out(void) const
void SetLocalCopyHook(CObjectStreamCopier &stream, CCopyClassMemberHook *hook) const
Definition: objectiter.cpp:168
void Copy(const CObjectTypeInfo &type)
Copy data.
Definition: objcopy.cpp:74
list< CRef< CSeq_annot > > TAnnot
Definition: Bioseq_.hpp:97
int main(int argc, char **argv)
USING_SCOPE(ncbi::objects)
USING_NCBI_SCOPE
int i
std::istream & in(std::istream &in_, double &x_)
Modified on Wed Apr 17 13:09:52 2024 by modify_doxy.py rev. 669887