//%LICENSE//////////////////////////////////////////////////////////////// // // Licensed to The Open Group (TOG) under one or more contributor license // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with // this work for additional information regarding copyright ownership. // Each contributor licenses this file to you under the OpenPegasus Open // Source License; you may not use this file except in compliance with the // License. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ////////////////////////////////////////////////////////////////////////// // //%///////////////////////////////////////////////////////////////////////////// #include #include #include #include "CIMValue.h" #include "CIMInstance.h" #include "Union.h" #include "XmlWriter.h" #include "CIMValueRep.h" #include "Config.h" #include "CIMType.h" #include "String.h" #include "CIMDateTime.h" #include "CIMObjectPath.h" #include "CIMObject.h" #include "Array.h" #include PEGASUS_NAMESPACE_BEGIN #define PEGASUS_ARRAY_T CIMValue # include "ArrayImpl.h" #undef PEGASUS_ARRAY_T // ATTN: By getting a CIMObject from a CIMValue, the client of CIMValue can // modify the internals of that CIMObject and thus change what CIMValue // itself refers to. There are two solutions: clone() at ever juncture or // force CIMValue to make its own unique copy when the client calls get() // to get a CIMObject. //============================================================================== // // CIMValueRep // //============================================================================== CIMValueRep CIMValueRep::_emptyRep((int*)0); void CIMValueRep::release() { if (isArray) { switch (type) { case CIMTYPE_BOOLEAN: CIMValueType::destructArray(this); break; case CIMTYPE_UINT8: CIMValueType::destructArray(this); break; case CIMTYPE_SINT8: CIMValueType::destructArray(this); break; case CIMTYPE_UINT16: CIMValueType::destructArray(this); break; case CIMTYPE_SINT16: CIMValueType::destructArray(this); break; case CIMTYPE_UINT32: CIMValueType::destructArray(this); break; case CIMTYPE_SINT32: CIMValueType::destructArray(this); break; case CIMTYPE_UINT64: CIMValueType::destructArray(this); break; case CIMTYPE_SINT64: CIMValueType::destructArray(this); break; case CIMTYPE_REAL32: CIMValueType::destructArray(this); break; case CIMTYPE_REAL64: CIMValueType::destructArray(this); break; case CIMTYPE_CHAR16: CIMValueType::destructArray(this); break; case CIMTYPE_STRING: CIMValueType::destructArray(this); break; case CIMTYPE_DATETIME: CIMValueType::destructArray(this); break; case CIMTYPE_REFERENCE: CIMValueType::destructArray(this); break; case CIMTYPE_OBJECT: CIMValueType::destructArray(this); break; case CIMTYPE_INSTANCE: CIMValueType::destructArray(this); break; } } else { switch (type) { case CIMTYPE_BOOLEAN: case CIMTYPE_UINT8: case CIMTYPE_SINT8: case CIMTYPE_UINT16: case CIMTYPE_SINT16: case CIMTYPE_UINT32: case CIMTYPE_SINT32: case CIMTYPE_UINT64: case CIMTYPE_SINT64: case CIMTYPE_REAL32: case CIMTYPE_REAL64: case CIMTYPE_CHAR16: break; case CIMTYPE_STRING: CIMValueType::destruct(this); break; case CIMTYPE_DATETIME: CIMValueType::destruct(this); break; case CIMTYPE_REFERENCE: CIMValueType::destruct(this); break; case CIMTYPE_OBJECT: CIMValueType::destruct(this); break; case CIMTYPE_INSTANCE: CIMValueType::destruct(this); break; } } } //============================================================================== // // CIMValue // //============================================================================== static inline void _release(CIMValueRep*& rep) { if (rep->refs.get() == 1) rep->release(); else { CIMValueRep::unref(rep); rep = new CIMValueRep; } } CIMValue::CIMValue(CIMType type, Boolean isArray, Uint32 arraySize) { _rep = new CIMValueRep; switch (type) { case CIMTYPE_BOOLEAN: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_UINT8: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_SINT8: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_UINT16: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_SINT16: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_UINT32: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_SINT32: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_UINT64: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_SINT64: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_REAL32: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_REAL64: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_CHAR16: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_STRING: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_DATETIME: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_REFERENCE: CIMValueType::setNull(_rep, type, isArray,arraySize); break; case CIMTYPE_OBJECT: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_INSTANCE: CIMValueType::setNull(_rep, type, isArray, arraySize); break; default: PEGASUS_UNREACHABLE(PEGASUS_ASSERT(0);) } } CIMValue::CIMValue(Boolean x) { _rep = new CIMValueRep; CIMValueType::set(_rep, x); } CIMValue::CIMValue(Uint8 x) { _rep = new CIMValueRep; CIMValueType::set(_rep, x); } CIMValue::CIMValue(Sint8 x) { _rep = new CIMValueRep; CIMValueType::set(_rep, x); } CIMValue::CIMValue(Uint16 x) { _rep = new CIMValueRep; CIMValueType::set(_rep, x); } CIMValue::CIMValue(Sint16 x) { _rep = new CIMValueRep; CIMValueType::set(_rep, x); } CIMValue::CIMValue(Uint32 x) { _rep = new CIMValueRep; CIMValueType::set(_rep, x); } CIMValue::CIMValue(Sint32 x) { _rep = new CIMValueRep; CIMValueType::set(_rep, x); } CIMValue::CIMValue(Uint64 x) { _rep = new CIMValueRep; CIMValueType::set(_rep, x); } CIMValue::CIMValue(Sint64 x) { _rep = new CIMValueRep; CIMValueType::set(_rep, x); } CIMValue::CIMValue(Real32 x) { _rep = new CIMValueRep; CIMValueType::set(_rep, x); } CIMValue::CIMValue(Real64 x) { _rep = new CIMValueRep; CIMValueType::set(_rep, x); } CIMValue::CIMValue(const Char16& x) { _rep = new CIMValueRep; CIMValueType::set(_rep, x); } CIMValue::CIMValue(const String& x) { _rep = new CIMValueRep; CIMValueType::set(_rep, x); } CIMValue::CIMValue(const CIMDateTime& x) { _rep = new CIMValueRep; CIMValueType::set(_rep, x); } CIMValue::CIMValue(const CIMObjectPath& x) { _rep = new CIMValueRep; CIMValueType::set(_rep, x); } CIMValue::CIMValue(const CIMObject& x) { if (x.isUninitialized()) { // Bug 3373, throw exception if uninitialized object is passed to set(). throw UninitializedObjectException(); } _rep = new CIMValueRep; CIMValueType::set(_rep, x.clone()); } CIMValue::CIMValue(const CIMInstance& x) { if (x.isUninitialized()) { // Bug 3373, throw exception if uninitialized object is passed to set(). throw UninitializedObjectException(); } _rep = new CIMValueRep; CIMValueType::set(_rep, x.clone()); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; CIMValueType::setArray(_rep, x); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; CIMValueType::setArray(_rep, x); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; CIMValueType::setArray(_rep, x); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; CIMValueType::setArray(_rep, x); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; CIMValueType::setArray(_rep, x); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; CIMValueType::setArray(_rep, x); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; CIMValueType::setArray(_rep, x); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; CIMValueType::setArray(_rep, x); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; CIMValueType::setArray(_rep, x); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; CIMValueType::setArray(_rep, x); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; CIMValueType::setArray(_rep, x); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; CIMValueType::setArray(_rep, x); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; CIMValueType::setArray(_rep, x); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; CIMValueType::setArray(_rep, x); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; CIMValueType::setArray(_rep, x); } CIMValue::CIMValue(const Array& x) { Array tmp; for (Uint32 i = 0, n = x.size(); i < n; i++) { if (x[i].isUninitialized()) { // Bug 3373, throw exception on uninitialized object. _rep = &CIMValueRep::_emptyRep; throw UninitializedObjectException(); } tmp.append(x[i].clone()); } _rep = new CIMValueRep; CIMValueType::setArray(_rep, tmp); } CIMValue::CIMValue(const Array& x) { Array tmp; for (Uint32 i = 0, n = x.size(); i < n; i++) { if (x[i].isUninitialized()) { // Bug 3373, throw exception on uninitialized object. _rep = &CIMValueRep::_emptyRep; throw UninitializedObjectException(); } tmp.append(x[i].clone()); } _rep = new CIMValueRep; CIMValueType::setArray(_rep, tmp); } void CIMValue::clear() { CIMValueRep::unref(_rep); _rep = &CIMValueRep::_emptyRep; } CIMValue& CIMValue::operator=(const CIMValue& x) { if (_rep != x._rep) { CIMValueRep::unref(_rep); CIMValueRep::ref(_rep = x._rep); } return *this; } void CIMValue::assign(const CIMValue& x) { if (_rep != x._rep) { CIMValueRep::unref(_rep); CIMValueRep::ref(_rep = x._rep); } } Boolean CIMValue::typeCompatible(const CIMValue& x) const { return (_rep->type == x._rep->type && _rep->isArray == x._rep->isArray); } Uint32 CIMValue::getArraySize() const { if (!_rep->isArray) return 0; switch (_rep->type) { case CIMTYPE_BOOLEAN: return CIMValueType::arraySize(_rep); case CIMTYPE_UINT8: return CIMValueType::arraySize(_rep); case CIMTYPE_SINT8: return CIMValueType::arraySize(_rep); case CIMTYPE_UINT16: return CIMValueType::arraySize(_rep); case CIMTYPE_SINT16: return CIMValueType::arraySize(_rep); case CIMTYPE_UINT32: return CIMValueType::arraySize(_rep); case CIMTYPE_SINT32: return CIMValueType::arraySize(_rep); case CIMTYPE_UINT64: return CIMValueType::arraySize(_rep); case CIMTYPE_SINT64: return CIMValueType::arraySize(_rep); case CIMTYPE_REAL32: return CIMValueType::arraySize(_rep); case CIMTYPE_REAL64: return CIMValueType::arraySize(_rep); case CIMTYPE_CHAR16: return CIMValueType::arraySize(_rep); case CIMTYPE_STRING: return CIMValueType::arraySize(_rep); case CIMTYPE_DATETIME: return CIMValueType::arraySize(_rep); case CIMTYPE_REFERENCE: return CIMValueType::arraySize(_rep); case CIMTYPE_OBJECT: return CIMValueType::arraySize(_rep); case CIMTYPE_INSTANCE: return CIMValueType::arraySize(_rep); default: PEGASUS_UNREACHABLE(PEGASUS_ASSERT(0);) } return 0; } void CIMValue::setNullValue(CIMType type, Boolean isArray, Uint32 arraySize) { // // Release any memory: // _release(_rep); // // Set the null value: // switch (type) { case CIMTYPE_BOOLEAN: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_UINT8: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_SINT8: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_UINT16: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_SINT16: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_UINT32: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_SINT32: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_UINT64: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_SINT64: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_REAL32: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_REAL64: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_CHAR16: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_STRING: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_DATETIME: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_REFERENCE: CIMValueType::setNull(_rep, type, isArray,arraySize); break; case CIMTYPE_OBJECT: CIMValueType::setNull(_rep, type, isArray, arraySize); break; case CIMTYPE_INSTANCE: CIMValueType::setNull(_rep, type, isArray, arraySize); break; default: PEGASUS_UNREACHABLE(PEGASUS_ASSERT(0);) } } void CIMValue::set(Boolean x) { _release(_rep); CIMValueType::set(_rep, x); } void CIMValue::set(Uint8 x) { _release(_rep); CIMValueType::set(_rep, x); } void CIMValue::set(Sint8 x) { _release(_rep); CIMValueType::set(_rep, x); } void CIMValue::set(Uint16 x) { _release(_rep); CIMValueType::set(_rep, x); } void CIMValue::set(Sint16 x) { _release(_rep); CIMValueType::set(_rep, x); } void CIMValue::set(Uint32 x) { _release(_rep); CIMValueType::set(_rep, x); } void CIMValue::set(Sint32 x) { _release(_rep); CIMValueType::set(_rep, x); } void CIMValue::set(Uint64 x) { _release(_rep); CIMValueType::set(_rep, x); } void CIMValue::set(Sint64 x) { _release(_rep); CIMValueType::set(_rep, x); } void CIMValue::set(Real32 x) { _release(_rep); CIMValueType::set(_rep, x); } void CIMValue::set(Real64 x) { _release(_rep); CIMValueType::set(_rep, x); } void CIMValue::set(const Char16& x) { _release(_rep); CIMValueType::set(_rep, x); } void CIMValue::set(const String& x) { _release(_rep); CIMValueType::set(_rep, x); } void CIMValue::set(const CIMDateTime& x) { _release(_rep); CIMValueType::set(_rep, x); } void CIMValue::set(const CIMObjectPath& x) { _release(_rep); CIMValueType::set(_rep, x); } void CIMValue::set(const CIMObject& x) { if (x.isUninitialized()) { // Bug 3373, throw exception on uninitialized object. throw UninitializedObjectException(); } _release(_rep); CIMValueType::set(_rep, x.clone()); } void CIMValue::set(const CIMInstance& x) { if (x.isUninitialized()) { // Bug 3373, throw exception on uninitialized object. throw UninitializedObjectException(); } _release(_rep); CIMValueType::set(_rep, x.clone()); } void CIMValue::set(const Array& x) { _release(_rep); CIMValueType::setArray(_rep, x); } void CIMValue::set(const Array& x) { _release(_rep); CIMValueType::setArray(_rep, x); } void CIMValue::set(const Array& x) { _release(_rep); CIMValueType::setArray(_rep, x); } void CIMValue::set(const Array& x) { _release(_rep); CIMValueType::setArray(_rep, x); } void CIMValue::set(const Array& x) { _release(_rep); CIMValueType::setArray(_rep, x); } void CIMValue::set(const Array& x) { _release(_rep); CIMValueType::setArray(_rep, x); } void CIMValue::set(const Array& x) { _release(_rep); CIMValueType::setArray(_rep, x); } void CIMValue::set(const Array& x) { _release(_rep); CIMValueType::setArray(_rep, x); } void CIMValue::set(const Array& x) { _release(_rep); CIMValueType::setArray(_rep, x); } void CIMValue::set(const Array& x) { _release(_rep); CIMValueType::setArray(_rep, x); } void CIMValue::set(const Array& x) { _release(_rep); CIMValueType::setArray(_rep, x); } void CIMValue::set(const Array& x) { _release(_rep); CIMValueType::setArray(_rep, x); } void CIMValue::set(const Array& x) { _release(_rep); CIMValueType::setArray(_rep, x); } void CIMValue::set(const Array& x) { _release(_rep); CIMValueType::setArray(_rep, x); } void CIMValue::set(const Array& x) { _release(_rep); CIMValueType::setArray(_rep, x); } void CIMValue::set(const Array& a) { Array tmp; for (Uint32 i = 0, n = a.size(); i < n; i++) { if (a[i].isUninitialized()) { // Bug 3373, throw exception on uninitialized object. throw UninitializedObjectException(); } tmp.append(a[i].clone()); } _release(_rep); CIMValueType::setArray(_rep, tmp); } void CIMValue::set(const Array& a) { Array tmp; for (Uint32 i = 0, n = a.size(); i < n; i++) { if (a[i].isUninitialized()) { // Bug 3373, throw exception on uninitialized object. throw UninitializedObjectException(); } tmp.append(a[i].clone()); } _release(_rep); CIMValueType::setArray(_rep, tmp); } void CIMValue::get(Boolean& x) const { if (_rep->type != CIMTYPE_BOOLEAN || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::ref(_rep); } void CIMValue::get(Uint8& x) const { if (_rep->type != CIMTYPE_UINT8 || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::ref(_rep); } void CIMValue::get(Sint8& x) const { if (_rep->type != CIMTYPE_SINT8 || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::ref(_rep); } void CIMValue::get(Uint16& x) const { if (_rep->type != CIMTYPE_UINT16 || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::ref(_rep); } void CIMValue::get(Sint16& x) const { if (_rep->type != CIMTYPE_SINT16 || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::ref(_rep); } void CIMValue::get(Uint32& x) const { if (_rep->type != CIMTYPE_UINT32 || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::ref(_rep); } void CIMValue::get(Sint32& x) const { if (_rep->type != CIMTYPE_SINT32 || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::ref(_rep); } void CIMValue::get(Uint64& x) const { if (_rep->type != CIMTYPE_UINT64 || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::ref(_rep); } void CIMValue::get(Sint64& x) const { if (_rep->type != CIMTYPE_SINT64 || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::ref(_rep); } void CIMValue::get(Real32& x) const { if (_rep->type != CIMTYPE_REAL32 || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::ref(_rep); } void CIMValue::get(Real64& x) const { if (_rep->type != CIMTYPE_REAL64 || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::ref(_rep); } void CIMValue::get(Char16& x) const { if (_rep->type != CIMTYPE_CHAR16 || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::ref(_rep); } void CIMValue::get(String& x) const { if (_rep->type != CIMTYPE_STRING || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::ref(_rep); } void CIMValue::get(CIMDateTime& x) const { if (_rep->type != CIMTYPE_DATETIME || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::ref(_rep); } void CIMValue::get(CIMObjectPath& x) const { if (_rep->type != CIMTYPE_REFERENCE || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::ref(_rep); } void CIMValue::get(CIMObject& x) const { if (_rep->type != CIMTYPE_OBJECT || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) // We have to clone our own unique copy since we are about to // return an object to the caller that he can modify; thereby, // changing the one we refer to as well. x = CIMValueType::ref(_rep).clone(); } void CIMValue::get(CIMInstance& x) const { if (_rep->type != CIMTYPE_INSTANCE || _rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) { // We have to clone our own unique copy since we are about to // return an object to the caller that he can modify; thereby, // changing the one we refer to as well. x = CIMValueType::ref(_rep).clone(); } } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_BOOLEAN || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::aref(_rep); } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_UINT8 || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::aref(_rep); } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_SINT8 || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::aref(_rep); } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_UINT16 || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::aref(_rep); } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_SINT16 || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::aref(_rep); } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_UINT32 || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::aref(_rep); } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_SINT32 || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::aref(_rep); } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_UINT64 || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::aref(_rep); } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_SINT64 || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::aref(_rep); } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_REAL32 || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::aref(_rep); } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_REAL64 || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::aref(_rep); } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_CHAR16 || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::aref(_rep); } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_STRING || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::aref(_rep); } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_DATETIME || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::aref(_rep); } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_REFERENCE || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) x = CIMValueType::aref(_rep); } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_OBJECT || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) { x.clear(); // We have to clone our own unique copy since we are about to // return an object to the caller that he can modify; thereby, // changing the one we refer to as well. for (Uint32 i = 0, n = CIMValueType::arraySize(_rep); i < n; i++) { x.append(CIMValueType::aref(_rep)[i].clone()); } } } void CIMValue::get(Array& x) const { if (_rep->type != CIMTYPE_INSTANCE || !_rep->isArray) throw TypeMismatchException(); if (!_rep->isNull) { x.clear(); // We have to clone our own unique copy since we are about to // return an object to the caller that he can modify; thereby, // changing the one we refer to as well. for (Uint32 i = 0, n = CIMValueType::arraySize(_rep); i < n; i++) { x.append(CIMValueType::aref(_rep)[i].clone()); } } } Boolean CIMValue::equal(const CIMValue& x) const { if (!typeCompatible(x)) return false; if (_rep->isNull != x._rep->isNull) return false; if (_rep->isNull) return true; if (_rep->isArray) { switch (_rep->type) { case CIMTYPE_BOOLEAN: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_UINT8: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_SINT8: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_UINT16: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_SINT16: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_UINT32: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_SINT32: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_UINT64: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_SINT64: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_REAL32: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_REAL64: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_CHAR16: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_STRING: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_DATETIME: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_REFERENCE: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_OBJECT: return CIMValueType::equalArray(_rep, x._rep); case CIMTYPE_INSTANCE: return CIMValueType::equalArray(_rep, x._rep); default: PEGASUS_UNREACHABLE(PEGASUS_ASSERT(0);) } } else { switch (_rep->type) { case CIMTYPE_BOOLEAN: return CIMValueType::equal(_rep, x._rep); case CIMTYPE_UINT8: return CIMValueType::equal(_rep, x._rep); case CIMTYPE_SINT8: return CIMValueType::equal(_rep, x._rep); case CIMTYPE_UINT16: return CIMValueType::equal(_rep, x._rep); case CIMTYPE_SINT16: return CIMValueType::equal(_rep, x._rep); case CIMTYPE_UINT32: return CIMValueType::equal(_rep, x._rep); case CIMTYPE_SINT32: return CIMValueType::equal(_rep, x._rep); case CIMTYPE_UINT64: return CIMValueType::equal(_rep, x._rep); case CIMTYPE_SINT64: return CIMValueType::equal(_rep, x._rep); case CIMTYPE_REAL32: return CIMValueType::equal(_rep, x._rep); case CIMTYPE_REAL64: return CIMValueType::equal(_rep, x._rep); case CIMTYPE_CHAR16: return CIMValueType::equal(_rep, x._rep); case CIMTYPE_STRING: return CIMValueType::equal(_rep, x._rep); case CIMTYPE_DATETIME: return CIMValueType::equal(_rep, x._rep); case CIMTYPE_REFERENCE: return CIMValueType::equal(_rep, x._rep); case CIMTYPE_OBJECT: return CIMValueType::ref(_rep).identical( CIMValueType::ref(x._rep)); case CIMTYPE_INSTANCE: return CIMValueType::ref(_rep).identical( CIMValueType::ref(x._rep)); default: PEGASUS_UNREACHABLE(PEGASUS_ASSERT(0);) } } return false; } String CIMValue::toString() const { Buffer out; // ATTN: Not sure what we should do with getstring for Null CIMValues // Choice return empty string or exception out. if (_rep->isNull) return String(); if (_rep->isArray) { switch (_rep->type) { case CIMTYPE_BOOLEAN: { const Array& a = CIMValueType::aref(_rep); Uint32 size = a.size(); for (Uint32 i = 0; i < size; i++) { _toString(out, a[i]); out.append(' '); } break; } case CIMTYPE_UINT8: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } case CIMTYPE_SINT8: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } case CIMTYPE_UINT16: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } case CIMTYPE_SINT16: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } case CIMTYPE_UINT32: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } case CIMTYPE_SINT32: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } case CIMTYPE_UINT64: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } case CIMTYPE_SINT64: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } case CIMTYPE_REAL32: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } case CIMTYPE_REAL64: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } case CIMTYPE_CHAR16: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } case CIMTYPE_STRING: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } case CIMTYPE_DATETIME: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } case CIMTYPE_REFERENCE: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } case CIMTYPE_OBJECT: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } case CIMTYPE_INSTANCE: { const Array& a = CIMValueType::aref(_rep); _toString(out, a.getData(), a.size()); break; } default: PEGASUS_UNREACHABLE(PEGASUS_ASSERT(0);) } } else { switch (_rep->type) { case CIMTYPE_BOOLEAN: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_UINT8: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_SINT8: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_UINT16: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_SINT16: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_UINT32: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_SINT32: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_UINT64: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_SINT64: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_REAL32: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_REAL64: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_CHAR16: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_STRING: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_DATETIME: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_REFERENCE: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_OBJECT: _toString(out, CIMValueType::ref(_rep)); break; case CIMTYPE_INSTANCE: _toString(out, CIMValueType::ref(_rep)); break; default: PEGASUS_UNREACHABLE(PEGASUS_ASSERT(0);) } } return out.getData(); } #ifdef PEGASUS_USE_DEPRECATED_INTERFACES CIMValue::CIMValue(char x) { _rep = new CIMValueRep; CIMValueType::set(_rep, (Sint8)x); } CIMValue::CIMValue(const Array& x) { _rep = new CIMValueRep; Array tmp((Sint8*)x.getData(), x.size()); CIMValueType::setArray(_rep, tmp); } void CIMValue::set(char x) { set(static_cast(x)); } void CIMValue::set(const Array& x) { set(*reinterpret_cast*>(&x)); } void CIMValue::get(char& x) const { get(*reinterpret_cast(&x)); } void CIMValue::get(Array& x) const { get(*reinterpret_cast*>(&x)); } #endif /* PEGASUS_USE_DEPRECATED_INTERFACES */ void CIMValue::_get(const String*& data, Uint32& size) const { const Array& a = CIMValueType::aref(_rep); data = a.getData(); size = a.size(); } Boolean operator==(const CIMValue& x, const CIMValue& y) { return x.equal(y); } Boolean operator!=(const CIMValue& x, const CIMValue& y) { return !x.equal(y); } PEGASUS_NAMESPACE_END