OW_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 "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 } // end namespace OW_NAMESPACE
00203 

Generated on Thu Feb 9 08:47:54 2006 for openwbem by  doxygen 1.4.6