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

  1 mike  1.1 //%/////////////////////////////////////////////////////////////////////////////
  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.1 //
 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.1 */
 44           class PEGASUS_COMMON_LINKAGE CIMObject
 45           {
 46           public:
 47           
 48               CIMObject() : _rep(0)
 49               {
 50           
 51               }
 52           
 53               CIMObject(const CIMObject& x)
 54               {
 55           	Inc(_rep = x._rep);
 56               }
 57           
 58               CIMObject(const CIMClass& x)
 59               {
 60           	Inc(_rep = x._rep);
 61               }
 62           
 63               CIMObject(const CIMInstance& x)
 64 mike  1.1     {
 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           	}
 75           	return *this;
 76               }
 77           
 78               CIMObject& operator=(const CIMClass& x)
 79               {
 80           	if (x._rep != _rep)
 81           	{
 82           	    Dec(_rep);
 83           	    Inc(_rep = x._rep);
 84           	}
 85 mike  1.1 	return *this;
 86               }
 87           
 88               CIMObject& operator=(const CIMInstance& x)
 89               {
 90           	if (x._rep != _rep)
 91           	{
 92           	    Dec(_rep);
 93           	    Inc(_rep = x._rep);
 94           	}
 95           	return *this;
 96               }
 97           
 98               ~CIMObject()
 99               {
100           	Dec(_rep);
101               }
102           
103               Boolean isClass() const
104               {
105           	_checkRep();
106 mike  1.1 	return dynamic_cast<CIMClassRep*>(_rep) != 0;
107               }
108           
109               Boolean isInstance() const
110               {
111           	_checkRep();
112           	return dynamic_cast<CIMInstanceRep*>(_rep) != 0;
113               }
114           
115               /** Returns the class contained by this object (if an class).
116           	@return CIMClass
117           	@exception throws TypeMismatch if object does not contain a CIMClass.
118               */
119               CIMClass getClass();
120           
121               /** Returns the instance contained by this object (if an instance).
122           	@return CIMInstance
123           	@exception throws TypeMismatch if object does not contain a CIMInstance.
124               */
125               CIMInstance getInstance();
126           
127 mike  1.1     operator int() const 
128               { 
129           	return _rep != 0; 
130               }
131           
132           private:
133           
134               void _checkRep() const
135               {
136           	if (!_rep)
137           	    ThrowUnitializedHandle();
138               }
139           
140               // Point to either a CIMClass or CIMInstance:
141           
142               Sharable* _rep;
143           };
144           
145           /** The CIMObjectWithPath encapsulates a CIMReference and CIMObject.
146               Accessors are provided for getting the two parts. Constructors are
147               provided for initializing it from a CIMObject.
148 mike  1.1 */
149           class PEGASUS_COMMON_LINKAGE CIMObjectWithPath
150           {
151           public:
152           
153               CIMObjectWithPath();
154           
155               CIMObjectWithPath(CIMReference& reference, CIMObject& object);
156           
157               CIMObjectWithPath(const CIMObjectWithPath& x);
158           
159               ~CIMObjectWithPath();
160           
161               CIMObjectWithPath& operator=(const CIMObjectWithPath& x);
162           
163               void set(CIMReference& reference, CIMObject& object);
164           
165               const CIMReference& getReference() const { return _reference; }
166           
167               const CIMObject& getObject() const { return _object; }
168           
169 mike  1.1     CIMReference& getReference() { return _reference; }
170           
171               CIMObject& getObject() { return _object; }
172           
173           private:
174           
175               CIMReference _reference;
176               CIMObject _object;
177           };
178           
179           PEGASUS_NAMESPACE_END
180           
181           #endif /* Pegasus_CIMObject_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2