NCBI C++ ToolKit
hooks_skip_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 
10 
11 
12 class CDemoHook : public CSkipChoiceVariantHook
13 {
14 public:
16  const CObjectTypeInfoCV& passed_info)
17  {
18  cout << in.GetStackPath() << endl;
19 #if 1
20  DefaultSkip(in, passed_info);
21 
22 #else
23 // get information about the variant
24  // typeinfo of the parent class (Seq-annot.data)
25  CObjectTypeInfo oti = passed_info.GetChoiceType();
26  // typeinfo of the variant (SET OF Seq-feat)
27  CObjectTypeInfo omti = passed_info.GetVariantType();
28  // index of the variant in parent class (1)
29  TMemberIndex mi = passed_info.GetVariantIndex();
30  // information about the variant, including its name (ftable)
31  const CVariantInfo* minfo = passed_info.GetVariantInfo();
32 
33 #if 1
34 // or read the whole SET OF Seq-feat at once
35  CObjectInfo oi(passed_info);
36  DefaultRead(in, oi);
37  cout << MSerial_AsnText << oi << endl;
38 #endif
39 #if 0
40 // or read CSeq_feat objects one by one
41  for ( CIStreamContainerIterator i(in, passed_info.GetVariantType()); i; ++i ) {
42  CSeq_feat feat;
43  i >> feat;
44  cout << MSerial_AsnText << feat << endl;
45  }
46 #endif
47 #if 0
48 // or read CSeq_feat objects one by one and write them into stdout
49  unique_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, "stdout", eSerial_StdWhenStd));
50  COStreamContainer o(*out, passed_info.GetVariantType());
51  for ( CIStreamContainerIterator i(in, passed_info.GetVariantType()); i; ++i ) {
52  CSeq_feat feat;
53  i >> feat;
54 // NOTE: this does not produce well formed text ASN, because of missing typeinfo name
55 // this would work though if we copied data into existing ASN stream
56 // where typeinfo name ("file header") is not required
57 // o << feat;
58 // if we needed well formed text ASN, we could write it like this:
59  cout << MSerial_AsnText << feat;
60  }
61 #endif
62 #if 0
63 // or read the whole SET OF Seq-feat at once
65  CObjectInfo oi(&ft, passed_info.GetVariantType().GetTypeInfo());
66  // or, like this:
67  // CObjectInfo oi(passed_info.GetVariantType());
68  in.ReadObject(oi);
69  // write them one by one
70  for( const auto& e: ft) {
71  cout << MSerial_AsnText << *e << endl;
72  }
73  // or write them all at once
74  unique_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, "stdout", eSerial_StdWhenStd));
75  out->WriteObject(oi);
76 #endif
77 #endif
78  }
79 };
80 
81 
82 int main(int argc, char** argv)
83 {
84  unique_ptr<CObjectIStream> in(CObjectIStream::Open(eSerial_AsnText, "seq-entry-sample.asn"));
85 
87  .GetPointedType()
88  .FindVariant("ftable")
89  .SetLocalSkipHook(*in, new CDemoHook());
90  in->Skip(CType<CSeq_entry>());
91 
92  return 0;
93 }
virtual void SkipChoiceVariant(CObjectIStream &in, const CObjectTypeInfoCV &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
CObjectIStream –.
Definition: objistr.hpp:93
CObjectInfo –.
Definition: objectinfo.hpp:597
CObjectTypeInfoCV –.
Definition: objectiter.hpp:477
CObjectTypeInfo –.
Definition: objectinfo.hpp:94
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
Skip hook for a choice variant (CHOICE)
Definition: objhook.hpp:239
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_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
CObjectTypeInfo GetVariantType(void) const
Get variant data type.
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
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
CObjectTypeInfo GetChoiceType(void) const
Get containing choice.
void DefaultSkip(CObjectIStream &in, const CObjectTypeInfo &object)
Default skip.
Definition: objhook.cpp:177
TMemberIndex GetVariantIndex(void) const
Get index of the variant in the choice.
const CVariantInfo * GetVariantInfo(void) const
list< CRef< CSeq_feat > > TFtable
Definition: Seq_annot_.hpp:193
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 Thu Apr 11 15:05:18 2024 by modify_doxy.py rev. 669887