Exemplo n.º 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);
        }
    }
}
Exemplo n.º 2
0
bool Serial_FilterSkip(CObjectIStream& in, const CObjectTypeInfo& ctype)
{
    if (!in.EndOfData()) {
        in.Skip(ctype);
        return true;
    }
    return false;
}
Exemplo n.º 3
0
 static void Read(CObjectIStream& in, TTypeInfo ,
                  TObjectPtr objectPtr)
     {
         if ( objectPtr != 0 ) {
             in.ThrowError(in.fInvalidData,
                 "non-null value when reading NULL member");
         }
         in.ReadNull();
     }
Exemplo n.º 4
0
void CChoiceTypeInfoFunctions::SkipChoiceDefault(CObjectIStream& in,
        TTypeInfo objectType)
{
    const CChoiceTypeInfo* choiceType =
        CTypeConverter<CChoiceTypeInfo>::SafeCast(objectType);
    BEGIN_OBJECT_FRAME_OF2(in, eFrameChoice, choiceType);
    in.BeginChoice(choiceType);
    BEGIN_OBJECT_FRAME_OF(in, eFrameChoiceVariant);
    TMemberIndex index = in.BeginChoiceVariant(choiceType);
    if ( index == kInvalidMember )
        in.ThrowError(in.fFormatError,"choice variant id expected");
    const CVariantInfo* variantInfo = choiceType->GetVariantInfo(index);
    if (variantInfo->GetId().IsAttlist()) {
        const CMemberInfo* memberInfo =
            dynamic_cast<const CMemberInfo*>(
                choiceType->GetVariants().GetItemInfo(index));
        memberInfo->SkipMember(in);
        in.EndChoiceVariant();
        index = in.BeginChoiceVariant(choiceType);
        if ( index == kInvalidMember )
            in.ThrowError(in.fFormatError,"choice variant id expected");
        variantInfo = choiceType->GetVariantInfo(index);
    }

    in.SetTopMemberId(variantInfo->GetId());

    variantInfo->SkipVariant(in);

    in.EndChoiceVariant();
    END_OBJECT_FRAME_OF(in);
    in.EndChoice();
    END_OBJECT_FRAME_OF(in);
}
Exemplo n.º 5
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
    }
Exemplo n.º 6
0
void CAliasTypeInfoFunctions::SkipAliasDefault(CObjectIStream& in,
                                               TTypeInfo objectType)
{
    const CAliasTypeInfo* aliasType =
        CTypeConverter<CAliasTypeInfo>::SafeCast(objectType);
    in.SkipAlias(aliasType);
}
Exemplo n.º 7
0
TObjectPtr CType_Base::GetParentObjectPtr(CObjectIStream& in,
                                          TTypeInfo typeInfo,
                                          size_t max_depth,
                                          size_t min_depth)
{
    return in.GetParentObjectPtr(typeInfo, max_depth, min_depth);
}
Exemplo n.º 8
0
void CTypeInfo::SetLocalSkipHook(CObjectIStream& stream,
                                 CSkipObjectHook* hook)
{
    CMutexGuard guard(GetTypeInfoMutex());
    m_SkipHookData.SetLocalHook(stream.m_ObjectSkipHookKey, hook);
    stream.AddMonitorType(this);
}
Exemplo n.º 9
0
void CChoiceTypeInfoFunctions::SkipChoiceSimple(CObjectIStream& in,
        TTypeInfo objectType)
{
    const CChoiceTypeInfo* choiceType =
        CTypeConverter<CChoiceTypeInfo>::SafeCast(objectType);
    in.SkipChoiceSimple(choiceType);
}
Exemplo n.º 10
0
//  --------------------------------------------------------------------------
CObjectIStream* CAsn2FastaApp::x_OpenIStream(const CArgs& args)
//  --------------------------------------------------------------------------
{

    // determine the file serialization format.
    // default for batch files is binary, otherwise text.
    ESerialDataFormat serial = args["batch"] ? eSerial_AsnBinary :eSerial_AsnText;
    if ( args["serial"] ) {
        const string& val = args["serial"].AsString();
        if ( val == "text" ) {
            serial = eSerial_AsnText;
        } else if ( val == "binary" ) {
            serial = eSerial_AsnBinary;
        } else if ( val == "XML" ) {
            serial = eSerial_Xml;
        }
    }

    // make sure of the underlying input stream. If -i was given on the command line
    // then the input comes from a file. Otherwise, it comes from stdin:
    CNcbiIstream* pInputStream = &NcbiCin;
    bool bDeleteOnClose = false;
    if ( args["i"] ) {
        pInputStream = new CNcbiIfstream( args["i"].AsString().c_str(), ios::binary  );
        bDeleteOnClose = true;
    }

    // if -c was specified then wrap the input stream into a gzip decompressor before
    // turning it into an object stream:
    CObjectIStream* pI = 0;
    if ( args["c"] ) {
        CZipStreamDecompressor* pDecompressor = new CZipStreamDecompressor(
            512, 512, kZlibDefaultWbits, CZipCompression::fCheckFileHeader );
        CCompressionIStream* pUnzipStream = new CCompressionIStream(
            *pInputStream, pDecompressor, CCompressionIStream::fOwnProcessor );
        pI = CObjectIStream::Open( serial, *pUnzipStream, eTakeOwnership );
    }
    else {
        pI = CObjectIStream::Open( 
            serial, *pInputStream, (bDeleteOnClose ? eTakeOwnership : eNoOwnership));
    }

    if ( 0 != pI ) {
        pI->UseMemoryPool();
    }
    return pI;
}
Exemplo n.º 11
0
void CPointerTypeInfo::SkipPointer(CObjectIStream& in,
                                   TTypeInfo objectType)
{
    const CPointerTypeInfo* pointerType =
        CTypeConverter<CPointerTypeInfo>::SafeCast(objectType);

    in.SkipPointer(pointerType->GetPointedType());
}
Exemplo n.º 12
0
void CAliasTypeInfoFunctions::ReadAliasDefault(CObjectIStream& in,
                                               TTypeInfo objectType,
                                               TObjectPtr objectPtr)
{
    const CAliasTypeInfo* aliasType =
        CTypeConverter<CAliasTypeInfo>::SafeCast(objectType);
    in.ReadAlias(aliasType, objectPtr);
}
Exemplo n.º 13
0
void CChoiceTypeInfoFunctions::ReadChoiceSimple(CObjectIStream& in,
        TTypeInfo objectType,
        TObjectPtr objectPtr)
{
    const CChoiceTypeInfo* choiceType =
        CTypeConverter<CChoiceTypeInfo>::SafeCast(objectType);
    in.ReadChoiceSimple(choiceType, objectPtr);
}
Exemplo n.º 14
0
void CContainerTypeInfo::SkipContainer(CObjectIStream& in,
                                       TTypeInfo objectType)
{
    const CContainerTypeInfo* containerType =
        CTypeConverter<CContainerTypeInfo>::SafeCast(objectType);

    in.SkipContainer(containerType);
}
Exemplo n.º 15
0
void CPointerTypeInfo::ReadPointer(CObjectIStream& in,
                                   TTypeInfo objectType,
                                   TObjectPtr objectPtr)
{
    const CPointerTypeInfo* pointerType =
        CTypeConverter<CPointerTypeInfo>::SafeCast(objectType);

    TTypeInfo pointedType = pointerType->GetPointedType();
    TObjectPtr pointedPtr = pointerType->GetObjectPointer(objectPtr);
    if ( pointedPtr ) {
        //pointedType->SetDefault(pointedPtr);
        in.ReadObject(pointedPtr, pointedType);
    }
    else {
        pointerType->SetObjectPointer(objectPtr,
                                      in.ReadPointer(pointedType).first);
    }
}
Exemplo n.º 16
0
void CContainerTypeInfo::ReadContainer(CObjectIStream& in,
                                       TTypeInfo objectType,
                                       TObjectPtr objectPtr)
{
    const CContainerTypeInfo* containerType =
        CTypeConverter<CContainerTypeInfo>::SafeCast(objectType);

    in.ReadContainer(containerType, objectPtr);
}
Exemplo n.º 17
0
void CObjectsSniffer::Probe(CObjectIStream& input)
{
    _ASSERT(m_Candidates.size());
    vector<CRef<COffsetReadHook> > hooks;  // list of all hooks we set

    //
    // create hooks for all candidates
    //

    TCandidates::const_iterator it;

    for (it = m_Candidates.begin(); it < m_Candidates.end(); ++it) {
        CRef<COffsetReadHook> h(new COffsetReadHook(this, it->event_mode));
        
        it->type_info.SetLocalReadHook(input, &(*h));
        hooks.push_back(h);

    } // for

    m_TopLevelMap.clear();


    if (input.GetDataFormat() == eSerial_AsnText
        || input.GetDataFormat() == eSerial_Xml) {
        ProbeText(input);
    } else {
        ProbeASN1_Bin(input);
    }

    //
    // Reset(clean) the hooks
    //

    _ASSERT(hooks.size() == m_Candidates.size());
    for (it = m_Candidates.begin(); it < m_Candidates.end(); ++it) {
        it->type_info.ResetLocalReadHook(input);
    } // for
}
Exemplo n.º 18
0
//  --------------------------------------------------------------------------
CSeq_entry_Handle CAsn2FastaApp::ObtainSeqEntryFromBioseqSet(
    CObjectIStream& is)
//  --------------------------------------------------------------------------
{
    try {
        CRef<CSeq_entry> entry(new CSeq_entry);
        is >> entry->SetSet();
        return m_Scope->AddTopLevelSeqEntry(*entry);
    }
    catch (CException& e) {
        if (! (is.GetFailFlags() & is.eEOF)) {
            ERR_POST(Error << e);
        }
    }
    return CSeq_entry_Handle();
}
Exemplo n.º 19
0
//  ============================================================================
string CFormatGuessApp::guess_object_type(CObjectIStream & obj_istrm)
//  ============================================================================
{
    set<TTypeInfo> known_types = {
        CType<CSeq_entry>().GetTypeInfo(),
        CType<CSeq_submit>().GetTypeInfo(),
        CType<CBioseq_set>().GetTypeInfo(),
        CType<CBioseq>().GetTypeInfo()
    };

    set<TTypeInfo> types = obj_istrm.GuessDataType(known_types);
    if ( types.size() != 1 ) {
        return "unknown";
    }
    return (*types.begin())->GetName();
}
Exemplo n.º 20
0
//  --------------------------------------------------------------------------
CSeq_entry_Handle CAsn2FastaApp::ObtainSeqEntryFromBioseq(
    CObjectIStream& is)
//  --------------------------------------------------------------------------
{
    try {
        CRef<CBioseq> bs(new CBioseq);
        is >> *bs;
        CBioseq_Handle bsh = m_Scope->AddBioseq(*bs);
        return bsh.GetTopLevelEntry();
    }
    catch (CException& e) {
        if (! (is.GetFailFlags() & is.eEOF)) {
            ERR_POST(Error << e);
        }
    }
    return CSeq_entry_Handle();
}
Exemplo n.º 21
0
//  --------------------------------------------------------------------------
CSeq_entry_Handle CAsn2FastaApp::ObtainSeqEntryFromSeqEntry(
    CObjectIStream& is)
//  --------------------------------------------------------------------------
{
    try {
        CRef<CSeq_entry> se(new CSeq_entry);
        is >> *se;
        if (se->Which() == CSeq_entry::e_not_set) {
            NCBI_THROW(CException, eUnknown,
                       "provided Seq-entry is empty");
        }
        return m_Scope->AddTopLevelSeqEntry(*se);
    }
    catch (CException& e) {
        if (! (is.GetFailFlags() & is.eEOF)) {
            ERR_POST(Error << e);
        }
    }
    return CSeq_entry_Handle();
}
Exemplo n.º 22
0
void Serial_FilterSkip(CObjectIStream& in, CObjectTypeInfo& ctype)
{
    in.Skip(ctype);
}
Exemplo n.º 23
0
void Read(CObjectIStream& in, TObjectPtr object, TTypeInfo type)
{
    in.Read(object, type);
}
Exemplo n.º 24
0
void Read(CObjectIStream& in, TObjectPtr object, const CTypeRef& type)
{
    //type.Get()->SetDefault(object);
    in.Read(object, type.Get());
}
Exemplo n.º 25
0
void CObjectOStreamAsn::CopyEnum(const CEnumeratedTypeValues& values,
                                 CObjectIStream& in)
{
    TEnumValueType value = in.ReadEnum(values);
    WriteEnum(values, value, values.FindName(value, values.IsInteger()));
}
Exemplo n.º 26
0
void CObjectOStream::CopyGi(CObjectIStream& in)
{
    TGi obj;
    in.ReadGi(obj);
    WriteGi(obj);
}
Exemplo n.º 27
0
void CObjectsSniffer::ProbeASN1_Bin(CObjectIStream& input)
{
    TCandidates::const_iterator last_cand = m_Candidates.end();
    for ( ;; ) {
        m_StreamPos = input.GetStreamPos();

        if ( last_cand != m_Candidates.end() ) {
            // Check the previously found candidate first
            // (performance optimization)
            try {
                TCandidates::const_iterator it = last_cand;
                CObjectInfo object_info(it->type_info.GetTypeInfo());
                input.Read(object_info);
                m_TopLevelMap.push_back(
                    SObjectDescription(it->type_info, m_StreamPos));
                _TRACE("Same type ASN.1 binary top level object found:" 
                       << it->type_info.GetTypeInfo()->GetName());
                continue;
            }
            catch ( CEofException& ) {
                // no more objects
                return;
            }
            catch ( exception& ) {
                Reset();
                input.SetStreamPos(m_StreamPos);
            }
        }

        bool found = false;
        // Scan through all candidates
        ITERATE ( TCandidates, it, m_Candidates ) {
            if ( it == last_cand ) {
                // already tried
                continue;
            }
            try {
                CObjectInfo object_info(it->type_info.GetTypeInfo());
                input.Read(object_info);
                found = true;
                last_cand = it;
                m_TopLevelMap.push_back(
                    SObjectDescription(it->type_info, m_StreamPos));
                LOG_POST_X(2, Info 
                           << "ASN.1 binary top level object found:" 
                           << it->type_info.GetTypeInfo()->GetName());
                break;
            }
            catch ( CEofException& ) {
                // no more objects
                return;
            }
            catch ( exception& ) {
                Reset();
                input.SetStreamPos(m_StreamPos);
            }
        }
        if ( !found ) {
            // no matching candidate
            break;
        }
    } // while
}
Exemplo n.º 28
0
 static void Skip(CObjectIStream& in, TTypeInfo )
     {
         in.SkipNull();
     }
Exemplo n.º 29
0
    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
    }
Exemplo n.º 30
0
void CChoiceTypeInfoFunctions::ReadChoiceDefault(CObjectIStream& in,
        TTypeInfo objectType,
        TObjectPtr objectPtr)
{
    const CChoiceTypeInfo* choiceType =
        CTypeConverter<CChoiceTypeInfo>::SafeCast(objectType);
    BEGIN_OBJECT_FRAME_OF3(in, eFrameChoice, choiceType, objectPtr);
    in.BeginChoice(choiceType);
    BEGIN_OBJECT_FRAME_OF(in, eFrameChoiceVariant);
    TMemberIndex index = in.BeginChoiceVariant(choiceType);
    if ( index == kInvalidMember ) {
        if (in.CanSkipUnknownVariants()) {
            in.SkipAnyContentVariant();
        } else {
            in.ThrowError(in.fFormatError, "choice variant id expected");
        }
    } else {
        for (;;) {
            const CVariantInfo* variantInfo = choiceType->GetVariantInfo(index);
            if (variantInfo->GetId().IsAttlist()) {
                const CMemberInfo* memberInfo =
                    static_cast<const CMemberInfo*>(
                        choiceType->GetVariants().GetItemInfo(index));
                memberInfo->ReadMember(in,objectPtr);
                in.EndChoiceVariant();
                index = in.BeginChoiceVariant(choiceType);
                if ( index == kInvalidMember ) {
                    if (in.CanSkipUnknownVariants()) {
                        in.SkipAnyContentVariant();
                        break;
                    } else {
                        in.ThrowError(in.fFormatError, "choice variant id expected");
                    }
                }
                variantInfo = choiceType->GetVariantInfo(index);
            }
            in.SetTopMemberId(variantInfo->GetId());

            variantInfo->ReadVariant(in, objectPtr);
            in.EndChoiceVariant();
            break;
        }
    }
    END_OBJECT_FRAME_OF(in);
    in.EndChoice();
    END_OBJECT_FRAME_OF(in);
}