⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objistrxml.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        if (GetSkipUnknownMembers() == eSerialSkipUnknown_Yes) {            string value;            ReadAnyContentTo(m_CurrNsPrefix,value, tagName);            return BeginClassMember(classType);        } else {            UnexpectedMember(id, classType->GetMembers());        }    }    return index;}TMemberIndexCObjectIStreamXml::BeginClassMember(const CClassTypeInfo* classType,                                    TMemberIndex pos){    CLightString tagName;    TMemberIndex first = classType->GetMembers().FirstIndex();    if (m_RejectedTag.empty()) {        if (m_Attlist && InsideTag()) {            if (HasAttlist()) {                for (;;) {                    char ch = SkipWS();                    if (IsEndOfTagChar(ch)) {                        return kInvalidMember;                    }                    tagName = ReadName(ch);                    if (tagName.GetLength()) {                        if (classType->GetMembers().Find(tagName) != kInvalidMember) {                            break;                        }                        string value;                        ReadAttributeValue(value, true);                    }                }            } else {                return kInvalidMember;            }        } else {            if (!m_Attlist) {                if (pos == first) {                    if (classType->GetMemberInfo(first)->GetId().IsAttlist()) {                        m_Attlist = true;                        if (m_TagState == eTagOutside) {                            m_Input.UngetChar('>');                            m_TagState = eTagInsideOpening;                        }                        return first;                    }// if class spec defines no attributes, but there are some - skip them                    if (HasAttlist()) {                        ReadUndefinedAttributes();                    }                }            }            if (m_Attlist && !SelfClosedTag()) {                m_Attlist = false;                if ( NextTagIsClosing() )                    return kInvalidMember;                if (!NextIsTag()) {                    TMemberIndex ind = first+1;                    if (classType->GetMemberInfo(ind)->GetId().HasNotag()) {                        TopFrame().SetNotag();                        return ind;                    }                }            }            if ( SelfClosedTag()) {                TMemberIndex last = classType->GetMembers().LastIndex();                if (pos == last) {                    if (classType->GetMemberInfo(pos)->GetId().HasNotag()) {                        TopFrame().SetNotag();                        return pos;                    }                }                m_Attlist = false;                return kInvalidMember;            }            if ( NextTagIsClosing() )                return kInvalidMember;            tagName = ReadName(BeginOpeningTag());        }    } else {        tagName = RejectedName();    }    TMemberIndex ind = classType->GetMembers().Find(tagName);    if (ind == kInvalidMember) {        ind = classType->GetMembers().FindDeep(tagName);        if (ind != kInvalidMember) {            TopFrame().SetNotag();            UndoClassMember();            return ind;        }    } else {        const CMemberInfo *mem_info = classType->GetMemberInfo(ind);        if (x_IsStdXml()) {            ETypeFamily type = GetRealTypeFamily(mem_info->GetTypeInfo());            bool needUndo = false;            if (GetEnforcedStdXml()) {                if (type == eTypeFamilyContainer) {                    needUndo = (GetContainerElementTypeFamily(                        mem_info->GetTypeInfo()) == eTypeFamilyPrimitive);                }            } else {                needUndo = (type != eTypeFamilyPrimitive);            }            if (needUndo) {                TopFrame().SetNotag();                UndoClassMember();            }            return ind;        }    }    if (x_IsStdXml()) {        UndoClassMember();        if (pos==first && HasAnyContent(classType)) {            TopFrame().SetNotag();            return first;        }        if (GetSkipUnknownMembers() == eSerialSkipUnknown_Yes &&            pos <= classType->GetMembers().LastIndex()) {            string value;            ReadAnyContentTo(m_CurrNsPrefix,value, RejectedName());            return BeginClassMember(classType, pos);        }        return kInvalidMember;    }    CLightString id = SkipStackTagName(tagName, 1, '_');    TMemberIndex index = classType->GetMembers().Find(id, pos);    if ( index == kInvalidMember ) {        if (GetSkipUnknownMembers() == eSerialSkipUnknown_Yes) {            string value;            ReadAnyContentTo(m_CurrNsPrefix,value, tagName);            return BeginClassMember(classType, pos);        } else {           UnexpectedMember(id, classType->GetMembers());        }    }    return index;}void CObjectIStreamXml::EndClassMember(void){    if (TopFrame().GetNotag()) {        TopFrame().SetNotag(false);    } else {        CloseStackTag(0);    }}void CObjectIStreamXml::UndoClassMember(void){    if (InsideOpeningTag()) {        m_RejectedTag = m_LastTag;        m_TagState = eTagOutside;#if defined(NCBI_SERIAL_IO_TRACE)    cout << ", Undo= " << m_LastTag;#endif    }}void CObjectIStreamXml::BeginChoice(const CChoiceTypeInfo* choiceType){    CheckStdXml(choiceType);    OpenTagIfNamed(choiceType);}void CObjectIStreamXml::EndChoice(void){    CloseTagIfNamed(TopFrame().GetTypeInfo());    x_EndTypeNamespace();}TMemberIndex CObjectIStreamXml::BeginChoiceVariant(const CChoiceTypeInfo* choiceType){    CLightString tagName;    TMemberIndex first = choiceType->GetVariants().FirstIndex();    if (m_RejectedTag.empty()) {        if (!m_Attlist) {            if (choiceType->GetVariantInfo(first)->GetId().IsAttlist()) {                m_Attlist = true;                if (m_TagState == eTagOutside) {                    m_Input.UngetChar('>');                    m_TagState = eTagInsideOpening;                }                return first;            }// if spec defines no attributes, but there are some - skip them            if (HasAttlist()) {                ReadUndefinedAttributes();            }        }        m_Attlist = false;        if ( NextTagIsClosing() ) {            TMemberIndex ind = choiceType->GetVariants().FindEmpty();            if (ind != kInvalidMember) {                TopFrame().SetNotag();            }            return ind;        }        tagName = ReadName(BeginOpeningTag());    } else {        tagName = RejectedName();    }    TMemberIndex ind = choiceType->GetVariants().Find(tagName);    if (ind == kInvalidMember) {        ind = choiceType->GetVariants().FindDeep(tagName);        if (ind != kInvalidMember) {            TopFrame().SetNotag();            UndoClassMember();            return ind;        }    } else {        const CVariantInfo *var_info = choiceType->GetVariantInfo(ind);        if (x_IsStdXml()) {            ETypeFamily type = GetRealTypeFamily(var_info->GetTypeInfo());            bool needUndo = false;            if (GetEnforcedStdXml()) {                if (type == eTypeFamilyContainer) {                    needUndo = (GetContainerElementTypeFamily(                        var_info->GetTypeInfo()) == eTypeFamilyPrimitive);                }            } else {                needUndo = (type != eTypeFamilyPrimitive);            }            if (needUndo) {                TopFrame().SetNotag();                UndoClassMember();            }            return ind;        }    }    if (x_IsStdXml()) {        UndoClassMember();        UnexpectedMember(tagName, choiceType->GetVariants());    }    CLightString id = SkipStackTagName(tagName, 1, '_');    ind = choiceType->GetVariants().Find(id);    if ( ind == kInvalidMember ) {        UnexpectedMember(tagName, choiceType->GetVariants());    }    return ind;}void CObjectIStreamXml::EndChoiceVariant(void){    if (TopFrame().GetNotag()) {        TopFrame().SetNotag(false);    } else {        CloseStackTag(0);    }}#ifdef VIRTUAL_MID_LEVEL_IOvoid CObjectIStreamXml::ReadChoice(const CChoiceTypeInfo* choiceType,                                   TObjectPtr choicePtr){    if ( choiceType->GetName().empty() ) {        ReadChoiceContents(choiceType, choicePtr);    }    else {        BEGIN_OBJECT_FRAME2(eFrameChoice, choiceType);        OpenTag(choiceType);        ReadChoiceContents(choiceType, choicePtr);        CloseTag(choiceType);        END_OBJECT_FRAME();    }}void CObjectIStreamXml::ReadChoiceContents(const CChoiceTypeInfo* choiceType,                                           TObjectPtr choicePtr){    CLightString tagName = ReadName(BeginOpeningTag());    CLightString id = SkipStackTagName(tagName, 0, '_');    TMemberIndex index = choiceType->GetVariants().Find(id);    if ( index == kInvalidMember )        UnexpectedMember(id, choiceType->GetVariants());    const CVariantInfo* variantInfo = choiceType->GetVariantInfo(index);    BEGIN_OBJECT_FRAME2(eFrameChoiceVariant, variantInfo->GetId());    variantInfo->ReadVariant(*this, choicePtr);        CloseStackTag(0);    END_OBJECT_FRAME();}void CObjectIStreamXml::SkipChoice(const CChoiceTypeInfo* choiceType){    if ( choiceType->GetName().empty() ) {        SkipChoiceContents(choiceType);    }    else {        BEGIN_OBJECT_FRAME2(eFrameChoice, choiceType);        OpenTag(choiceType);        SkipChoiceContents(choiceType);        CloseTag(choiceType);        END_OBJECT_FRAME();    }}void CObjectIStreamXml::SkipChoiceContents(const CChoiceTypeInfo* choiceType){    CLightString tagName = ReadName(BeginOpeningTag());    CLightString id = SkipStackTagName(tagName, 0, '_');    TMemberIndex index = choiceType->GetVariants().Find(id);    if ( index == kInvalidMember )        UnexpectedMember(id, choiceType->GetVariants());    const CVariantInfo* variantInfo = choiceType->GetVariantInfo(index);    BEGIN_OBJECT_FRAME2(eFrameChoiceVariant, variantInfo->GetId());    variantInfo->SkipVariant(*this);        CloseStackTag(0);    END_OBJECT_FRAME();}#endifvoid CObjectIStreamXml::BeginBytes(ByteBlock& ){    BeginData();}int CObjectIStreamXml::GetHexChar(void){    char c = m_Input.GetChar();    if ( c >= '0' && c <= '9' ) {        return c - '0';    }    else if ( c >= 'A' && c <= 'Z' ) {        return c - 'A' + 10;    }    else if ( c >= 'a' && c <= 'z' ) {        return c - 'a' + 10;    }    else {        m_Input.UngetChar(c);        if ( c != '<' )            ThrowError(fFormatError, "invalid char in octet string");    }    return -1;}size_t CObjectIStreamXml::ReadBytes(ByteBlock& block,                                    char* dst, size_t length){    size_t count = 0;    while ( length-- > 0 ) {        int c1 = GetHexChar();        if ( c1 < 0 ) {            block.EndOfBlock();            return count;        }        int c2 = GetHexChar();        if ( c2 < 0 ) {            *dst++ = c1 << 4;            count++;            block.EndOfBlock();            return count;        }        else {            *dst++ = (c1 << 4) | c2;            count++;        }    }    return count;}void CObjectIStreamXml::BeginChars(CharBlock& ){    BeginData();}size_t CObjectIStreamXml::ReadChars(CharBlock& block,                                    char* dst, size_t length){    size_t count = 0;    while ( length-- > 0 ) {        char c = m_Input.GetChar();        if (c == '<') {            block.EndOfBlock();            break;        }        *dst++ = c;        count++;    }    return count;}void CObjectIStreamXml::SkipBool(void){    ReadBool();}void CObjectIStreamXml::SkipChar(void){    ReadChar();}void CObjectIStreamXml::SkipSNumber(void){    BeginData();    size_t i;    char c = SkipWSAndComments();    switch ( c ) {    case '+':    case '-':        c = m_Input.PeekChar(1);        // next char        i = 2;        break;    default:        // next char        i = 1;        break;    }    if ( c < '0' || c > '9' ) {        ThrowError(fFormatError, "invalid symbol in number");    }    while ( (c = m_Input.PeekCharNoEOF(i)) >= '0' && c <= '9' ) {        ++i;    }    m_Input.SkipChars(i);}void CObjectIStreamXml::SkipUNumber(void){    BeginData();    size_t i;    char c = SkipWSAndComments();    switch ( c ) {    case '+':        c = m_Input.PeekChar(1);        // next char        i = 2;        break;    default:        // next char        i = 1;        break;    }    if ( c < '0' || c > '9' ) {        ThrowError(fFormatError, "invalid symbol in number");    }    while ( (c = m_Input.PeekCharNoEOF(i)) >= '0' && c <= '9' ) {     

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -