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

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