OWBI1_CIMParameter.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 
00036 #include "OWBI1_config.h"
00037 #include "OWBI1_CIMParameter.hpp"
00038 #include "OWBI1_StringBuffer.hpp"
00039 #include "OW_BinarySerialization.hpp"
00040 #include "OW_StrictWeakOrdering.hpp"
00041 #include "OWBI1_CIMDataType.hpp"
00042 #include "OWBI1_CIMQualifier.hpp"
00043 #include "OWBI1_CIMName.hpp"
00044 #include "OWBI1_CIMValue.hpp"
00045 #include "OWBI1_COWIntrusiveCountableBase.hpp"
00046 #include "OWBI1_Array.hpp"
00047 
00048 namespace OWBI1
00049 {
00050 
00051 using namespace OpenWBEM;
00052 using std::istream;
00053 using std::ostream;
00055 struct CIMParameter::PARMData : public COWIntrusiveCountableBase
00056 {
00057    CIMName m_name;
00058    CIMDataType m_dataType;
00059    CIMQualifierArray m_qualifiers;
00060    PARMData* clone() const { return new PARMData(*this); }
00061 };
00063 bool operator<(const CIMParameter::PARMData& x, const CIMParameter::PARMData& y)
00064 {
00065    return StrictWeakOrdering(
00066       x.m_name, y.m_name,
00067       x.m_dataType, y.m_dataType,
00068       x.m_qualifiers, y.m_qualifiers);
00069 }
00071 CIMParameter::CIMParameter() :
00072    CIMElement(), m_pdata(new PARMData)
00073 {
00074 }
00076 CIMParameter::CIMParameter(CIMNULL_t) :
00077    CIMElement(), m_pdata(0)
00078 {
00079 }
00081 CIMParameter::CIMParameter(const char* name) :
00082    CIMElement(), m_pdata(new PARMData)
00083 {
00084    m_pdata->m_name = name;
00085 }
00087 CIMParameter::CIMParameter(const CIMName& name) :
00088    CIMElement(), m_pdata(new PARMData)
00089 {
00090    m_pdata->m_name = name;
00091 }
00093 CIMParameter::CIMParameter(const CIMParameter& x) :
00094    CIMElement(), m_pdata(x.m_pdata)
00095 {
00096 }
00098 CIMParameter::~CIMParameter()
00099 {
00100 }
00102 void
00103 CIMParameter::setNull()
00104 {
00105    m_pdata = NULL;
00106 }
00108 CIMParameter&
00109 CIMParameter::operator= (const CIMParameter& x)
00110 {
00111    m_pdata = x.m_pdata;
00112    return *this;
00113 }
00115 CIMParameter&
00116 CIMParameter::setQualifiers(const CIMQualifierArray& quals)
00117 {
00118    m_pdata->m_qualifiers = quals;
00119    return *this;
00120 }
00122 CIMQualifierArray
00123 CIMParameter::getQualifiers() const
00124 {
00125    return m_pdata->m_qualifiers;
00126 }
00128 CIMParameter&
00129 CIMParameter::setDataType(const CIMDataType& type)
00130 {
00131    m_pdata->m_dataType = type;
00132    return *this;
00133 }
00135 CIMDataType
00136 CIMParameter::getType() const
00137 {
00138    return m_pdata->m_dataType;
00139 }
00141 Int32
00142 CIMParameter::getDataSize() const
00143 {
00144    return m_pdata->m_dataType.getSize();
00145 }
00147 CIMQualifier
00148 CIMParameter::getQualifier(const CIMName& name) const
00149 {
00150    for (size_t i = 0; i < m_pdata->m_qualifiers.size(); i++)
00151    {
00152       CIMQualifier nq = m_pdata->m_qualifiers[i];
00153       if (nq.getName() == name)
00154       {
00155          return nq;
00156       }
00157    }
00158    return CIMQualifier(CIMNULL);
00159 }
00161 CIMName
00162 CIMParameter::getName() const
00163 {
00164    return m_pdata->m_name;
00165 }
00167 void
00168 CIMParameter::setName(const CIMName& name)
00169 {
00170    m_pdata->m_name = name;
00171 }
00173 void
00174 CIMParameter::writeObject(ostream &ostrm) const
00175 {
00176    CIMBase::writeSig( ostrm, OWBI1_CIMPARAMETERSIG );
00177    m_pdata->m_name.writeObject(ostrm);
00178    m_pdata->m_dataType.writeObject(ostrm);
00179    BinarySerialization::writeArray(ostrm, m_pdata->m_qualifiers);
00180 }
00182 void
00183 CIMParameter::readObject(istream &istrm)
00184 {
00185    CIMName name;
00186    CIMDataType dataType(CIMNULL);
00187    CIMQualifierArray qualifiers;
00188    CIMBase::readSig( istrm, OWBI1_CIMPARAMETERSIG );
00189    name.readObject(istrm);
00190    dataType.readObject(istrm);
00191    BinarySerialization::readArray(istrm, qualifiers);
00192    if (!m_pdata)
00193    {
00194       m_pdata = new PARMData;
00195    }
00196    m_pdata->m_name = name;
00197    m_pdata->m_dataType = dataType;
00198    m_pdata->m_qualifiers = qualifiers;
00199 }
00201 String
00202 CIMParameter::toString() const
00203 {
00204    return "CIMParameter(" + m_pdata->m_name.toString() + ")";
00205 }
00207 String
00208 CIMParameter::toMOF() const
00209 {
00210    StringBuffer rv;
00211    if (m_pdata->m_qualifiers.size() > 0)
00212    {
00213       rv += '[';
00214       for (size_t i = 0; i < m_pdata->m_qualifiers.size(); i++)
00215       {
00216          CIMQualifier nq = m_pdata->m_qualifiers[i];
00217          if (i > 0)
00218          {
00219             rv += ',';
00220          }
00221          rv += nq.toMOF();
00222       }
00223       rv += ']';
00224    }
00225    rv += m_pdata->m_dataType.toMOF();
00226    rv += ' ';
00227    rv += m_pdata->m_name.toString();
00228    if (m_pdata->m_dataType.isArrayType())
00229    {
00230       rv += '[';
00231       int arraySize = m_pdata->m_dataType.getSize();
00232       if (arraySize != -1)
00233       {
00234          rv += arraySize;
00235       }
00236       rv += ']';
00237    }
00238    return rv.releaseString();
00239 }
00241 bool operator<(const CIMParameter& x, const CIMParameter& y)
00242 {
00243    return *x.m_pdata < *y.m_pdata;
00244 }
00246 bool 
00247 CIMParameter::hasTrueQualifier(const CIMName& name) const
00248 {
00249    CIMQualifier q = getQualifier(name);
00250    if (!q)
00251    {
00252       return false;
00253    }
00254    CIMValue v = q.getValue();
00255    if (!v)
00256    {
00257       return false;
00258    }
00259    if (v.getType() != CIMDataType::BOOLEAN)
00260    {
00261       return false;
00262    }
00263    Bool b;
00264    v.get(b);
00265    return b;
00266 }
00267 
00268 } // end namespace OWBI1
00269 

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