NCBI C++ ToolKit
hooks_skip_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 
10 
11 
12 class CDemoHook : public CSkipClassMemberHook
13 {
14 public:
16  const CObjectTypeInfoMI& passed_info)
17  {
18  cout << in.GetStackPath() << endl;
19 #if 1
20  DefaultSkip(in, passed_info);
21 #else
22 // get information about the member
23  // typeinfo of the parent class (Bioseq)
24  CObjectTypeInfo oti = passed_info.GetClassType();
25  // typeinfo of the member (SET OF Seq-annot)
26  CObjectTypeInfo omti = passed_info.GetMemberType();
27  // index of the member in parent class (4)
28  TMemberIndex mi = passed_info.GetMemberIndex();
29  // information about the member, including its name (annot)
30  const CMemberInfo* minfo = passed_info.GetMemberInfo();
31 #if 1
32 // or read the whole SET OF Seq-annot at once
33  CObjectInfo oi(passed_info);
34  DefaultRead(in, oi);
35  cout << MSerial_AsnText << oi << endl;
36 #endif
37 
38 #if 0
39 // or read CSeq_annot objects one by one and write them into stdout
40  unique_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, "stdout", eSerial_StdWhenStd));
41  COStreamContainer o(*out, passed_info);
42  for ( CIStreamContainerIterator i(in, passed_info); i; ++i ) {
43  CSeq_annot annot;
44  i >> annot;
45 // NOTE: this does not produce well formed text ASN, because of missing typeinfo name
46 // this would work though if we copied data into existing ASN stream
47 // where typeinfo name ("file header") is not required
48  o << annot;
49 // if we needed well formed text ASN, we could write it like this:
50 // cout << MSerial_AsnText << annot;
51  }
52 #endif
53 #if 0
54 // or read the whole SET OF Seq-annot at once
55  CBioseq::TAnnot annot;
56  CObjectInfo oi(&annot, passed_info.GetMemberType().GetTypeInfo());
57  in.ReadObject(oi);
58  // write them one by one
59  for( const auto& e: annot) {
60  cout << MSerial_AsnText << *e << endl;
61  }
62  // or write them all at once
63  unique_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, "stdout", eSerial_StdWhenStd));
64  out->WriteObject(oi);
65 #endif
66 #endif
67  }
68 };
69 
70 
71 int main(int argc, char** argv)
72 {
73  unique_ptr<CObjectIStream> in(CObjectIStream::Open(eSerial_AsnText, "seq-entry-sample.asn"));
75  .FindMember("annot")
76  .SetLocalSkipHook(*in, new CDemoHook());
77 
78  in->Skip(CType<CSeq_entry>());
79 
80  return 0;
81 }
virtual void SkipClassMember(CObjectIStream &in, 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
CObjectIStream –.
Definition: objistr.hpp:93
CObjectInfo –.
Definition: objectinfo.hpp:597
CObjectTypeInfoMI –.
Definition: objectiter.hpp:246
CObjectTypeInfo –.
Definition: objectinfo.hpp:94
Skip hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:223
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
TMemberIndex GetMemberIndex(void) const
Get index of the member in the class.
void SetLocalSkipHook(CObjectIStream &stream, CSkipClassMemberHook *hook) const
Definition: objectiter.cpp:150
const CMemberInfo * GetMemberInfo(void) const
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
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
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 Mon May 20 05:05:23 2024 by modify_doxy.py rev. 669887