OWBI1_CIMParamValue.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
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 } // end namespace OWBI1
00205 

Generated on Thu Feb 9 08:48:26 2006 for openwbem by  doxygen 1.4.6