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

  1 mike  1.6 //%/////////////////////////////////////////////////////////////////////////////
  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.6 //
 23           // Author: Mike Brasher (mbrasher@bmc.com)
 24           //
 25           // Modified By:
 26           //
 27           //%/////////////////////////////////////////////////////////////////////////////
 28           
 29           #ifndef Pegasus_CIMObject_h
 30           #define Pegasus_CIMObject_h
 31           
 32           #include <Pegasus/Common/Config.h>
 33           #include <Pegasus/Common/CIMClass.h>
 34           #include <Pegasus/Common/CIMInstance.h>
 35           
 36           PEGASUS_NAMESPACE_BEGIN
 37           
 38           /** This class contains either a class or an instance (both CIM objects).
 39               Initializers are provided for both CIMClass and CIMInstance. The
 40               isClass() and isInstance() methods are provided for determining the
 41               type of contained object. Methods are also provided for getting
 42               the internal object (into a CIMClass or CIMInstance).
 43 mike  1.6 */
 44           class PEGASUS_COMMON_LINKAGE CIMObject
 45           {
 46           public:
 47           
 48               CIMObject() : _rep(0), _type(TYPE_NONE)
 49               {
 50           
 51               }
 52           
 53               CIMObject(const CIMObject& x) : _type(x._type)
 54               {
 55           	Inc(_rep = x._rep);
 56               }
 57           
 58               CIMObject(const CIMClass& x) : _type(TYPE_CLASS)
 59               {
 60           	Inc(_rep = x._rep);
 61               }
 62           
 63               CIMObject(const CIMInstance& x) : _type(TYPE_INSTANCE)
 64 mike  1.6     {
 65           	Inc(_rep = x._rep);
 66               }
 67           
 68               CIMObject& operator=(const CIMObject& x)
 69               {
 70           	if (x._rep != _rep)
 71           	{
 72           	    Dec(_rep);
 73           	    Inc(_rep = x._rep);
 74           	    _type = x._type;
 75           	}
 76           	return *this;
 77               }
 78           
 79               CIMObject& operator=(const CIMClass& x)
 80               {
 81           	if (x._rep != _rep)
 82           	{
 83           	    Dec(_rep);
 84           	    Inc(_rep = x._rep);
 85 mike  1.6 	    _type = TYPE_CLASS;
 86           	}
 87           	return *this;
 88               }
 89           
 90               CIMObject& operator=(const CIMInstance& x)
 91               {
 92           	if (x._rep != _rep)
 93           	{
 94           	    Dec(_rep);
 95           	    Inc(_rep = x._rep);
 96           	    _type = TYPE_INSTANCE;
 97           	}
 98           	return *this;
 99               }
100           
101               ~CIMObject()
102               {
103           	Dec(_rep);
104               }
105           
106 mike  1.6     Boolean isClass() const
107               {
108           	return _type == TYPE_CLASS;
109               }
110           
111               Boolean isInstance() const
112               {
113           	return _type == TYPE_INSTANCE;
114               }
115           
116               /** Returns the class contained by this object (if an class).
117           	@return CIMClass
118           	@exception throws TypeMismatch if object does not contain a CIMClass.
119               */
120               CIMClass getClass();
121           
122               /** Const version of getClass() */
123           
124               CIMConstClass getClass() const;
125           
126               /** Returns the instance contained by this object (if an instance).
127 mike  1.6 	@return CIMInstance
128           	@exception throws TypeMismatch if object does not contain a CIMInstance.
129               */
130               CIMInstance getInstance();
131           
132               /** Const version of getInstance() */
133           
134               CIMConstInstance getInstance() const;
135           
136               operator int() const 
137               { 
138           	return _rep != 0; 
139               }
140           
141               void toXml(Array<Sint8>& out) const;
142           
143           private:
144           
145               void _checkRep() const
146               {
147           	if (!_rep)
148 mike  1.6 	    ThrowUnitializedHandle();
149               }
150           
151               // Point to either a CIMClass or CIMInstance:
152           
153               Sharable* _rep;
154           
155               enum Type { TYPE_CLASS, TYPE_INSTANCE, TYPE_NONE };
156               Type _type;
157           };
158           
159           /** The CIMObjectWithPath encapsulates a CIMReference and CIMObject.
160               Accessors are provided for getting the two parts. Constructors are
161               provided for initializing it from a CIMObject.
162           */
163           class PEGASUS_COMMON_LINKAGE CIMObjectWithPath
164           {
165           public:
166           
167               /**	Constructor
168               */
169 mike  1.6     CIMObjectWithPath();
170           
171               /** constructor
172               */
173               CIMObjectWithPath(const CIMReference& reference, const CIMObject& object);
174           
175               /** Constructor - Constructs a CIMObjectWithPath Object from
176                   another CimObjectWithPath
177                   @param - ATTN
178               */
179               CIMObjectWithPath(const CIMObjectWithPath& x);
180           
181               ~CIMObjectWithPath();
182           
183               CIMObjectWithPath& operator=(const CIMObjectWithPath& x);
184           
185               /** set - 
186               */
187               void set(const CIMReference& reference, const CIMObject& object);
188           
189               /**
190 mike  1.6     */
191               const CIMReference& getReference() const { return _reference; }
192           
193               /**
194               */
195               const CIMObject& getObject() const { return _object; }
196           
197               /**
198               */
199               CIMReference& getReference() { return _reference; }
200           
201               /**
202               */
203               CIMObject& getObject() { return _object; }
204           
205               /**
206               */
207               void toXml(Array<Sint8>& out) const;
208           
209           private:
210           
211 mike  1.6     CIMReference _reference;
212               CIMObject _object;
213           };
214           
215           PEGASUS_NAMESPACE_END
216           
217           #endif /* Pegasus_CIMObject_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2