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

  1 mike  1.11 //%/////////////////////////////////////////////////////////////////////////////
  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.11 //
 23            // Author: Mike Brasher (mbrasher@bmc.com)
 24            //
 25 karl  1.13 // Modified By: Karl schopmeyer (k.schopmeyer@opengroup.org)
 26 kumpf 1.14 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 27 mike  1.11 //
 28            //%/////////////////////////////////////////////////////////////////////////////
 29            
 30            #ifndef Pegasus_Value_h
 31            #define Pegasus_Value_h
 32            
 33            #include <Pegasus/Common/String.h>
 34            #include <Pegasus/Common/Config.h>
 35            #include <Pegasus/Common/CIMType.h>
 36            #include <Pegasus/Common/CIMDateTime.h>
 37            #include <Pegasus/Common/Union.h>
 38            #include <Pegasus/Common/Array.h>
 39            
 40            PEGASUS_NAMESPACE_BEGIN
 41            
 42            /**
 43                The CIMValue class represents a value of any of the CIM data types
 44                (see CIMType.h for a list of valid CIM data types). This class
 45                encapsulates a union which holds the current value. The class also
 46                has a type field indicating the type of that value.
 47            */
 48 mike  1.11 class PEGASUS_COMMON_LINKAGE CIMValue
 49            {
 50            public:
 51 karl  1.15     /**	Constructor with no value. This constructor creates an NULL CIMValue
 52                    object set to null and with type CIMType:none and !arraytype.
 53                */
 54 mike  1.11     CIMValue();
 55            
 56 karl  1.15     /** Constructor with only the Type. This constructor creates a NULL CIMValue
 57                    object with the array indicator set as shown and with the
 58                */
 59                CIMValue(CIMType type, Boolean isArray, Uint32 arraySize = 0);
 60            
 61                /**	Constructor with the Value constructor and a value.  This constructs a
 62                    CIMValue object with the type defined by the value constructor and the value
 63                    installed
 64                    <pre>
 65                    ATTN: Add example
 66                    </pre> 
 67                */
 68 mike  1.11     CIMValue(Boolean x) { _init(); set(x); }
 69            
 70                ///	Constructor
 71                CIMValue(Uint8 x) { _init(); set(x); }
 72            
 73                ///	Constructor
 74                CIMValue(Sint8 x) { _init(); set(x); }
 75            
 76                ///	Constructor
 77                CIMValue(Uint16 x) { _init(); set(x); }
 78            
 79                ///	Constructor
 80                CIMValue(Sint16 x) { _init(); set(x); }
 81            
 82                ///	Constructor
 83                CIMValue(Uint32 x) { _init(); set(x); }
 84            
 85                ///	Constructor
 86                CIMValue(Sint32 x) { _init(); set(x); }
 87            
 88                ///	Constructor
 89 mike  1.11     CIMValue(Uint64 x) { _init(); set(x); }
 90            
 91                ///	Constructor
 92                CIMValue(Sint64 x) { _init(); set(x); }
 93            
 94                ///	Constructor
 95                CIMValue(Real32 x) { _init(); set(x); }
 96            
 97                ///	Constructor
 98                CIMValue(Real64 x) { _init(); set(x); }
 99            
100                ///	Constructor
101                CIMValue(const Char16& x) { _init(); set(x); }
102            
103                ///	Constructor
104                CIMValue(const String& x) { _init(); set(x); }
105            
106                ///	Constructor
107                CIMValue(const char* x) { _init(); set(x); }
108            
109                ///	Constructor
110 mike  1.11     CIMValue(const CIMDateTime& x) { _init(); set(x); }
111            
112                ///	Constructor
113                CIMValue(const CIMReference& x) { _init(); set(x); }
114            
115                ///	Constructor
116                CIMValue(const Array<Boolean>& x) { _init(); set(x); }
117            
118                ///	Constructor
119                CIMValue(const Array<Uint8>& x) { _init(); set(x); }
120            
121                ///	Constructor
122                CIMValue(const Array<Sint8>& x) { _init(); set(x); }
123            
124                ///	Constructor
125                CIMValue(const Array<Uint16>& x) { _init(); set(x); }
126            
127                ///	Constructor
128                CIMValue(const Array<Sint16>& x) { _init(); set(x); }
129            
130                ///	Constructor
131 mike  1.11     CIMValue(const Array<Uint32>& x) { _init(); set(x); }
132            
133                ///	Constructor
134                CIMValue(const Array<Sint32>& x) { _init(); set(x); }
135            
136                ///	Constructor
137                CIMValue(const Array<Uint64>& x) { _init(); set(x); }
138            
139                ///	Constructor
140                CIMValue(const Array<Sint64>& x) { _init(); set(x); }
141            
142                ///	Constructor
143                CIMValue(const Array<Real32>& x) { _init(); set(x); }
144            
145                ///	Constructor
146                CIMValue(const Array<Real64>& x) { _init(); set(x); }
147            
148                ///	Constructor
149                CIMValue(const Array<Char16>& x) { _init(); set(x); }
150            
151                ///	Constructor
152 mike  1.11     CIMValue(const Array<String>& x) { _init(); set(x); }
153            
154                ///	Constructor
155                CIMValue(const Array<CIMDateTime>& x) { _init(); set(x); }
156            
157                ///	Constructor
158 kumpf 1.14     CIMValue(const Array<CIMReference>& x) { _init(); set(x); }
159            
160                ///	Constructor
161 mike  1.11     CIMValue(const CIMValue& x);
162            
163 kumpf 1.14     ///	Destructor
164 mike  1.11     ~CIMValue();
165            
166                /// Operator =
167                CIMValue& operator=(const CIMValue& x) 
168                { 
169            	assign(x); return *this; 
170                }
171            
172 karl  1.13     /** assign - The method to assign one CIMValue object to another CIMValue
173                object.
174                
175                */
176 mike  1.11     void assign(const CIMValue& x);
177            
178 karl  1.13     /** clear - Clears the attributes and value of the CIMValue object.
179                <pre>
180                ATTNDOC:
181                </pre>
182                */
183 mike  1.11     void clear();
184            
185 karl  1.13     /** typeCompatible - Compares the types of two CIMvalues. This
186                    compares the type field and the array indicators.
187            	@return true if both are of the same type and both are either arrays
188                    or not. Else returns false.
189                    <pre>
190                        CIMValue a(Boolean(true);
191                        CIMValue b = a;
192                        if b.typeCompatible(a)
193                            ...
194                    </pre>
195 mike  1.11     */
196                Boolean typeCompatible(const CIMValue& x) const
197                {
198            	return _type == x._type && _isArray == x._isArray;
199                }
200            
201 karl  1.13     /** isArray - Determines if the value is an array
202 mike  1.11 	@return TRUE if the value is an array
203                */
204                Boolean isArray() const { return _isArray; }
205            
206 karl  1.13     /** Returns whether the CIMvalue object is Null. 
207 mike  1.12 	Null is the specific condition where no value has
208            	yet been set into the value.
209            	If a CIMValue object is Null, any get on that object
210            	will create an exception.
211            	@return Returns True if the CIMValue object is Null
212                */
213                Boolean isNull() const { return _isNull; }
214            
215 karl  1.13     /** getArraySize = Returns the size of an Array CIMValue
216 mike  1.11 	@return The number of entries in the array
217                */
218                Uint32 getArraySize() const;
219            
220 karl  1.13     /** getType - Gets the CIMType attribute for the CIMValue.
221                    The CIMType is defined in ATTN:
222                    @return Returns the CIMType value
223                */
224 mike  1.11     CIMType getType() const 
225                { 
226            	return CIMType(_type); 
227                }
228            
229 karl  1.13     /** setNullvalue - Sets the CIMType, the Array indicator and if it is
230                    the arraytype, the Arraysize of a CIMValue and sets the isNull
231                    Attribute.  This function is used to set up CIMValues an NULL but
232                    with valid CIMType and array characteristics (ex. when update from
233                    XML)
234                    @param type - The CIMType for this CIMValue
235                    @paramisArray - Boolean indicating whether this is an array CIMValue
236                    @param arraySize (optional)  Uint32parameter indicating the array
237                    size
238                    @return void
239 karl  1.15         <pre>
240                        CIMValue value;                   // Create a CIMValue object
241                        value.setNullValue(CIMType::BOOLEAN, false);  // Set it       
242                    </pre>
243 karl  1.13     */
244 mike  1.11     void setNullValue(CIMType type, Boolean isArray, Uint32 arraySize = 0);
245            
246 karl  1.13     /** set - Sets the type, Array attribute and puts the value provided
247                    into the value of the target CIMValue. This function sets the
248 karl  1.15         CIMValue to nonNull also. The result is a complete CIMValue object
249 karl  1.13         All of the CIMTypes defined in ATTN: and the Array types defined in
250                    ATTN: may be set.
251                    @param x Typed value (ex. Boolean(true).
252                    @return void
253                    <pre>
254                        CIMValue x;
255                        x.set(Uint16(9));
256                    </pre>
257                */    
258 mike  1.11     void set(Boolean x);
259            
260 karl  1.13     /// Set
261 mike  1.11     void set(Uint8 x);
262 karl  1.13     ///
263 mike  1.11     void set(Sint8 x);
264 karl  1.13     ///
265 mike  1.11     void set(Uint16 x);
266 karl  1.13     ///
267 mike  1.11     void set(Sint16 x);
268 karl  1.13     ///
269 mike  1.11     void set(Uint32 x);
270 karl  1.13     ///
271 mike  1.11     void set(Sint32 x);
272 karl  1.13     ///
273 mike  1.11     void set(Uint64 x);
274 karl  1.13     ///
275 mike  1.11     void set(Sint64 x);
276 karl  1.13     ///
277 mike  1.11     void set(Real32 x);
278 karl  1.13     ///
279 mike  1.11     void set(Real64 x);
280 karl  1.13     ///
281 mike  1.11     void set(const Char16& x);
282 karl  1.13     ///
283 mike  1.11     void set(const String& x);
284 karl  1.13     ///
285 mike  1.11     void set(const char* x);
286 karl  1.13     ///
287 mike  1.11     void set(const CIMDateTime& x);
288 karl  1.13     ///
289 mike  1.11     void set(const CIMReference& x);
290 karl  1.13     ///
291 mike  1.11     void set(const Array<Boolean>& x);
292 karl  1.13     ///
293 mike  1.11     void set(const Array<Uint8>& x);
294 karl  1.13     ///
295 mike  1.11     void set(const Array<Sint8>& x);
296 karl  1.13     ///
297 mike  1.11     void set(const Array<Uint16>& x);
298 karl  1.13     ///
299 mike  1.11     void set(const Array<Sint16>& x);
300 karl  1.13     ///
301 mike  1.11     void set(const Array<Uint32>& x);
302 karl  1.13     ///
303 mike  1.11     void set(const Array<Sint32>& x);
304 karl  1.13     ///
305 mike  1.11     void set(const Array<Uint64>& x);
306 karl  1.13     ///
307 mike  1.11     void set(const Array<Sint64>& x);
308 karl  1.13     ///
309 mike  1.11     void set(const Array<Real32>& x);
310 karl  1.13     ///
311 mike  1.11     void set(const Array<Real64>& x);
312 karl  1.13     ///
313 mike  1.11     void set(const Array<Char16>& x);
314 karl  1.13     ///
315 mike  1.11     void set(const Array<String>& x);
316 karl  1.13     ///
317 mike  1.11     void set(const Array<CIMDateTime>& x);
318 kumpf 1.14     ///
319                void set(const Array<CIMReference>& x);
320 mike  1.11 
321 karl  1.13     /** get - Gets the value of a CIMValue
322 karl  1.17         @param Variable in which we return the value:
323                    @return void
324            		<pre>
325            		Uint32 v;
326            		CIMValue value(CIMValue::UINT32, UINT32(99));
327            		value.get(v);
328            		</pre>
329 karl  1.13     */
330 mike  1.11     void get(Boolean& x) const;
331 karl  1.13     ///
332 mike  1.11     void get(Uint8& x) const;
333 karl  1.13     ///
334 mike  1.11     void get(Sint8& x) const;
335 karl  1.13     ///
336 mike  1.11     void get(Uint16& x) const;
337 karl  1.13     ///
338 mike  1.11     void get(Sint16& x) const;
339 karl  1.13     ///
340 mike  1.11     void get(Uint32& x) const;
341 karl  1.13     ///
342 mike  1.11     void get(Sint32& x) const;
343 karl  1.13     ///
344 mike  1.11     void get(Uint64& x) const;
345 karl  1.13     ///
346 mike  1.11     void get(Sint64& x) const;
347 karl  1.13     ///
348 mike  1.11     void get(Real32& x) const;
349 karl  1.13     ///
350 mike  1.11     void get(Real64& x) const;
351 karl  1.13     ///
352 mike  1.11     void get(Char16& x) const;
353 karl  1.13     ///
354 mike  1.11     void get(String& x) const;
355 karl  1.13     ///
356 mike  1.11     void get(CIMDateTime& x) const;
357 karl  1.13     ///
358 mike  1.11     void get(CIMReference& x) const;
359 karl  1.13     ///
360 mike  1.11     void get(Array<Boolean>& x) const;
361 karl  1.13     ///
362 mike  1.11     void get(Array<Uint8>& x) const;
363 karl  1.13     //////
364 mike  1.11     void get(Array<Sint8>& x) const;
365 karl  1.13     ///
366 mike  1.11     void get(Array<Uint16>& x) const;
367 karl  1.13     ///
368 mike  1.11     void get(Array<Sint16>& x) const;
369 karl  1.13     ///
370 mike  1.11     void get(Array<Uint32>& x) const;
371 karl  1.13     ///
372 mike  1.11     void get(Array<Sint32>& x) const;
373 karl  1.13     ///
374 mike  1.11     void get(Array<Uint64>& x) const;
375 karl  1.13     ///
376 mike  1.11     void get(Array<Sint64>& x) const;
377 karl  1.13     ///
378 mike  1.11     void get(Array<Real32>& x) const;
379 karl  1.13     ///
380 mike  1.11     void get(Array<Real64>& x) const;
381 karl  1.13     ///
382 mike  1.11     void get(Array<Char16>& x) const;
383 karl  1.13     ///
384 mike  1.11     void get(Array<String>& x) const;
385 karl  1.13     ///
386 mike  1.11     void get(Array<CIMDateTime>& x) const; 
387 kumpf 1.14     ///
388                void get(Array<CIMReference>& x) const; 
389 mike  1.11 
390 karl  1.13     /** toXML - Converts a CIMValue object to XML. The XML is appended
391 kumpf 1.14         to the Array provided with the call.  Returns the result as an
392                    XML element wrapped in the <VALUE>, <VALUE.ARRAY>, <VALUE.REFERENCE>,
393                    or <VALUE.REFARRAY> tags. If the CIMValue is Null, no element is
394                    returned.
395 karl  1.16 	@param out Sint8 Array to hold the XML representation
396                    @param forceTag Boolean parameter that if set forces the XML tags to
397                    be output even if the CIMValue is NULL.
398 mike  1.12 	@return Returns the XML representation of the CIMValue
399 karl  1.16 	object in the input parameter out.
400 mike  1.11     */
401 karl  1.16     void toXml(Array<Sint8>& out, Boolean forceTag) const;
402 mike  1.11 
403 karl  1.13     /** toXML - Converts a CIMValue object to XML. There is no input
404                    parameter and the result is returned as a String rather
405                    than appended to an 8-bit array as above.  Returns the
406 kumpf 1.14         element as value wrapped in the <VALUE>, <VALUE.ARRAY>,
407                    <VALUE.REFERENCE>, or <VALUE.REFARRAY> tags. If the
408 karl  1.13         CIMValue is Null, no element is returned.
409 karl  1.16         @param forceTag Boolean parameter that if set forces the XML tags to
410                    be output even if the CIMValue is NULL.
411 mike  1.12 	@return Returns the XML representation of the CIMValue
412            	object in String form.
413                */
414 karl  1.16     String toXml(Boolean forceTag) const;
415 mike  1.12 
416 karl  1.13     /** CIMMethod print - Format and print the Value as XML to std output
417 mike  1.11     	stream
418 karl  1.16         @param forceTag Boolean parameter that if set forces the XML tags to
419                    be output even if the CIMValue is NULL.
420                    @param o Stream to output to. Defaults to cout.
421 mike  1.11 	@return None
422            	<PRE>
423            	Example:
424            	    CIMValue value(Boolean(true));
425 karl  1.16 	    value.print(true);	  // Prints "true"
426            	</PRE>
427 mike  1.11     */
428 karl  1.16     void print(Boolean forceTag, PEGASUS_STD(ostream) &o=PEGASUS_STD(cout)) const;
429 mike  1.11 
430 mike  1.12     /** toMof - Converts a CIMValueObject to Mof.
431            	@out Sint8 Array to hold the Mof representation
432            	@return Returns the Mof representation of the CIMValue
433            	object in the input parameter out. 
434                */
435                void toMof(Array<Sint8>& out) const;
436            
437                /** toString - Converts the CIMvalue to a string.  Should only be
438                        used for output purposes.  To get an actual String value, use
439                        get(String &).
440 mike  1.11 	@return - String output for CIMValue.
441 karl  1.13         @exception - Throws exception CIMValueInvalidType if the CIMValue
442                        has an invalid type. Normally this is a Pegasus internal error.
443 mike  1.11 	<PRE>
444            	Example:
445            	    String test;
446            	    CIMValue value(Boolean(true));
447 mike  1.12 	    test = value.toString();	  // puts "TRUE" into test
448 mike  1.11 	</PRE>
449            	*/
450                String toString() const;
451            
452            private:
453            
454                void _init();
455            
456                CIMType _type;
457                Boolean _isArray;
458 mike  1.12     Boolean _isNull;
459 mike  1.11     Union _u;
460            
461                friend class CIMMethodRep;
462                friend class CIMParameterRep;
463                friend class CIMPropertyRep;
464                friend class CIMQualifierRep;
465                friend class CIMQualifierDeclRep;
466                PEGASUS_COMMON_LINKAGE friend Boolean operator==(
467            	const CIMValue& x, 
468            	const CIMValue& y);
469            };
470 karl  1.17 /** operator == compares two CIMValue objects for equality.
471            	@param x - First CIMvalue to compare
472            	@parm y - Second CIMValue to compare
473            	@return True if they are identical in type, attribute and value.
474            */
475 mike  1.11 PEGASUS_COMMON_LINKAGE Boolean operator==(const CIMValue& x, const CIMValue& y);
476            
477 karl  1.17 /** operator != compares two CIMValue objects for nonequality
478            */
479 mike  1.11 inline Boolean operator!=(const CIMValue& x, const CIMValue& y)
480            {
481                return !operator==(x, y);
482            }
483            
484            #define PEGASUS_ARRAY_T CIMValue
485            # include "ArrayInter.h"
486            #undef PEGASUS_ARRAY_T
487            
488            PEGASUS_NAMESPACE_END
489            
490            #endif /* Pegasus_Value_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2