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

  1 martin 1.13 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.14 //
  3 martin 1.13 // 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.14 //
 10 martin 1.13 // 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.14 //
 17 martin 1.13 // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19 martin 1.14 //
 20 martin 1.13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.14 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.13 // 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.14 //
 28 martin 1.13 //////////////////////////////////////////////////////////////////////////
 29 schuur 1.1  //
 30             //%/////////////////////////////////////////////////////////////////////////////
 31             
 32             #ifndef Pegasus_ValueRep_h
 33             #define Pegasus_ValueRep_h
 34             
 35 mike   1.6  #include <new>
 36 schuur 1.1  #include "Union.h"
 37 mike   1.6  #include "AtomicInt.h"
 38 schuur 1.1  
 39             PEGASUS_NAMESPACE_BEGIN
 40             
 41 mike   1.10 class PEGASUS_COMMON_LINKAGE CIMValueRep
 42 schuur 1.1  {
 43             public:
 44 mike   1.6  
 45                 CIMValueRep();
 46             
 47 kumpf  1.11     CIMValueRep(int*);
 48 mike   1.6  
 49                 ~CIMValueRep();
 50             
 51                 void release();
 52             
 53                 static void ref(const CIMValueRep* rep);
 54             
 55                 static void unref(const CIMValueRep* rep);
 56             
 57                 AtomicInt refs;
 58                 CIMType type;
 59                 Boolean isArray;
 60                 Boolean isNull;
 61                 Union u;
 62             
 63                 static CIMValueRep _emptyRep;
 64             };
 65             
 66             inline CIMValueRep::CIMValueRep() : refs(1)
 67             {
 68 kumpf  1.11 }
 69 mike   1.6  
 70             inline CIMValueRep::CIMValueRep(int*) :
 71 kumpf  1.11     refs(2), type(CIMTYPE_BOOLEAN), isArray(false), isNull(true)
 72 mike   1.6  {
 73                 // This constructor is only used by the _emptyRep object.
 74                 memset(&u, 0, sizeof(Union));
 75             }
 76             
 77 kumpf  1.11 inline CIMValueRep::~CIMValueRep()
 78 mike   1.6  {
 79                 release();
 80             }
 81             
 82             inline void CIMValueRep::ref(const CIMValueRep* rep)
 83             {
 84                 if (rep != &CIMValueRep::_emptyRep)
 85 schuur 1.1      {
 86 mike   1.6          ((CIMValueRep*)rep)->refs++;
 87 schuur 1.1      }
 88 mike   1.6  }
 89 schuur 1.1  
 90 mike   1.6  inline void CIMValueRep::unref(const CIMValueRep* rep)
 91             {
 92 kumpf  1.11     if (rep != &CIMValueRep::_emptyRep &&
 93                     ((CIMValueRep*)rep)->refs.decAndTestIfZero())
 94 mike   1.6      {
 95 kumpf  1.11         delete (CIMValueRep*)rep;
 96 mike   1.6      }
 97             }
 98             
 99             //==============================================================================
100             //
101             // CIMValueType - template utilities used below.
102             //
103             //==============================================================================
104             
105             // Functions to perform type deduction.
106             inline CIMType TypeOf(Boolean*) { return CIMTYPE_BOOLEAN; }
107             inline CIMType TypeOf(Uint8*) { return CIMTYPE_UINT8; }
108             inline CIMType TypeOf(Sint8*) { return CIMTYPE_SINT8; }
109             inline CIMType TypeOf(Uint16*) { return CIMTYPE_UINT16; }
110             inline CIMType TypeOf(Sint16*) { return CIMTYPE_SINT16; }
111             inline CIMType TypeOf(Uint32*) { return CIMTYPE_UINT32; }
112             inline CIMType TypeOf(Sint32*) { return CIMTYPE_SINT32; }
113             inline CIMType TypeOf(Uint64*) { return CIMTYPE_UINT64; }
114             inline CIMType TypeOf(Sint64*) { return CIMTYPE_SINT64; }
115             inline CIMType TypeOf(Real32*) { return CIMTYPE_REAL32; }
116             inline CIMType TypeOf(Real64*) { return CIMTYPE_REAL64; }
117 mike   1.6  inline CIMType TypeOf(Char16*) { return CIMTYPE_CHAR16; }
118             inline CIMType TypeOf(String*) { return CIMTYPE_STRING; }
119             inline CIMType TypeOf(CIMDateTime*) { return CIMTYPE_DATETIME; }
120             inline CIMType TypeOf(CIMObjectPath*) { return CIMTYPE_REFERENCE; }
121             inline CIMType TypeOf(CIMObject*) { return CIMTYPE_OBJECT; }
122 a.dunfey 1.9  inline CIMType TypeOf(CIMInstance*) { return CIMTYPE_INSTANCE; }
123 mike     1.6  
124               inline bool IsRaw(Boolean*) { return true; }
125               inline bool IsRaw(Uint8*) { return true; }
126               inline bool IsRaw(Sint8*) { return true; }
127               inline bool IsRaw(Uint16*) { return true; }
128               inline bool IsRaw(Sint16*) { return true; }
129               inline bool IsRaw(Uint32*) { return true; }
130               inline bool IsRaw(Sint32*) { return true; }
131               inline bool IsRaw(Uint64*) { return true; }
132               inline bool IsRaw(Sint64*) { return true; }
133               inline bool IsRaw(Real32*) { return true; }
134               inline bool IsRaw(Real64*) { return true; }
135               inline bool IsRaw(Char16*) { return true; }
136               inline bool IsRaw(String*) { return false; }
137               inline bool IsRaw(CIMDateTime*) { return false; }
138               inline bool IsRaw(CIMObjectPath*) { return false; }
139               inline bool IsRaw(CIMObject*) { return false; }
140 a.dunfey 1.9  inline bool IsRaw(CIMInstance*) { return false; }
141 mike     1.6  
142               template<class T>
143               struct CIMValueType
144               {
145               public:
146               
147                   static T* ptr(const CIMValueRep* rep)
148                   {
149 kumpf    1.11         return (T*)(&rep->u);
150 mike     1.6      }
151               
152                   static T& ref(const CIMValueRep* rep)
153 schuur   1.1      {
154 kumpf    1.11         return *((T*)((void*)&rep->u));
155 schuur   1.1      }
156               
157 mike     1.6      static Array<T>* aptr(const CIMValueRep* rep)
158 schuur   1.1      {
159 kumpf    1.11         return (Array<T>*)(&rep->u);
160 schuur   1.1      }
161               
162 mike     1.6      static Array<T>& aref(const CIMValueRep* rep)
163                   {
164 kumpf    1.11         return *((Array<T>*)((void*)&rep->u));
165 mike     1.6      }
166 mike     1.5  
167 mike     1.6      static void defaultConstruct(CIMValueRep* rep)
168 mike     1.5      {
169 kumpf    1.11         if (IsRaw((T*)0))
170                           rep->u._uint64Value = (Uint64)0;
171                       else
172                           new((T*)((void*)&rep->u)) T();
173 mike     1.5      }
174               
175 mike     1.6      static void copyConstruct(CIMValueRep* rep, const T& x)
176 mike     1.5      {
177 kumpf    1.11         new((T*)((void*)&rep->u)) T(x);
178 mike     1.6      }
179               
180                   static void copyConstructArray(CIMValueRep* rep, const Array<T>& x)
181                   {
182 kumpf    1.11         new((Array<T>*)((void*)&rep->u)) Array<T>(x);
183 mike     1.6      }
184               
185                   static void constructArrayWithSize(CIMValueRep* rep, Uint32 arraySize)
186                   {
187 kumpf    1.11         new((Array<T>*)((void*)&rep->u)) Array<T>(arraySize);
188 mike     1.6      }
189               
190                   static void destruct(CIMValueRep* rep)
191                   {
192 kumpf    1.11         ((T*)((void*)&rep->u))->~T();
193 mike     1.6      }
194               
195                   static void destructArray(CIMValueRep* rep)
196                   {
197 kumpf    1.11         ((Array<T>*)((void*)&rep->u))->~Array<T>();
198 mike     1.6      }
199               
200                   static void setNull(
201 kumpf    1.11         CIMValueRep* rep, CIMType type_, bool isArray_, Uint32 arraySize_)
202 mike     1.6      {
203 kumpf    1.11         rep->type = type_;
204                       rep->isArray = isArray_;
205                       rep->isNull = true;
206               
207                       if (isArray_)
208                           constructArrayWithSize(rep, arraySize_);
209                       else
210                           defaultConstruct(rep);
211 mike     1.6      }
212               
213                   static void set(CIMValueRep* rep, const T& x)
214                   {
215 kumpf    1.11         rep->type = TypeOf((T*)0);
216                       rep->isArray = false;
217                       rep->isNull = false;
218                       copyConstruct(rep, x);
219 mike     1.6      }
220               
221                   static void setArray(CIMValueRep* rep, const Array<T>& x)
222                   {
223 kumpf    1.11         rep->type = TypeOf((T*)0);
224                       rep->isArray = true;
225                       rep->isNull = false;
226                       copyConstructArray(rep, x);
227 mike     1.6      }
228               
229                   static Uint32 arraySize(CIMValueRep* rep)
230                   {
231 kumpf    1.11         return aref(rep).size();
232 mike     1.6      }
233               
234                   static bool equal(const CIMValueRep* r1, const CIMValueRep* r2)
235                   {
236 kumpf    1.11         return ref(r1) == ref(r2);
237 mike     1.6      }
238               
239                   static bool equalArray(const CIMValueRep* r1, const CIMValueRep* r2)
240                   {
241 kumpf    1.11         return aref(r1) == aref(r2);
242 mike     1.5      }
243 schuur   1.1  };
244               
245               PEGASUS_NAMESPACE_END
246               
247               #endif /* Pegasus_ValueRep_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2