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

  1 karl  1.8 //%2006////////////////////////////////////////////////////////////////////////
  2 schuur 1.1 //
  3 karl   1.2 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 schuur 1.1 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl   1.2 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl   1.3 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl   1.8 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 schuur 1.1 //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15            // of this software and associated documentation files (the "Software"), to
 16            // deal in the Software without restriction, including without limitation the
 17            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18            // sell copies of the Software, and to permit persons to whom the Software is
 19            // furnished to do so, subject to the following conditions:
 20            // 
 21            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29            //
 30            //==============================================================================
 31            //
 32            //%/////////////////////////////////////////////////////////////////////////////
 33            
 34 schuur 1.1 #ifndef Pegasus_ValueRep_h
 35            #define Pegasus_ValueRep_h
 36            
 37 mike   1.6 #include <new>
 38 schuur 1.1 #include "Union.h"
 39 mike   1.6 #include "AtomicInt.h"
 40 schuur 1.1 
 41            PEGASUS_NAMESPACE_BEGIN
 42            
 43 mike   1.10 class PEGASUS_COMMON_LINKAGE CIMValueRep
 44 schuur 1.1  {
 45             public:
 46 mike   1.6  
 47                 CIMValueRep();
 48             
 49 kumpf  1.11     CIMValueRep(int*);
 50 mike   1.6  
 51                 ~CIMValueRep();
 52             
 53                 void release();
 54             
 55                 static void ref(const CIMValueRep* rep);
 56             
 57                 static void unref(const CIMValueRep* rep);
 58             
 59                 AtomicInt refs;
 60                 CIMType type;
 61                 Boolean isArray;
 62                 Boolean isNull;
 63                 Union u;
 64             
 65                 static CIMValueRep _emptyRep;
 66             };
 67             
 68             inline CIMValueRep::CIMValueRep() : refs(1)
 69             {
 70 kumpf  1.11 }
 71 mike   1.6  
 72             inline CIMValueRep::CIMValueRep(int*) :
 73 kumpf  1.11     refs(2), type(CIMTYPE_BOOLEAN), isArray(false), isNull(true)
 74 mike   1.6  {
 75                 // This constructor is only used by the _emptyRep object.
 76                 memset(&u, 0, sizeof(Union));
 77             }
 78             
 79 kumpf  1.11 inline CIMValueRep::~CIMValueRep()
 80 mike   1.6  {
 81                 release();
 82             }
 83             
 84             inline void CIMValueRep::ref(const CIMValueRep* rep)
 85             {
 86                 if (rep != &CIMValueRep::_emptyRep)
 87 schuur 1.1      {
 88 mike   1.6          ((CIMValueRep*)rep)->refs++;
 89 schuur 1.1      }
 90 mike   1.6  }
 91 schuur 1.1  
 92 mike   1.6  inline void CIMValueRep::unref(const CIMValueRep* rep)
 93             {
 94 kumpf  1.11     if (rep != &CIMValueRep::_emptyRep &&
 95                     ((CIMValueRep*)rep)->refs.decAndTestIfZero())
 96 mike   1.6      {
 97 kumpf  1.11         delete (CIMValueRep*)rep;
 98 mike   1.6      }
 99             }
100             
101             //==============================================================================
102             //
103             // CIMValueType - template utilities used below.
104             //
105             //==============================================================================
106             
107             // Functions to perform type deduction.
108             inline CIMType TypeOf(Boolean*) { return CIMTYPE_BOOLEAN; }
109             inline CIMType TypeOf(Uint8*) { return CIMTYPE_UINT8; }
110             inline CIMType TypeOf(Sint8*) { return CIMTYPE_SINT8; }
111             inline CIMType TypeOf(Uint16*) { return CIMTYPE_UINT16; }
112             inline CIMType TypeOf(Sint16*) { return CIMTYPE_SINT16; }
113             inline CIMType TypeOf(Uint32*) { return CIMTYPE_UINT32; }
114             inline CIMType TypeOf(Sint32*) { return CIMTYPE_SINT32; }
115             inline CIMType TypeOf(Uint64*) { return CIMTYPE_UINT64; }
116             inline CIMType TypeOf(Sint64*) { return CIMTYPE_SINT64; }
117             inline CIMType TypeOf(Real32*) { return CIMTYPE_REAL32; }
118             inline CIMType TypeOf(Real64*) { return CIMTYPE_REAL64; }
119 mike   1.6  inline CIMType TypeOf(Char16*) { return CIMTYPE_CHAR16; }
120             inline CIMType TypeOf(String*) { return CIMTYPE_STRING; }
121             inline CIMType TypeOf(CIMDateTime*) { return CIMTYPE_DATETIME; }
122             inline CIMType TypeOf(CIMObjectPath*) { return CIMTYPE_REFERENCE; }
123             inline CIMType TypeOf(CIMObject*) { return CIMTYPE_OBJECT; }
124 a.dunfey 1.9  #ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
125               inline CIMType TypeOf(CIMInstance*) { return CIMTYPE_INSTANCE; }
126               #endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT
127 mike     1.6  
128               inline bool IsRaw(Boolean*) { return true; }
129               inline bool IsRaw(Uint8*) { return true; }
130               inline bool IsRaw(Sint8*) { return true; }
131               inline bool IsRaw(Uint16*) { return true; }
132               inline bool IsRaw(Sint16*) { return true; }
133               inline bool IsRaw(Uint32*) { return true; }
134               inline bool IsRaw(Sint32*) { return true; }
135               inline bool IsRaw(Uint64*) { return true; }
136               inline bool IsRaw(Sint64*) { return true; }
137               inline bool IsRaw(Real32*) { return true; }
138               inline bool IsRaw(Real64*) { return true; }
139               inline bool IsRaw(Char16*) { return true; }
140               inline bool IsRaw(String*) { return false; }
141               inline bool IsRaw(CIMDateTime*) { return false; }
142               inline bool IsRaw(CIMObjectPath*) { return false; }
143               inline bool IsRaw(CIMObject*) { return false; }
144 a.dunfey 1.9  #ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
145               inline bool IsRaw(CIMInstance*) { return false; }
146               #endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT
147 mike     1.6  
148               template<class T>
149               struct CIMValueType
150               {
151               public:
152               
153                   static T* ptr(const CIMValueRep* rep)
154                   {
155 kumpf    1.11         return (T*)(&rep->u);
156 mike     1.6      }
157               
158                   static T& ref(const CIMValueRep* rep)
159 schuur   1.1      {
160 kumpf    1.11         return *((T*)((void*)&rep->u));
161 schuur   1.1      }
162               
163 mike     1.6      static Array<T>* aptr(const CIMValueRep* rep)
164 schuur   1.1      {
165 kumpf    1.11         return (Array<T>*)(&rep->u);
166 schuur   1.1      }
167               
168 mike     1.6      static Array<T>& aref(const CIMValueRep* rep)
169                   {
170 kumpf    1.11         return *((Array<T>*)((void*)&rep->u));
171 mike     1.6      }
172 mike     1.5  
173 mike     1.6      static void defaultConstruct(CIMValueRep* rep)
174 mike     1.5      {
175 kumpf    1.11         if (IsRaw((T*)0))
176                           rep->u._uint64Value = (Uint64)0;
177                       else
178                           new((T*)((void*)&rep->u)) T();
179 mike     1.5      }
180               
181 mike     1.6      static void copyConstruct(CIMValueRep* rep, const T& x)
182 mike     1.5      {
183 kumpf    1.11         new((T*)((void*)&rep->u)) T(x);
184 mike     1.6      }
185               
186                   static void copyConstructArray(CIMValueRep* rep, const Array<T>& x)
187                   {
188 kumpf    1.11         new((Array<T>*)((void*)&rep->u)) Array<T>(x);
189 mike     1.6      }
190               
191                   static void constructArrayWithSize(CIMValueRep* rep, Uint32 arraySize)
192                   {
193 kumpf    1.11         new((Array<T>*)((void*)&rep->u)) Array<T>(arraySize);
194 mike     1.6      }
195               
196                   static void destruct(CIMValueRep* rep)
197                   {
198 kumpf    1.11         ((T*)((void*)&rep->u))->~T();
199 mike     1.6      }
200               
201                   static void destructArray(CIMValueRep* rep)
202                   {
203 kumpf    1.11         ((Array<T>*)((void*)&rep->u))->~Array<T>();
204 mike     1.6      }
205               
206                   static void setNull(
207 kumpf    1.11         CIMValueRep* rep, CIMType type_, bool isArray_, Uint32 arraySize_)
208 mike     1.6      {
209 kumpf    1.11         rep->type = type_;
210                       rep->isArray = isArray_;
211                       rep->isNull = true;
212               
213                       if (isArray_)
214                           constructArrayWithSize(rep, arraySize_);
215                       else
216                           defaultConstruct(rep);
217 mike     1.6      }
218               
219                   static void set(CIMValueRep* rep, const T& x)
220                   {
221 kumpf    1.11         rep->type = TypeOf((T*)0);
222                       rep->isArray = false;
223                       rep->isNull = false;
224                       copyConstruct(rep, x);
225 mike     1.6      }
226               
227                   static void setArray(CIMValueRep* rep, const Array<T>& x)
228                   {
229 kumpf    1.11         rep->type = TypeOf((T*)0);
230                       rep->isArray = true;
231                       rep->isNull = false;
232                       copyConstructArray(rep, x);
233 mike     1.6      }
234               
235                   static Uint32 arraySize(CIMValueRep* rep)
236                   {
237 kumpf    1.11         return aref(rep).size();
238 mike     1.6      }
239               
240                   static bool equal(const CIMValueRep* r1, const CIMValueRep* r2)
241                   {
242 kumpf    1.11         return ref(r1) == ref(r2);
243 mike     1.6      }
244               
245                   static bool equalArray(const CIMValueRep* r1, const CIMValueRep* r2)
246                   {
247 kumpf    1.11         return aref(r1) == aref(r2);
248 mike     1.5      }
249 schuur   1.1  };
250               
251               PEGASUS_NAMESPACE_END
252               
253               #endif /* Pegasus_ValueRep_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2