Example #1
0
void COffsetReadHook::ReadObject(CObjectIStream &in, 
                                 const CObjectInfo &object)
{
    CCallStackGuard guard(m_Sniffer->m_CallStack, object);
    
    if (m_EventMode == CObjectsSniffer::eCallAlways) {

        // Clear the discard flag before calling sniffer's event reactors
        m_Sniffer->SetDiscardCurrObject(false);

        m_Sniffer->OnObjectFoundPre(object, in.GetStreamPos());
     
        DefaultRead(in, object);

        m_Sniffer->OnObjectFoundPost(object);

        // Relay discard flag to the stream
        bool discard = m_Sniffer->GetDiscardCurrObject();
        in.SetDiscardCurrObject(discard);
    }
    else {
        if (m_EventMode == CObjectsSniffer::eSkipObject) {
            DefaultSkip(in, object);
        }
        else {
            DefaultRead(in, object);
        }
    }
}
Example #2
0
    virtual void SkipClassMember(CObjectIStream& in,
                                 const CObjectTypeInfoMI& passed_info)
    {
        cout << in.GetStackPath() << endl;
#if 1
        DefaultSkip(in, passed_info);
#else
// get information about the member
        // typeinfo of the parent class (Bioseq)
        CObjectTypeInfo oti = passed_info.GetClassType();
        // typeinfo of the member  (SET OF Seq-annot)
        CObjectTypeInfo omti = passed_info.GetMemberType();
        // index of the member in parent class  (4)
        TMemberIndex mi = passed_info.GetMemberIndex();
        // information about the member, including its name (annot)
        const CMemberInfo* minfo = passed_info.GetMemberInfo();
#if 1
// or read the whole SET OF Seq-annot at once
        CObjectInfo oi(passed_info);
        DefaultRead(in, oi);
        cout << MSerial_AsnText << oi << endl;
#endif

#if 0
// or read CSeq_annot objects one by one and write them into stdout
        unique_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, "stdout", eSerial_StdWhenStd));
        COStreamContainer o(*out, passed_info);
        for ( CIStreamContainerIterator i(in, passed_info); i; ++i ) {
            CSeq_annot annot;
            i >> annot;
// NOTE: this does not produce well formed text ASN, because of missing typeinfo name
// this would work though if we copied data into existing ASN stream
// where typeinfo name ("file header") is not required
            o << annot;
// if we needed well formed text ASN, we could write it like this:
//            cout << MSerial_AsnText << annot;
        }
#endif
#if 0
// or read the whole SET OF Seq-annot at once
        CBioseq::TAnnot annot;
        CObjectInfo oi(&annot, passed_info.GetMemberType().GetTypeInfo());
        in.ReadObject(oi);
        // write them one by one
        for( const auto& e: annot) {
            cout << MSerial_AsnText << *e << endl;
        }
        // or write them all at once
        unique_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, "stdout", eSerial_StdWhenStd));
        out->WriteObject(oi);
#endif
#endif
    }
Example #3
0
    // Implement the hook method.
    //
    // Once the read hook has been set, ReadClassMember() will be called
    // whenever the specified class member is encountered while
    // reading a hooked input stream.  Without the hook, the encountered
    // class member would have been automatically read.  With the hook, it is
    // now the responsibility of the ReadClassMember() method to remove the
    // class member from the input stream and process it as desired.  It can
    // either read it or skip it to remove it from the stream.  This is
    // easily done by calling DefaultRead() or DefaultSkip() from within
    // ReadClassMember().  Subsequent processing is up to the application.
    virtual void ReadClassMember(CObjectIStream& in,
                                 const CObjectInfoMI& passed_info)
    {
        // Perform any pre-read processing here.
        //NcbiCout << "In ReadClassMember() hook, before reading." << NcbiEndl;

        // You must call DefaultRead() (or perform an equivalent operation)
        // if you want the object to be read into memory.  You could also
        // call DefaultSkip() if you wanted to skip the hooked object while
        // reading everything else.
        DefaultRead(in, passed_info);

#if 0
// call DefaultRead to read member data, or DefaultSkip to skip it
        DefaultSkip(in, passed_info);

// get information about the member
        // typeinfo of the parent class
        CObjectTypeInfo oti = passed_info.GetClassType();
        // typeinfo and data of the parent class
        const CObjectInfo& oi = passed_info.GetClassObject();
        // typeinfo of the member
        CObjectTypeInfo omti = passed_info.GetMemberType();
        // typeinfo and data of the member
        CObjectInfo om = passed_info.GetMember();
        // index of the member in parent class
        TMemberIndex mi = passed_info.GetMemberIndex();
        // information about the member, including its name
        const CMemberInfo* minfo = passed_info.GetMemberInfo();
#endif

        // Perform any post-read processing here.  Once the object has been
        // read, its data can be used for processing.
        CNcbiOstrstream oss;
        oss << MSerial_AsnText << passed_info.GetClassObject();
        string s = CNcbiOstrstreamToString(oss);
        NcbiCout << s << NcbiEndl;
    }
    virtual void SkipChoiceVariant(CObjectIStream& in,
                                   const CObjectTypeInfoCV& passed_info)
    {
        cout << in.GetStackPath() << endl;
#if 1
        DefaultSkip(in, passed_info);

#else
// get information about the variant
        // typeinfo of the parent class (Seq-annot.data)
        CObjectTypeInfo oti = passed_info.GetChoiceType();
        // typeinfo of the variant  (SET OF Seq-feat)
        CObjectTypeInfo omti = passed_info.GetVariantType();
        // index of the variant in parent class  (1)
        TMemberIndex mi = passed_info.GetVariantIndex();
        // information about the variant, including its name (ftable)
        const CVariantInfo* minfo = passed_info.GetVariantInfo();

#if 1
// or read the whole SET OF Seq-feat at once
        CObjectInfo oi(passed_info);
        DefaultRead(in, oi);
        cout << MSerial_AsnText << oi << endl;
#endif
#if 0
// or read CSeq_feat objects one by one
        for ( CIStreamContainerIterator i(in, passed_info.GetVariantType()); i; ++i ) {
            CSeq_feat feat;
            i >> feat;
            cout << MSerial_AsnText << feat << endl;
        }
#endif
#if 0
// or read CSeq_feat objects one by one and write them into stdout
        unique_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, "stdout", eSerial_StdWhenStd));
        COStreamContainer o(*out, passed_info.GetVariantType());
        for ( CIStreamContainerIterator i(in, passed_info.GetVariantType()); i; ++i ) {
            CSeq_feat feat;
            i >> feat;
// NOTE: this does not produce well formed text ASN, because of missing typeinfo name
// this would work though if we copied data into existing ASN stream
// where typeinfo name ("file header") is not required
//            o << feat;
// if we needed well formed text ASN, we could write it like this:
            cout << MSerial_AsnText << feat;
        }
#endif
#if 0
// or read the whole SET OF Seq-feat at once
        CSeq_annot::TData::TFtable ft;
        CObjectInfo oi(&ft, passed_info.GetVariantType().GetTypeInfo());
        // or, like this:
        //  CObjectInfo oi(passed_info.GetVariantType());
        in.ReadObject(oi);
        // write them one by one
        for( const auto& e: ft) {
            cout << MSerial_AsnText << *e << endl;
        }
        // or write them all at once
        unique_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, "stdout", eSerial_StdWhenStd));
        out->WriteObject(oi);
#endif
#endif
    }
Example #5
0
void CPreReadChoiceVariantHook::ReadChoiceVariant(CObjectIStream& in,
                                                  const CObjectInfoCV& variant)
{
    PreReadChoiceVariant(in, variant);
    DefaultRead(in, variant);
}
Example #6
0
void CPreReadClassMemberHook::ReadClassMember(CObjectIStream& in,
                                              const CObjectInfoMI& member)
{
    PreReadClassMember(in, member);
    DefaultRead(in, member);
}