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

  1 mike  1.15 //%/////////////////////////////////////////////////////////////////////////////
  2            //
  3            // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
  4            //
  5            // Permission is hereby granted, free of charge, to any person obtaining a copy
  6            // of this software and associated documentation files (the "Software"), to 
  7            // deal in the Software without restriction, including without limitation the 
  8            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
  9            // sell copies of the Software, and to permit persons to whom the Software is
 10            // furnished to do so, subject to the following conditions:
 11            // 
 12            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN 
 13            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 14            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 15            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 16            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
 17            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
 18            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 19            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 20            //
 21            //==============================================================================
 22 mike  1.15 //
 23            // Author: Mike Brasher (mbrasher@bmc.com)
 24            //
 25            // Modified By:
 26            //
 27            //%/////////////////////////////////////////////////////////////////////////////
 28            
 29            #ifndef Pegasus_InheritanceTree_h
 30            #define Pegasus_InheritanceTree_h
 31            
 32            #include <iostream>
 33            #include <Pegasus/Common/Config.h>
 34            #include <Pegasus/Common/String.h>
 35            #include <Pegasus/Common/Exception.h>
 36            
 37            PEGASUS_NAMESPACE_BEGIN
 38            
 39            struct InheritanceTreeRep;
 40            
 41            /** The InheritanceTree class tracks inheritance relationships of CIM classes.
 42            
 43 mike  1.15     This class is a memory resident version of the repository's persistent 
 44                inheritance information (represented using file names). The InheritanceTree 
 45                provides O(1) access (via hashing) to any class in the inheritance tree.
 46            
 47                The inheritance tree provides methods for interrogating certain kinds of
 48                information about a class, including:
 49            
 50            	<ul>
 51            	<li>the superclass</li>
 52            	<li>the subclasses</li>
 53            	<li>the descendent classes</li>
 54            	</ul>
 55            
 56                The insert() method is used to build up an InheritanceTree. The insert()
 57                method is called for each class-subclass relationship. For example, consider
 58                the following list of class-subclass pairs:
 59            
 60            	<pre>
 61            	{ "D", "B" }
 62            	{ "E", "B" }
 63            	{ "B", "A" }
 64 mike  1.15 	{ "C", "A" }
 65            	{ "F", "C" }
 66            	</pre>
 67            
 68                These pairs specify the following inheritance tree:
 69            
 70            	<pre>
 71                          A
 72                        /   \
 73                       B     C
 74                     /   \     \
 75                    D     E     F
 76            	</pre>
 77            
 78                The pairs above may be used to build a class tree as follows:
 79            
 80            	<pre>
 81            	InheritanceTree it;
 82            	it.insert("D", "B");
 83            	it.insert("E", "B");
 84            	it.insert("B", "A");
 85 mike  1.15 	it.insert("C", "A");
 86            	it.insert("F", "C");
 87            	it.insert("A", "");
 88            	it.check();
 89            	</pre>
 90            
 91                The check() method determines whether insert() was called for every class
 92                used as a superclass. In the following example, check() would fail (and
 93                throw and exception) since the "B" class is passed as a superclass (second
 94                argument) in two insert() calls but was never passed as the class itself
 95                (first argument) in any insert() call:
 96            
 97            	<pre>
 98            	InheritanceTree it;
 99            	it.insert("D", "B");
100            	it.insert("E", "B");
101            	it.insert("C", "A");
102            	it.insert("F", "C");
103            	it.insert("A", "");
104            	it.check();
105            	</pre>
106 mike  1.15 
107                In this case, check() throws an InvalidInheritanceTree exception.
108            
109                The InheritanceTree may be printed by calling the print() method.
110            
111                The insertFromPath() method is used to build up an InheritanceTree from
112                the file names in a certain directory as used by the CIMRepository. The
113                CIMRepository contains a disk file per class and the name has this form:
114            
115            	<pre>
116            	<ClassName>.<SuperClassName>
117            	</pre>
118            
119                For example, a class called "ThisClass" with super class "ThatClass" 
120                has this name:
121            
122            	<pre>
123            	ThisClass.ThisClass
124            	</pre>
125            
126                The file or course contains the XML encoding of the ThisClass class (which 
127 mike  1.15     is irrelevant for the InheritanceTree). A root class (with no superclass
128                has the following form):
129            
130            	<pre>
131            	<ClassName>.#
132            	</pre>
133            
134                Suppose that ThatClass is a root class; then its file name is:
135            
136            	<pre>
137            	ThatClass.#
138            	</pre>
139            
140                It must be obvious by now that the insertFromPath() method just scans
141                the file names in a directory and calls insert() for each one (splitting
142                the class name from superclass name and translating '#' to an empty string).
143            
144                The insertFromPath() method does NOT call check(), so it still must be 
145                called to verify the InheritanceTree.
146            */
147            class PEGASUS_REPOSITORY_LINKAGE InheritanceTree
148 mike  1.15 {
149            public:
150            
151                /** Default constructor. */
152                InheritanceTree();
153            
154                /** Destructor. */
155                ~InheritanceTree();
156            
157                /** Inserts a class-subclass relationship into the inheritance three.
158            	Note that a class CAN be inserted before its superclass, in which case
159            	a provisional entry is made for the superclass and flagged as such; 
160            	when the superclass is later inserted, the provisional flag is cleared.
161            	@param className - name of class being inserted.
162            	@param superClassName - name of super class of class.
163                */
164                void insert(const String& className, const String& superClassName);
165            
166                /** Scan directory for file names of the form <ClassName>.<SuperClass> and
167            	call insert on insert for each one. Note that root classes (classes with
168            	no superclass) will use "#" for a SuperClass name.
169 mike  1.15 	@param path - directory that contains files describing inheritance 
170            	    infoformation.
171            	@exception throws CannotOpenDirectory is invalid path specifies an
172            	    invalid directory.
173                */
174                void insertFromPath(const String& path);
175            
176                /** Checks that every superClassName passed to insert() was also passed
177            	as a className argument to insert(). In other words, it checks that
178            	there are no provisional entries as described in the insert() method.
179            	@exception InvalidInheritanceTree
180                */
181                void check() const;
182            
183                /** Get subclass names of the given class.
184            	@param className - class whose subclass names will be gotten. If
185            	    className is empty, all classnames are returned.
186            	@param deepInheritance - if true all descendent classes of class
187            	    are returned. If className is empty, only root classes are returned.
188            	@param subClassNames - output argument to hold subclass names.
189            	@return true on success. False if no such class.
190 mike  1.15     */
191                Boolean getSubClassNames(
192            	const String& className,
193            	Boolean deepInheritance,
194            	Array<String>& subClassNames) const;
195            
196                /** Returns true if class1 is a subclass of class2.
197                */
198                Boolean isSubClass(const String& class1, const String& class2);
199            
200                /** Get the names of all superclasses of this class (direct and indirect).
201                */
202                Boolean getSuperClassNames(
203            	const String& className,
204            	Array<String>& subClassNames) const;
205            
206                /** Get the superclass of the given class.
207            	@param className name of class.
208            	@param superClassName name of superclass upon return.
209            	@return true if class was found; false otherwise.
210                */
211 mike  1.15     Boolean getSuperClass(
212            	const String& className,
213            	String& superClassName) const;
214            
215                /** Returns true if the given class has sub-classes. */
216                Boolean hasSubClasses(
217            	const String& className,
218            	Boolean& hasSubClasses) const;
219            
220                /** Returns true if this inhertance tree contains the given class. */
221                Boolean containsClass(const String& className) const;
222            
223                /** Removes the given class from the class graph. 
224            	@exception CIMException(CIM_ERR_CLASS_HAS_CHILDREN)
225            	@exception CIMException(CIM_ERR_INVALID_CLASS)
226                */
227                void remove(const String& className);
228            
229                /** Prints the class */
230                void print(PEGASUS_STD(ostream)& os) const;
231            
232 mike  1.15 private:
233            
234                InheritanceTree(const InheritanceTree&) { }
235            
236                InheritanceTree& operator=(const InheritanceTree&) { return *this; }
237            
238                InheritanceTreeRep* _rep;
239            };
240            
241            /** The InvalidInheritanceTree exception is thrown when the
242                InheritanceTreeRep::check() method determines that an inheritance tree
243                was not fully specified (when any class was passed as a superClassName
244                argument to insert() but never as a className argument.
245            */
246            class InvalidInheritanceTree : public Exception
247            {
248            public:
249            
250                InvalidInheritanceTree(const String& className) 
251            	: Exception("Invalid inheritance tree: unknown class: " + className) { }
252            };
253 mike  1.15 
254            PEGASUS_NAMESPACE_END
255            
256            #endif /* Pegasus_InheritanceTree_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2