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 "OW_config.h"
00036 #include "OW_CIMParamValue.hpp"
00037 #include "OW_StringBuffer.hpp"
00038 #include "OW_BinarySerialization.hpp"
00039 #include "OW_StrictWeakOrdering.hpp"
00040 #include "OW_COWIntrusiveCountableBase.hpp"
00041
00042 namespace OW_NAMESPACE
00043 {
00044
00045 using std::istream;
00046 using std::ostream;
00048 struct CIMParamValue::Data : public COWIntrusiveCountableBase
00049 {
00050 Data()
00051 : m_val(CIMNULL)
00052 {}
00053 CIMName m_name;
00054 CIMValue m_val;
00055 Data* clone() const { return new Data(*this); }
00056 };
00058 bool operator<(const CIMParamValue::Data& x, const CIMParamValue::Data& y)
00059 {
00060 return StrictWeakOrdering(
00061 x.m_name, y.m_name,
00062 x.m_val, y.m_val);
00063 }
00065 CIMParamValue::CIMParamValue() :
00066 m_pdata(new Data)
00067 {
00068 }
00070 CIMParamValue::CIMParamValue(CIMNULL_t) :
00071 m_pdata(0)
00072 {
00073 }
00075 CIMParamValue::CIMParamValue(const CIMName& name) :
00076 m_pdata(new Data)
00077 {
00078 m_pdata->m_name = name;
00079 }
00081 CIMParamValue::CIMParamValue(const CIMName& name, const CIMValue& val) :
00082 m_pdata(new Data)
00083 {
00084 m_pdata->m_name = name;
00085 m_pdata->m_val = val;
00086 }
00088 CIMParamValue::CIMParamValue(const CIMParamValue& x) :
00089 CIMBase(x), m_pdata(x.m_pdata)
00090 {
00091 }
00093 CIMParamValue::~CIMParamValue()
00094 {
00095 }
00097 CIMParamValue&
00098 CIMParamValue::operator= (const CIMParamValue& x)
00099 {
00100 m_pdata = x.m_pdata;
00101 return *this;
00102 }
00104 String
00105 CIMParamValue::getName() const
00106 {
00107 return m_pdata->m_name.toString();
00108 }
00110 CIMParamValue&
00111 CIMParamValue::setName(const CIMName& name)
00112 {
00113 m_pdata->m_name = name;
00114 return *this;
00115 }
00117 CIMValue
00118 CIMParamValue::getValue() const
00119 {
00120 return m_pdata->m_val;
00121 }
00123 CIMParamValue&
00124 CIMParamValue::setValue(const CIMValue& val)
00125 {
00126 m_pdata->m_val = val;
00127 return *this;
00128 }
00130 void
00131 CIMParamValue::setNull()
00132 {
00133 m_pdata = NULL;
00134 }
00136 void
00137 CIMParamValue::writeObject(ostream &ostrm) const
00138 {
00139 CIMBase::writeSig( ostrm, OW_CIMPARAMVALUESIG );
00140 m_pdata->m_name.writeObject(ostrm);
00141 if (m_pdata->m_val)
00142 {
00143 Bool(true).writeObject(ostrm);
00144 m_pdata->m_val.writeObject(ostrm);
00145 }
00146 else
00147 {
00148 Bool(false).writeObject(ostrm);
00149 }
00150 }
00152 void
00153 CIMParamValue::readObject(istream &istrm)
00154 {
00155 CIMName name;
00156 CIMValue val(CIMNULL);
00157 CIMBase::readSig( istrm, OW_CIMPARAMVALUESIG );
00158 name.readObject(istrm);
00159 Bool b;
00160 b.readObject(istrm);
00161 if (b)
00162 {
00163 val.readObject(istrm);
00164 }
00165 m_pdata->m_name = name;
00166 m_pdata->m_val = val;
00167 }
00169 String
00170 CIMParamValue::toString() const
00171 {
00172 return "CIMParamValue(" + m_pdata->m_name.toString() + "): " + m_pdata->m_val.toString();
00173 }
00175 String
00176 CIMParamValue::toMOF() const
00177 {
00178 return "ERROR: CIMParamValue cannot be converted to MOF";
00179 }
00181 bool operator<(const CIMParamValue& x, const CIMParamValue& y)
00182 {
00183 return *x.m_pdata < *y.m_pdata;
00184 }
00185
00187 CIMValue
00188 getParamValue(const String& paramName, const CIMParamValueArray& params)
00189 {
00190 for ( CIMParamValueArray::const_iterator param = params.begin();
00191 param != params.end();
00192 ++param )
00193 {
00194 if ( param->getName().equalsIgnoreCase(paramName) )
00195 {
00196 return param->getValue();
00197 }
00198 }
00199 return CIMValue(CIMNULL);
00200 }
00201
00202 }
00203