1 martin 1.34 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.35 //
|
3 martin 1.34 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.35 //
|
10 martin 1.34 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.35 //
|
17 martin 1.34 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.35 //
|
20 martin 1.34 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.35 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.34 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.35 //
|
28 martin 1.34 //////////////////////////////////////////////////////////////////////////
|
29 mike 1.15 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #ifndef Pegasus_InheritanceTree_h
33 #define Pegasus_InheritanceTree_h
34
35 #include <iostream>
36 #include <Pegasus/Common/Config.h>
|
37 kumpf 1.21 #include <Pegasus/Common/ArrayInternal.h>
|
38 kumpf 1.22 #include <Pegasus/Common/CIMName.h>
|
39 mike 1.15 #include <Pegasus/Common/String.h>
|
40 kumpf 1.20 #include <Pegasus/Common/InternalException.h>
|
41 kumpf 1.19 #include <Pegasus/Repository/Linkage.h>
|
42 kumpf 1.31 #include <Pegasus/Common/MessageLoader.h>
|
43 mike 1.15
44 PEGASUS_NAMESPACE_BEGIN
45
46 struct InheritanceTreeRep;
|
47 schuur 1.25 class NameSpace;
|
48 mike 1.15
49 /** The InheritanceTree class tracks inheritance relationships of CIM classes.
50
|
51 kumpf 1.31 This class is a memory resident version of the repository's persistent
52 inheritance information (represented using file names). The InheritanceTree
|
53 mike 1.15 provides O(1) access (via hashing) to any class in the inheritance tree.
54
55 The inheritance tree provides methods for interrogating certain kinds of
56 information about a class, including:
57
|
58 kumpf 1.31 <ul>
59 <li>the superclass</li>
60 <li>the subclasses</li>
61 <li>the descendent classes</li>
62 </ul>
|
63 mike 1.15
64 The insert() method is used to build up an InheritanceTree. The insert()
65 method is called for each class-subclass relationship. For example, consider
66 the following list of class-subclass pairs:
67
|
68 kumpf 1.31 <pre>
69 { "D", "B" }
70 { "E", "B" }
71 { "B", "A" }
72 { "C", "A" }
73 { "F", "C" }
74 </pre>
|
75 mike 1.15
76 These pairs specify the following inheritance tree:
77
|
78 kumpf 1.31 <pre>
|
79 mike 1.15 A
80 / \
81 B C
82 / \ \
83 D E F
|
84 kumpf 1.31 </pre>
|
85 mike 1.15
86 The pairs above may be used to build a class tree as follows:
87
|
88 kumpf 1.31 <pre>
89 InheritanceTree it;
90 it.insert("D", "B");
91 it.insert("E", "B");
92 it.insert("B", "A");
93 it.insert("C", "A");
94 it.insert("F", "C");
95 it.insert("A", "");
96 it.check();
97 </pre>
|
98 mike 1.15
99 The check() method determines whether insert() was called for every class
100 used as a superclass. In the following example, check() would fail (and
101 throw and exception) since the "B" class is passed as a superclass (second
102 argument) in two insert() calls but was never passed as the class itself
103 (first argument) in any insert() call:
104
|
105 kumpf 1.31 <pre>
106 InheritanceTree it;
107 it.insert("D", "B");
108 it.insert("E", "B");
109 it.insert("C", "A");
110 it.insert("F", "C");
111 it.insert("A", "");
112 it.check();
113 </pre>
|
114 mike 1.15
115 In this case, check() throws an InvalidInheritanceTree exception.
116
117 The InheritanceTree may be printed by calling the print() method.
118 */
119 class PEGASUS_REPOSITORY_LINKAGE InheritanceTree
120 {
121 public:
122
123 /** Default constructor. */
124 InheritanceTree();
125
126 /** Destructor. */
127 ~InheritanceTree();
128
129 /** Inserts a class-subclass relationship into the inheritance three.
|
130 kumpf 1.31 Note that a class CAN be inserted before its superclass, in which case
131 a provisional entry is made for the superclass and flagged as such;
132 when the superclass is later inserted, the provisional flag is cleared.
133 @param className - name of class being inserted.
134 @param superClassName - name of super class of class.
|
135 mike 1.15 */
136 void insert(const String& className, const String& superClassName);
|
137 kumpf 1.31 void insert(
138 const String& className,
139 const String& superClassName,
140 InheritanceTree& parentTree,
141 NameSpace* parent);
|
142 mike 1.15
143 /** Checks that every superClassName passed to insert() was also passed
|
144 kumpf 1.31 as a className argument to insert(). In other words, it checks that
145 there are no provisional entries as described in the insert() method.
146 @exception InvalidInheritanceTree
|
147 mike 1.15 */
148 void check() const;
149
150 /** Get subclass names of the given class.
|
151 kumpf 1.31 @param className - class whose subclass names will be gotten. If
152 className is empty, all classnames are returned.
153 @param deepInheritance - if true all descendent classes of class
154 are returned. If className is empty, only root classes are returned.
155 @param subClassNames - output argument to hold subclass names.
156 @return true on success. False if no such class.
|
157 mike 1.15 */
158 Boolean getSubClassNames(
|
159 kumpf 1.31 const CIMName& className,
160 Boolean deepInheritance,
161 Array<CIMName>& subClassNames,
162 NameSpace* ns = NULL) const;
|
163 mike 1.15
|
164 schuur 1.25 #if 0
|
165 mike 1.15 /** Returns true if class1 is a subclass of class2.
166 */
|
167 kumpf 1.22 Boolean isSubClass(const CIMName& class1, const CIMName& class2) const;
|
168 schuur 1.25 #endif
|
169 mike 1.15
170 /** Get the names of all superclasses of this class (direct and indirect).
171 */
172 Boolean getSuperClassNames(
|
173 kumpf 1.31 const CIMName& className,
174 Array<CIMName>& subClassNames) const;
|
175 mike 1.15
176 /** Get the superclass of the given class.
|
177 kumpf 1.31 @param className name of class.
178 @param superClassName name of superclass upon return.
179 @return true if class was found; false otherwise.
|
180 mike 1.15 */
181 Boolean getSuperClass(
|
182 kumpf 1.31 const CIMName& className,
183 CIMName& superClassName) const;
|
184 mike 1.15
185 /** Returns true if the given class has sub-classes. */
186 Boolean hasSubClasses(
|
187 kumpf 1.31 const CIMName& className,
188 Boolean& hasSubClasses) const;
|
189 mike 1.15
190 /** Returns true if this inhertance tree contains the given class. */
|
191 kumpf 1.22 Boolean containsClass(const CIMName& className) const;
|
192 mike 1.15
|
193 kumpf 1.31 /** Removes the given class from the class graph.
194 @exception CIMException(CIM_ERR_CLASS_HAS_CHILDREN)
195 @exception CIMException(CIM_ERR_INVALID_CLASS)
|
196 mike 1.15 */
|
197 schuur 1.25 void remove(const CIMName& className,
|
198 kumpf 1.31 InheritanceTree& parentTree,
199 NameSpace* ns = NULL);
|
200 mike 1.15
201 /** Prints the class */
202 void print(PEGASUS_STD(ostream)& os) const;
203
204 private:
205
206 InheritanceTree(const InheritanceTree&) { }
207
208 InheritanceTree& operator=(const InheritanceTree&) { return *this; }
209
210 InheritanceTreeRep* _rep;
|
211 kumpf 1.31
|
212 david.dillard 1.26 friend struct InheritanceTreeNode;
|
213 mike 1.15 };
214
215 /** The InvalidInheritanceTree exception is thrown when the
216 InheritanceTreeRep::check() method determines that an inheritance tree
217 was not fully specified (when any class was passed as a superClassName
218 argument to insert() but never as a className argument.
219 */
|
220 mike 1.30 class PEGASUS_REPOSITORY_LINKAGE InvalidInheritanceTree : public Exception
|
221 mike 1.15 {
222 public:
|
223 kumpf 1.31 InvalidInheritanceTree(const String& className)
224 : Exception(MessageLoaderParms(
225 "Repository.InheritanceTree.INVALID_INHERITANCE_TREE",
226 "Invalid inheritance tree: unknown class: $0", className))
227 {
228 }
|
229 mike 1.15 };
230
231 PEGASUS_NAMESPACE_END
232
233 #endif /* Pegasus_InheritanceTree_h */
|