(file) Return to InheritanceTree.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Repository

Diff for /pegasus/src/Pegasus/Repository/InheritanceTree.h between version 1.1 and 1.2

version 1.1, 2001/04/27 00:01:34 version 1.2, 2001/04/27 02:09:03
Line 19 
Line 19 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author:  // Author: Mike Brasher (mbrasher@bmc.com)
 // //
 // Modified By: // Modified By:
 // //
Line 28 
Line 28 
 #ifndef Pegasus_InheritanceTree_h #ifndef Pegasus_InheritanceTree_h
 #define Pegasus_InheritanceTree_h #define Pegasus_InheritanceTree_h
  
   #include <iostream>
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
   #include <Pegasus/Common/HashTable.h>
   #include <Pegasus/Common/String.h>
   #include <Pegasus/Common/HashTable.h>
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
Line 39 
Line 43 
     provides O(1) access (via hashing) to any class in the inheritance tree.     provides O(1) access (via hashing) to any class in the inheritance tree.
  
 */ */
   class PEGASUS_REPOSITORY_LINKAGE InheritanceTree
   {
   public:
  
       InheritanceTree()
       {
   
       }
   
       Boolean insert(const String& className, const String& superClassName)
       {
           // ATTN: need found flag!
   
           // -- Insert superclass:
   
           Node* superClassNode = 0;
   
           if (superClassName.getLength() &&
               !_table.lookup(superClassName, superClassNode))
           {
               superClassNode = new Node(superClassName);
               _table.insert(superClassName, superClassNode);
           }
   
           // -- Insert class:
   
           Node* classNode = 0;
   
           if (!_table.lookup(className, classNode))
           {
               classNode = new Node(className);
               _table.insert(className, classNode);
           }
   
           // -- Link the class and superclass nodes:
   
           if (superClassNode)
               superClassNode->addSubClass(classNode);
   
           return true;
       }
   
       void print() const
       {
           for (Table::Iterator i = _table.start(); i; i++)
               i.value()->print();
       }
   
   private:
   
       struct Node
       {
           Node(const String& className) : _className(className), _superClass(0),
               _sibling(0), _subClasses(0)
           {
   
           }
   
           void addSubClass(Node* child)
           {
               child->_superClass = this;
               child->_sibling = _subClasses;
               _subClasses = child;
           }
   
           String _className;
           Node* _superClass;
           Node* _sibling;
           Node* _subClasses;
   
           void print() const
           {
               std::cout << "*** ClassName: " << _className << std::endl;
   
               std::cout << "Subclasses: ";
   
               for (Node* p = _subClasses; p; p = p->_sibling)
                   std::cout << p->_className << ' ';
               std::cout << std::endl;
   
               std::cout << "Superclass: ";
   
               if (_superClass)
                   std::cout << _superClass->_className;
               else
                   std::cout << "#";
   
               std::cout << std::endl;
           }
       };
   
       typedef HashTable<String, Node*> Table;
       Table _table;
   };
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END
  


Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2