OW_CIMMethod.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_CIMMethod.hpp"
00038 #include "OW_StringBuffer.hpp"
00039 #include "OW_CIMDataType.hpp"
00040 #include "OW_CIMQualifier.hpp"
00041 #include "OW_CIMParameter.hpp"
00042 #include "OW_CIMName.hpp"
00043 #include "OW_Array.hpp"
00044 #include "OW_BinarySerialization.hpp"
00045 #include "OW_StrictWeakOrdering.hpp"
00046 #include "OW_COWIntrusiveCountableBase.hpp"
00047 
00048 namespace OW_NAMESPACE
00049 {
00050 
00051 using std::ostream;
00052 using std::istream;
00053 using namespace WBEMFlags;
00055 struct CIMMethod::METHData : public COWIntrusiveCountableBase
00056 {
00057    METHData() 
00058       : m_propagated(false)
00059    {
00060    }
00061    CIMName m_name;
00062    CIMDataType m_returnDatatype;
00063    CIMQualifierArray m_qualifiers;
00064    CIMParameterArray m_parameters;
00065    CIMName m_originClass;
00066    CIMName m_override;
00067    Bool m_propagated;
00068    METHData* clone() const { return new METHData(*this); }
00069 };
00071 bool operator<(const CIMMethod::METHData& x, const CIMMethod::METHData& y)
00072 {
00073    return StrictWeakOrdering(
00074       x.m_name, y.m_name,
00075       x.m_returnDatatype, y.m_returnDatatype,
00076       x.m_qualifiers, y.m_qualifiers,
00077       x.m_parameters, y.m_parameters,
00078       x.m_originClass, y.m_originClass,
00079       x.m_override, y.m_override,
00080       x.m_propagated, y.m_propagated);
00081 }
00083 CIMMethod::CIMMethod() :
00084    CIMElement(), m_pdata(new METHData)
00085 {
00086 }
00088 CIMMethod::CIMMethod(CIMNULL_t) :
00089    CIMElement(), m_pdata(0)
00090 {
00091 }
00093 CIMMethod::CIMMethod(const char* name) :
00094    CIMElement(), m_pdata(new METHData)
00095 {
00096    m_pdata->m_name = name;
00097 }
00099 CIMMethod::CIMMethod(const CIMName& name) :
00100    CIMElement(), m_pdata(new METHData)
00101 {
00102    m_pdata->m_name = name;
00103 }
00105 CIMMethod::CIMMethod(const CIMMethod& x)
00106    : CIMElement(), m_pdata(x.m_pdata)
00107 {
00108 }
00110 CIMMethod::~CIMMethod()
00111 {
00112 }
00114 void
00115 CIMMethod::setNull()
00116 {
00117    m_pdata = NULL;
00118 }
00120 CIMMethod&
00121 CIMMethod::operator= (const CIMMethod& x)
00122 {
00123    m_pdata = x.m_pdata;
00124    return *this;
00125 }
00127 CIMMethod&
00128 CIMMethod::addQualifier(const CIMQualifier& qual)
00129 {
00130    m_pdata->m_qualifiers.append(qual);
00131    return *this;
00132 }
00134 CIMMethod&
00135 CIMMethod::setQualifiers(const CIMQualifierArray& quals)
00136 {
00137    m_pdata->m_qualifiers = quals;
00138    return *this;
00139 }
00141 CIMQualifierArray
00142 CIMMethod::getQualifiers() const
00143 {
00144    return m_pdata->m_qualifiers;
00145 }
00147 CIMQualifier
00148 CIMMethod::getQualifier(const CIMName& name) const
00149 {
00150    int tsize = m_pdata->m_qualifiers.size();
00151    for (int i = 0; i < tsize; i++)
00152    {
00153       CIMQualifier nq = m_pdata->m_qualifiers[i];
00154       if (nq.getName() == name)
00155       {
00156          return nq;
00157       }
00158    }
00159    return CIMQualifier(CIMNULL);
00160 }
00162 String
00163 CIMMethod::getOriginClass() const
00164 {
00165    return m_pdata->m_originClass.toString();
00166 }
00168 CIMMethod&
00169 CIMMethod::setOriginClass(const CIMName& originCls)
00170 {
00171    m_pdata->m_originClass = originCls;
00172    return *this;
00173 }
00175 CIMMethod&
00176 CIMMethod::addParameter(const CIMParameter& param)
00177 {
00178    m_pdata->m_parameters.append(param);
00179    return *this;
00180 }
00182 CIMMethod&
00183 CIMMethod::setParameters(const CIMParameterArray& inParms)
00184 {
00185    m_pdata->m_parameters = inParms;
00186    return *this;
00187 }
00189 CIMParameterArray
00190 CIMMethod::getParameters() const
00191 {
00192    return m_pdata->m_parameters;
00193 }
00195 CIMParameterArray
00196 CIMMethod::getINParameters() const
00197 {
00198    CIMParameterArray rval;
00199    for (size_t i = 0; i < m_pdata->m_parameters.size(); ++i)
00200    {
00201       // TODO
00202       // Note: The following code assumes the default value for the
00203       // CIM_QUAL_IN qualifier is true. The is per the CIM 2.2 spec.
00204       // THE SPEC ALSO STATES THAT THE DEFAULT VALUE FOR QUALIFIERS CAN
00205       // BE CHANGED.
00206       CIMQualifier q = m_pdata->m_parameters[i].getQualifier(CIMQualifier::CIM_QUAL_IN);
00207       if (!q || q.getValue() == CIMValue(true))
00208       {
00209          rval.push_back(m_pdata->m_parameters[i]);
00210       }
00211    }
00212 
00213    return rval;
00214 }
00216 CIMParameterArray
00217 CIMMethod::getOUTParameters() const
00218 {
00219    CIMParameterArray rval;
00220    for (size_t i = 0; i < m_pdata->m_parameters.size(); ++i)
00221    {
00222       if (m_pdata->m_parameters[i].hasTrueQualifier(CIMQualifier::CIM_QUAL_OUT))
00223       {
00224          rval.push_back(m_pdata->m_parameters[i]);
00225       }
00226    }
00227 
00228    return rval;
00229 }
00231 CIMMethod&
00232 CIMMethod::setReturnType(const CIMDataType& type)
00233 {
00234    m_pdata->m_returnDatatype = type;
00235    return *this;
00236 }
00238 CIMDataType
00239 CIMMethod::getReturnType() const
00240 {
00241    return m_pdata->m_returnDatatype;
00242 }
00244 Int32
00245 CIMMethod::getReturnDataSize() const
00246 {
00247    return m_pdata->m_returnDatatype.getSize();
00248 }
00250 CIMMethod&
00251 CIMMethod::setOverridingMethod(const CIMName& omname)
00252 {
00253    m_pdata->m_override = omname;
00254    return *this;
00255 }
00257 String
00258 CIMMethod::getOverridingMethod() const
00259 {
00260    return m_pdata->m_override.toString();
00261 }
00263 CIMMethod
00264 CIMMethod::clone(EIncludeQualifiersFlag includeQualifiers,
00265    EIncludeClassOriginFlag includeClassOrigin) const
00266 {
00267    if (!m_pdata)
00268    {
00269       return CIMMethod(CIMNULL);
00270    }
00271    CIMMethod theMethod;
00272    theMethod.m_pdata->m_name = m_pdata->m_name;
00273    theMethod.m_pdata->m_returnDatatype = m_pdata->m_returnDatatype;
00274    theMethod.m_pdata->m_parameters = m_pdata->m_parameters;
00275    theMethod.m_pdata->m_override = m_pdata->m_override;
00276    theMethod.m_pdata->m_propagated = m_pdata->m_propagated;
00277    if (includeQualifiers)
00278    {
00279       theMethod.m_pdata->m_qualifiers = m_pdata->m_qualifiers;
00280    }
00281    if (includeClassOrigin)
00282    {
00283       theMethod.m_pdata->m_originClass = m_pdata->m_originClass;
00284    }
00285    return theMethod;
00286 }
00288 CIMMethod&
00289 CIMMethod::setPropagated(bool propagated)
00290 {
00291    m_pdata->m_propagated = propagated;
00292    return *this;
00293 }
00295 bool
00296 CIMMethod::getPropagated() const
00297 {
00298    return m_pdata->m_propagated;
00299 }
00301 String
00302 CIMMethod::getName() const
00303 {
00304    return m_pdata->m_name.toString();
00305 }
00307 void
00308 CIMMethod::setName(const CIMName& name)
00309 {
00310    m_pdata->m_name = name;
00311 }
00313 void
00314 CIMMethod::readObject(istream &istrm)
00315 {
00316    CIMName name;
00317    CIMDataType returnDatatype(CIMNULL);
00318    CIMQualifierArray qualifiers;
00319    CIMParameterArray parameters;
00320    CIMName originClass;
00321    CIMName override;
00322    Bool propagated;
00323    CIMBase::readSig( istrm, OW_CIMMETHODSIG );
00324    name.readObject(istrm);
00325    returnDatatype.readObject(istrm);
00326    BinarySerialization::readArray(istrm, qualifiers);
00327    BinarySerialization::readArray(istrm, parameters);
00328    originClass.readObject(istrm);
00329    override.readObject(istrm);
00330    propagated.readObject(istrm);
00331    if (!m_pdata)
00332    {
00333       m_pdata = new METHData;
00334    }
00335    m_pdata->m_name = name;
00336    m_pdata->m_originClass = originClass;
00337    m_pdata->m_override = override;
00338    m_pdata->m_parameters = parameters;
00339    m_pdata->m_propagated = propagated;
00340    m_pdata->m_qualifiers = qualifiers;
00341    m_pdata->m_returnDatatype = returnDatatype;
00342 }
00344 void
00345 CIMMethod::writeObject(ostream &ostrm) const
00346 {
00347    CIMBase::writeSig( ostrm, OW_CIMMETHODSIG );
00348    m_pdata->m_name.writeObject(ostrm);
00349    m_pdata->m_returnDatatype.writeObject(ostrm);
00350    BinarySerialization::writeArray(ostrm, m_pdata->m_qualifiers);
00351    BinarySerialization::writeArray(ostrm, m_pdata->m_parameters);
00352    m_pdata->m_originClass.writeObject(ostrm);
00353    m_pdata->m_override.writeObject(ostrm);
00354    m_pdata->m_propagated.writeObject(ostrm);
00355 }
00357 String
00358 CIMMethod::toMOF() const
00359 {
00360    StringBuffer rv;
00361    size_t i;
00362    if (m_pdata->m_qualifiers.size() > 0)
00363    {
00364       rv += '[';
00365       for (i = 0; i < m_pdata->m_qualifiers.size(); i++)
00366       {
00367          CIMQualifier nq = m_pdata->m_qualifiers[i];
00368          if (i > 0)
00369          {
00370             rv += ',';
00371          }
00372          rv += nq.toMOF();
00373       }
00374       rv += ']';
00375    }
00376    rv += m_pdata->m_returnDatatype.toMOF();
00377    rv += ' ';
00378    rv += m_pdata->m_name.toString();
00379    rv += '(';
00380    if (m_pdata->m_parameters.size() > 0)
00381    {
00382       for (i = 0; i < m_pdata->m_parameters.size(); i++)
00383       {
00384          CIMParameter nq = m_pdata->m_parameters[i];
00385          if (i > 0)
00386          {
00387             rv += ',';
00388          }
00389          rv += nq.toMOF();
00390       }
00391    }
00392    rv += ");\n";
00393    return rv.releaseString();
00394 }
00396 String
00397 CIMMethod::toString() const
00398 {
00399    String rv("CIMMethod NAME = ");
00400    rv += m_pdata->m_name.toString();
00401    return rv;
00402 }
00404 bool operator<(const CIMMethod& x, const CIMMethod& y)
00405 {
00406    return *x.m_pdata < *y.m_pdata;
00407 }
00408 
00409 } // end namespace OW_NAMESPACE
00410 

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