complextypeinfo.cpp

来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,129 行 · 第 1/3 页

CPP
1,129
字号
    const ContentSpecNode::NodeTypes curType = curNode->getType();    // When checking Unique Particle Attribution, rename leaf elements    if (checkUPA) {        if (curNode->getElement()) {            if (fUniqueURI == fContentSpecOrgURISize) {                resizeContentSpecOrgURI();            }            fContentSpecOrgURI[fUniqueURI] = curNode->getElement()->getURI();            curNode->getElement()->setURI(fUniqueURI);            fUniqueURI++;        }    }    // Get the spec type of the passed node    int minOccurs = curNode->getMinOccurs();    int maxOccurs = curNode->getMaxOccurs();    ContentSpecNode* retNode = curNode;    if ((curType & 0x0f) == ContentSpecNode::Any        || (curType & 0x0f) == ContentSpecNode::Any_Other        || (curType & 0x0f) == ContentSpecNode::Any_NS        || curType == ContentSpecNode::Leaf)    {        retNode =  expandContentModel(curNode, minOccurs, maxOccurs);    }    else if (((curType & 0x0f) == ContentSpecNode::Choice)        ||   (curType == ContentSpecNode::All)        ||   ((curType & 0x0f) == ContentSpecNode::Sequence))    {        ContentSpecNode* childNode = curNode->getFirst();        ContentSpecNode* leftNode = convertContentSpecTree(childNode, checkUPA);        ContentSpecNode* rightNode = curNode->getSecond();        if (!rightNode) {            retNode = expandContentModel(leftNode, minOccurs, maxOccurs);            curNode->setAdoptFirst(false);            delete curNode;            return retNode;        }        if (leftNode != childNode) {            curNode->setAdoptFirst(false);            curNode->setFirst(leftNode);            curNode->setAdoptFirst(true);        }        childNode = rightNode;        rightNode =  convertContentSpecTree(childNode, checkUPA);        if (rightNode != childNode) {            curNode->setAdoptSecond(false);            curNode->setSecond(rightNode);            curNode->setAdoptSecond(true);        }        retNode =  expandContentModel(curNode, minOccurs, maxOccurs);    }    return retNode;}ContentSpecNode* ComplexTypeInfo::expandContentModel(ContentSpecNode* const specNode,                                                     const int minOccurs,                                                     const int maxOccurs){    if (!specNode) {        return 0;    }    ContentSpecNode* saveNode = specNode;    ContentSpecNode* retNode = specNode;    if (minOccurs == 1 && maxOccurs == 1) {    }    else if (minOccurs == 0 && maxOccurs == 1) {        retNode = new (fMemoryManager) ContentSpecNode        (            ContentSpecNode::ZeroOrOne            , retNode            , 0            , true            , true            , fMemoryManager        );    }    else if (minOccurs == 0 && maxOccurs == -1) {        retNode = new (fMemoryManager) ContentSpecNode        (            ContentSpecNode::ZeroOrMore            , retNode            , 0            , true            , true            , fMemoryManager        );    }    else if (minOccurs == 1 && maxOccurs == -1) {        retNode = new (fMemoryManager) ContentSpecNode        (            ContentSpecNode::OneOrMore            , retNode            , 0            , true            , true            , fMemoryManager        );    }    else if (maxOccurs == -1) {        retNode = new (fMemoryManager) ContentSpecNode        (            ContentSpecNode::OneOrMore            , retNode            , 0            , true            , true            , fMemoryManager        );        for (int i=0; i < (int)(minOccurs-1); i++) {            retNode = new (fMemoryManager) ContentSpecNode            (                ContentSpecNode::Sequence                , saveNode                , retNode                , false                , true                , fMemoryManager            );        }    }    else {        if (minOccurs == 0) {            ContentSpecNode* optional = new (fMemoryManager) ContentSpecNode            (                ContentSpecNode::ZeroOrOne                , saveNode                , 0                , true                , true                , fMemoryManager            );            retNode = optional;            for (int i=0; i < (int)(maxOccurs-minOccurs-1); i++) {                retNode = new (fMemoryManager) ContentSpecNode                (                    ContentSpecNode::Sequence                    , retNode                    , optional                    , true                    , false                    , fMemoryManager                );            }        }        else {            if (minOccurs > 1) {                retNode = new (fMemoryManager) ContentSpecNode                (                    ContentSpecNode::Sequence                    , retNode                    , saveNode                    , true                    , false                    , fMemoryManager                );                for (int i=1; i < (int)(minOccurs-1); i++) {                    retNode = new (fMemoryManager) ContentSpecNode                    (                        ContentSpecNode::Sequence                        , retNode                        , saveNode                        , true                        , false                        , fMemoryManager                    );                }            }            int counter = maxOccurs-minOccurs;            if (counter > 0) {                ContentSpecNode* optional = new (fMemoryManager) ContentSpecNode                (                    ContentSpecNode::ZeroOrOne                    , saveNode                    , 0                    , false                    , true                    , fMemoryManager                );                retNode = new (fMemoryManager) ContentSpecNode                (                    ContentSpecNode::Sequence                    , retNode                    , optional                    , true                    , true                    , fMemoryManager                );                for (int j=1; j < counter; j++) {                    retNode = new (fMemoryManager) ContentSpecNode                    (                        ContentSpecNode::Sequence					    , retNode                        , optional                        , true                        , false                        , fMemoryManager                    );                }            }        }    }    return retNode;}void ComplexTypeInfo::resizeContentSpecOrgURI() {    unsigned int newSize = fContentSpecOrgURISize * 2;    unsigned int* newContentSpecOrgURI = (unsigned int*) fMemoryManager->allocate    (        newSize * sizeof(unsigned int)    ); //new unsigned int[newSize];    // Copy the existing values    unsigned int index = 0;    for (; index < fContentSpecOrgURISize; index++)        newContentSpecOrgURI[index] = fContentSpecOrgURI[index];    for (; index < newSize; index++)        newContentSpecOrgURI[index] = 0;    // Delete the old array and udpate our members    fMemoryManager->deallocate(fContentSpecOrgURI); //delete [] fContentSpecOrgURI;    fContentSpecOrgURI = newContentSpecOrgURI;    fContentSpecOrgURISize = newSize;}/*** * Support for Serialization/De-serialization ***/IMPL_XSERIALIZABLE_TOCREATE(ComplexTypeInfo)void ComplexTypeInfo::serialize(XSerializeEngine& serEng){       if (serEng.isStoring())    {            serEng<<fAnonymous;        serEng<<fAbstract;        serEng<<fAdoptContentSpec;        serEng<<fAttWithTypeId;        serEng<<fPreprocessed;        serEng<<fDerivedBy;        serEng<<fBlockSet;        serEng<<fFinalSet;        serEng<<fScopeDefined;        serEng<<fElementId;        serEng<<fContentType;        serEng.writeString(fTypeName);        serEng.writeString(fTypeLocalName);        serEng.writeString(fTypeUri);        DatatypeValidator::storeDV(serEng, fBaseDatatypeValidator);        DatatypeValidator::storeDV(serEng, fDatatypeValidator);        serEng<<fBaseComplexTypeInfo;        serEng<<fContentSpec;        serEng<<fAttWildCard;        serEng<<fAttList;        /***         *          * Serialize RefVectorOf<SchemaElementDecl>*    fElements;         * Serialize RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;         ***/        XTemplateSerializer::storeObject(fElements, serEng);        XTemplateSerializer::storeObject(fAttDefs, serEng);         /***          *   Don't serialize           *          *   fContentModel;          *   fFormattedModel;          *   fLocator;                    *           *   fContentSpecOrgURI:     start of the array          *   fContentSpecOrgURISize: size of the array          *   fUniqueURI:             the current last element in the array          ***/    }    else    {        serEng>>fAnonymous;        serEng>>fAbstract;        serEng>>fAdoptContentSpec;        serEng>>fAttWithTypeId;        serEng>>fPreprocessed;        serEng>>fDerivedBy;        serEng>>fBlockSet;        serEng>>fFinalSet;        serEng>>fScopeDefined;        serEng>>fElementId;        serEng>>fContentType;        serEng.readString(fTypeName);        serEng.readString(fTypeLocalName);        serEng.readString(fTypeUri);        fBaseDatatypeValidator = DatatypeValidator::loadDV(serEng);        fDatatypeValidator     = DatatypeValidator::loadDV(serEng);        serEng>>fBaseComplexTypeInfo;        serEng>>fContentSpec;        serEng>>fAttWildCard;        serEng>>fAttList;        /***         *          * Deserialize RefVectorOf<SchemaElementDecl>*    fElements;         * Deserialize RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;         ***/        XTemplateSerializer::loadObject(&fElements, 8, false, serEng);        XTemplateSerializer::loadObject(&fAttDefs, 29, true, serEng);         /***          *   Don't deserialize           *          *   fFormattedModel;          *   fLocator;                    *           *   fContentSpecOrgURI:     start of the array          *   fContentSpecOrgURISize: size of the array          *   fUniqueURI:             the current last element in the array          ***/         fFormattedModel = 0;         fLocator = 0;                  fContentSpecOrgURI = 0;         fContentSpecOrgURISize = 0;         fUniqueURI = 0;    }}XERCES_CPP_NAMESPACE_END/**  * End of file ComplexTypeInfo.cpp  */

⌨️ 快捷键说明

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