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

Go to the SVN repository for this file.

1 #include <ncbi_pch.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 class CDemoHook : public CCopyChoiceVariantHook
15 {
16 public:
17  virtual void CopyChoiceVariant(CObjectStreamCopier& copier,
18  const CObjectTypeInfoCV& 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 variant in input stream:
27  copier.In().SkipObject(passed_info.GetVariantType());
28 #endif
29 #if 0
30 // or read CSeq_feat objects one by one
31  for ( CIStreamContainerIterator i(copier.In(), passed_info.GetVariantType()); i; ++i ) {
32  CSeq_feat feat;
33  i >> feat;
34  cout << MSerial_AsnText << feat << endl;
35  }
36 #endif
37 #if 0
38 // or read CSeq_feat objects one by one
39  for ( CIStreamContainerIterator i(copier.In(), passed_info.GetVariantType()); i; ++i ) {
40  CObjectInfo oi(CSeq_feat::GetTypeInfo());
41  i.ReadElement(oi);
42  cout << MSerial_AsnText << oi << endl;
43  }
44 #endif
45 #if 0
46 // or read CSeq_feat objects one by one and write them into output stream
47  COStreamContainer o(copier.Out(), passed_info.GetVariantType());
48  for ( CIStreamContainerIterator i(copier.In(), passed_info.GetVariantType()); i; ++i ) {
49  CSeq_feat feat;
50  i >> feat;
51  o << feat;
52  cout << MSerial_AsnText << feat << endl;
53  }
54 #endif
55 #if 0
56 // or read the whole SET OF Seq-feat at once
58  CObjectInfo oi(&ft, passed_info.GetVariantType().GetTypeInfo());
59  // or, like this:
60  // CObjectInfo oi(passed_info.GetVariantType());
61  copier.In().ReadObject(oi);
62  // write them one by one
63  for( const auto& e: ft) {
64  cout << MSerial_AsnText << *e << endl;
65  }
66  copier.Out().WriteObject(oi);
67 #endif
68 #if 0
69 // or read the whole SET OF Seq-feat at once
70  CObjectInfo oi(passed_info.GetVariantType());
71  copier.In().ReadObject(oi);
72  copier.Out().WriteObject(oi);
73 #endif
74 
75 // get information about the variant
76  // typeinfo of the parent class (Seq-annot)
77  CObjectTypeInfo oti = passed_info.GetChoiceType();
78  // typeinfo of the variant (SET OF Seq-feat)
79  CObjectTypeInfo omti = passed_info.GetVariantType();
80  // index of the variant in parent class (1)
81  TMemberIndex mi = passed_info.GetVariantIndex();
82  // information about the variant, including its name (ftable)
83  const CVariantInfo* minfo = passed_info.GetVariantInfo();
84 #endif
85  }
86 };
87 
88 int main(int argc, char** argv)
89 {
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  .GetPointedType()
96  .FindVariant("ftable")
97  .SetLocalCopyHook(copier, new CDemoHook);
98 
99  copier.Copy(CType<CSeq_entry>());
100 
101  return 0;
102 }
static CObjectOStream * Open(ESerialDataFormat format, CNcbiOstream &outStream, bool deleteOutStream)
Create serial object writer and attach it to an output stream.
Definition: objostr.cpp:126
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:682
USING_NCBI_SCOPE
void SkipObject(const CObjectTypeInfo &objectType)
Skip child object.
Definition: objistr.cpp:1080
std::ofstream out("events_result.xml")
main entry point for tests
virtual void CopyChoiceVariant(CObjectStreamCopier &copier, const CObjectTypeInfoCV &passed_info)
ASN.1 text.
Definition: serialdef.hpp:73
CObjectIStream & In(void) const
USING_SCOPE(ncbi::objects)
CObjectTypeInfo –.
Definition: objectinfo.hpp:93
CObjectInfo –.
Definition: objectinfo.hpp:596
const CVariantInfo * GetVariantInfo(void) const
CObjectStreamCopier –.
Definition: objcopy.hpp:70
int i
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
CObjectOStream & Out(void) const
CObjectTypeInfo GetChoiceType(void) const
Get containing choice.
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:229
CMemberIterator FindMember(const string &memberName) const
Find class member by its name.
Writing containers (SET OF, SEQUENCE OF).
Definition: objectio.hpp:236
const string & GetStackPath(void) const
Definition: objstack.cpp:262
void ReadObject(const CObjectInfo &object)
Read child object.
Definition: objistr.cpp:1075
void Copy(const CObjectTypeInfo &type)
Copy data.
Definition: objcopy.cpp:74
Copy hook for a choice variant (CHOICE)
Definition: objhook.hpp:279
list< CRef< CSeq_feat > > TFtable
Definition: Seq_annot_.hpp:193
void DefaultCopy(CObjectStreamCopier &copier, const CObjectTypeInfo &type)
Definition: objhook.cpp:243
void WriteObject(const CConstObjectInfo &object)
Definition: objostr.cpp:555
Reading (iterating through) elements of containers (SET OF, SEQUENCE OF).
Definition: objectio.hpp:163
CObjectTypeInfoCV –.
Definition: objectiter.hpp:476
int main(int argc, char **argv)
CObjectTypeInfo GetVariantType(void) const
Get variant data type.
namespace ncbi::objects::
Definition: Seq_feat.hpp:56
TMemberIndex GetVariantIndex(void) const
Get index of the variant in the choice.
std::istream & in(std::istream &in_, double &x_)
TTypeInfo GetTypeInfo(void) const
Modified on Thu Feb 22 13:22:51 2018 by modify_doxy.py rev. 546573