00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00035 #include "OWBI1_config.h"
00036 #include "OWBI1_CIMParamValue.hpp"
00037 #include "OWBI1_StringBuffer.hpp"
00038 #include "OW_BinarySerialization.hpp"
00039 #include "OW_StrictWeakOrdering.hpp"
00040 #include "OWBI1_COWIntrusiveCountableBase.hpp"
00041 #include "OWBI1_CIMName.hpp"
00042 #include "OWBI1_CIMValue.hpp"
00043
00044 namespace OWBI1
00045 {
00046 using namespace OpenWBEM;
00047 using std::istream;
00048 using std::ostream;
00050 struct CIMParamValue::Data : public COWIntrusiveCountableBase
00051 {
00052 Data()
00053 : m_val(CIMNULL)
00054 {}
00055 CIMName m_name;
00056 CIMValue m_val;
00057 Data* clone() const { return new Data(*this); }
00058 };
00060 bool operator<(const CIMParamValue::Data& x, const CIMParamValue::Data& y)
00061 {
00062 return StrictWeakOrdering(
00063 x.m_name, y.m_name,
00064 x.m_val, y.m_val);
00065 }
00067 CIMParamValue::CIMParamValue() :
00068 m_pdata(new Data)
00069 {
00070 }
00072 CIMParamValue::CIMParamValue(CIMNULL_t) :
00073 m_pdata(0)
00074 {
00075 }
00077 CIMParamValue::CIMParamValue(const CIMName& name) :
00078 m_pdata(new Data)
00079 {
00080 m_pdata->m_name = name;
00081 }
00083 CIMParamValue::CIMParamValue(const CIMName& name, const CIMValue& val) :
00084 m_pdata(new Data)
00085 {
00086 m_pdata->m_name = name;
00087 m_pdata->m_val = val;
00088 }
00090 CIMParamValue::CIMParamValue(const CIMParamValue& x) :
00091 CIMBase(x), m_pdata(x.m_pdata)
00092 {
00093 }
00095 CIMParamValue::~CIMParamValue()
00096 {
00097 }
00099 CIMParamValue&
00100 CIMParamValue::operator= (const CIMParamValue& x)
00101 {
00102 m_pdata = x.m_pdata;
00103 return *this;
00104 }
00106 String
00107 CIMParamValue::getName() const
00108 {
00109 return m_pdata->m_name.toString();
00110 }
00112 CIMParamValue&
00113 CIMParamValue::setName(const CIMName& name)
00114 {
00115 m_pdata->m_name = name;
00116 return *this;
00117 }
00119 CIMValue
00120 CIMParamValue::getValue() const
00121 {
00122 return m_pdata->m_val;
00123 }
00125 CIMParamValue&
00126 CIMParamValue::setValue(const CIMValue& val)
00127 {
00128 m_pdata->m_val = val;
00129 return *this;
00130 }
00132 void
00133 CIMParamValue::setNull()
00134 {
00135 m_pdata = NULL;
00136 }
00138 void
00139 CIMParamValue::writeObject(ostream &ostrm) const
00140 {
00141 CIMBase::writeSig( ostrm, OWBI1_CIMPARAMVALUESIG );
00142 m_pdata->m_name.writeObject(ostrm);
00143 if (m_pdata->m_val)
00144 {
00145 Bool(true).writeObject(ostrm);
00146 m_pdata->m_val.writeObject(ostrm);
00147 }
00148 else
00149 {
00150 Bool(false).writeObject(ostrm);
00151 }
00152 }
00154 void
00155 CIMParamValue::readObject(istream &istrm)
00156 {
00157 CIMName name;
00158 CIMValue val(CIMNULL);
00159 CIMBase::readSig( istrm, OWBI1_CIMPARAMVALUESIG );
00160 name.readObject(istrm);
00161 Bool b;
00162 b.readObject(istrm);
00163 if (b)
00164 {
00165 val.readObject(istrm);
00166 }
00167 m_pdata->m_name = name;
00168 m_pdata->m_val = val;
00169 }
00171 String
00172 CIMParamValue::toString() const
00173 {
00174 return "CIMParamValue(" + m_pdata->m_name.toString() + "): " + m_pdata->m_val.toString();
00175 }
00177 String
00178 CIMParamValue::toMOF() const
00179 {
00180 return "ERROR: CIMParamValue cannot be converted to MOF";
00181 }
00183 bool operator<(const CIMParamValue& x, const CIMParamValue& y)
00184 {
00185 return *x.m_pdata < *y.m_pdata;
00186 }
00187
00189 CIMValue
00190 getParamValue(const String& paramName, const CIMParamValueArray& params)
00191 {
00192 for ( CIMParamValueArray::const_iterator param = params.begin();
00193 param != params.end();
00194 ++param )
00195 {
00196 if ( param->getName().equalsIgnoreCase(paramName) )
00197 {
00198 return param->getValue();
00199 }
00200 }
00201 return CIMValue(CIMNULL);
00202 }
00203
00204 }
00205