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

📄 inheritancetree.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    {       for (int i=0, m=extNode->extNodes->size(); i < m; i++)          if ((*extNode->extNodes)[i])            delete (*(extNode->extNodes))[i];       delete extNode;    }    extNode = NULL;*/}void InheritanceTree::insert(    const String& className,    const String& superClassName){    // ATTN: need found flag!    // -- Insert superclass:    InheritanceTreeNode* superClassNode = 0;    if (superClassName.size() &&        !_rep->table.lookup(superClassName, superClassNode))    {        superClassNode =            new InheritanceTreeNode(CIMNameUnchecked(superClassName));        _rep->table.insert(superClassName, superClassNode);    }    // -- Insert class:    InheritanceTreeNode* classNode = 0;    if (!_rep->table.lookup(className, classNode))    {        classNode = new InheritanceTreeNode(CIMNameUnchecked(className));        _rep->table.insert(className, classNode);    }    classNode->provisional = false;    // -- Link the class and superclass nodes:    if (superClassNode)        superClassNode->addSubClass(classNode);}void InheritanceTree::insertFromPath(const String& path,      InheritanceTree* parentTree,      NameSpace* ns){    for (Dir dir(path); dir.more(); dir.next())    {        String fileName = dir.getName();        // Ignore the current and parent directories.        if (fileName == "." || fileName == "..")            continue;        Uint32 dot = fileName.find('.');        // Ignore files without dots in them:        if (dot == PEG_NOT_FOUND)            continue;        String className = fileName.subString(0, dot);        String superClassName = fileName.subString(dot + 1);        if (superClassName == "#")            superClassName.clear();#ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8        if (ns)            insert(                escapeStringDecoder(className),                escapeStringDecoder(superClassName),                *parentTree, ns);        else            insert(                escapeStringDecoder(className),                escapeStringDecoder(superClassName));#else        if (ns)            insert(className, superClassName, *parentTree, ns);        else            insert(className, superClassName);#endif    }}void InheritanceTree::check() const{    for (InheritanceTreeRep::Table::Iterator i = _rep->table.start(); i; i++)    {        if (i.value()->provisional)            throw InvalidInheritanceTree(i.value()->className.getString());    }}Boolean InheritanceTree::getSubClassNames(    const CIMName& className,    Boolean deepInheritance,    Array<CIMName>& subClassNames,    NameSpace* ns) const{    // -- Case 1: className is empty: get all class names (if deepInheritance)    // -- or just root class names (if not deepInheritance).    if (className.isNull())    {        for (InheritanceTreeRep::Table::Iterator i = _rep->table.start();i;i++)        {            InheritanceTreeNode* itn=i.value();            if (itn->extension)            {                if (!ns)                    continue;                for (int j=0,m=itn->extNodes->size(); j<m; j++)                {                    InheritanceTreeExt* itx=(*(itn->extNodes))[j];                    if (itx->tag==ns)                    {                        InheritanceTreeNode* itn=itx->node;                        if (deepInheritance)                        {                            subClassNames.append(CIMNameUnchecked(i.key()));                            itn->getSubClassNames(                                subClassNames, deepInheritance, ns);                        }                        else if (!i.value()->superClass)                            subClassNames.append(CIMNameUnchecked(i.key()));                        break;                    }                }            }            else if (deepInheritance)            {                // Append all classes:                subClassNames.append(CIMNameUnchecked(i.key()));            }            else if (!i.value()->superClass)            {                // Just append root classes:                subClassNames.append(CIMNameUnchecked(i.key()));            }        }        return true;    }    // -- Case 2: className non-empty: get names of classes descendent from    // -- the given class.    for (InheritanceTreeRep::Table::Iterator i = _rep->table.start(); i; i++)    {        if (className.equal (CIMNameUnchecked(i.key())))        {            i.value()->getSubClassNames(subClassNames, deepInheritance, ns);            return true;        }    }    // Not found!    return false;}#if 0Boolean InheritanceTree::isSubClass(    const CIMName& class1,    const CIMName& class2) const{    InheritanceTreeNode* node = 0;    if (!_rep->table.lookup(class1.getString(), node))        return false;    return node->isSubClass(class2.getString());}#endifBoolean InheritanceTree::getSuperClassNames(    const CIMName& className,    Array<CIMName>& superClassNames) const{    InheritanceTreeNode* classNode;    if (_rep->table.lookup(className.getString(), classNode))    {        classNode->getSuperClassNames(superClassNames);        return true;    }    return false;}Boolean InheritanceTree::getSuperClass(    const CIMName& className,    CIMName& superClassName) const{    InheritanceTreeNode* classNode;    if (_rep->table.lookup(className.getString(), classNode))    {        if (classNode->superClass)        {            superClassName = classNode->superClass->className;        }        else        {            superClassName.clear();        }        return true;    }    return false;}Boolean InheritanceTree::hasSubClasses(    const CIMName& className,    Boolean& hasSubClasses) const{    InheritanceTreeNode* node = 0;    if (!_rep->table.lookup(className.getString(), node))        return false;    hasSubClasses = node->subClasses != 0;    return true;}Boolean InheritanceTree::containsClass(const CIMName& className) const{    return _rep->table.contains(className.getString());}void InheritanceTree::remove(    const CIMName& className,    InheritanceTree& parentTree,    NameSpace* tag){    // -- Lookup the node:    InheritanceTreeNode* node = 0;    if (!_rep->table.lookup(className.getString(), node))        throw PEGASUS_CIM_EXCEPTION(            CIM_ERR_INVALID_CLASS, className.getString());    // -- Disallow if is has any subclasses:    if (node->subClasses)        throw PEGASUS_CIM_EXCEPTION(            CIM_ERR_CLASS_HAS_CHILDREN, className.getString());    // -- Remove as child of superclass:    InheritanceTreeNode* superClass = node->superClass;    if (tag)    {        InheritanceTreeNode* itn = 0;        if (parentTree._rep->table.lookup(className.getString(), itn))        {            if (itn->extension)            {                for (int j = 0, m = itn->extNodes->size(); j < m; j++)                {                    if ((*(itn->extNodes))[j]->tag == tag)                    {                        itn->extNodes->remove(j);                        break;                    }                }                if (itn->extNodes->size() == 0)                {                    delete itn->extNodes;                    parentTree._rep->table.remove(className.getString());                }            }        }        else        {            Boolean result = superClass->removeSubClass(node);            PEGASUS_ASSERT(result);        }    }    else if (superClass)    {        Boolean result = superClass->removeSubClass(node);        PEGASUS_ASSERT(result);    }    // -- Remove from the hash table and delete:    Boolean result = _rep->table.remove(className.getString());    PEGASUS_ASSERT(result);    delete node;}void InheritanceTree::print(PEGASUS_STD(ostream)& os) const{    for (InheritanceTreeRep::Table::Iterator i = _rep->table.start(); i; i++)        i.value()->print(os);}PEGASUS_NAMESPACE_END

⌨️ 快捷键说明

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