00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00036 #include "OWBI1_config.h"
00037 #include "OWBI1_CIMMethod.hpp"
00038 #include "OWBI1_StringBuffer.hpp"
00039 #include "OWBI1_CIMDataType.hpp"
00040 #include "OWBI1_CIMQualifier.hpp"
00041 #include "OWBI1_CIMParameter.hpp"
00042 #include "OWBI1_CIMName.hpp"
00043 #include "OWBI1_CIMValue.hpp"
00044 #include "OWBI1_Array.hpp"
00045 #include "OW_BinarySerialization.hpp"
00046 #include "OW_StrictWeakOrdering.hpp"
00047 #include "OWBI1_COWIntrusiveCountableBase.hpp"
00048
00049 namespace OWBI1
00050 {
00051
00052 using namespace OpenWBEM;
00053 using std::ostream;
00054 using std::istream;
00055 using namespace WBEMFlags;
00057 struct CIMMethod::METHData : public COWIntrusiveCountableBase
00058 {
00059 METHData()
00060 : m_propagated(false)
00061 {
00062 }
00063 CIMName m_name;
00064 CIMDataType m_returnDatatype;
00065 CIMQualifierArray m_qualifiers;
00066 CIMParameterArray m_parameters;
00067 CIMName m_originClass;
00068 CIMName m_override;
00069 Bool m_propagated;
00070 METHData* clone() const { return new METHData(*this); }
00071 };
00073 bool operator<(const CIMMethod::METHData& x, const CIMMethod::METHData& y)
00074 {
00075 return StrictWeakOrdering(
00076 x.m_name, y.m_name,
00077 x.m_returnDatatype, y.m_returnDatatype,
00078 x.m_qualifiers, y.m_qualifiers,
00079 x.m_parameters, y.m_parameters,
00080 x.m_originClass, y.m_originClass,
00081 x.m_override, y.m_override,
00082 x.m_propagated, y.m_propagated);
00083 }
00085 CIMMethod::CIMMethod() :
00086 CIMElement(), m_pdata(new METHData)
00087 {
00088 }
00090 CIMMethod::CIMMethod(CIMNULL_t) :
00091 CIMElement(), m_pdata(0)
00092 {
00093 }
00095 CIMMethod::CIMMethod(const char* name) :
00096 CIMElement(), m_pdata(new METHData)
00097 {
00098 m_pdata->m_name = name;
00099 }
00101 CIMMethod::CIMMethod(const CIMName& name) :
00102 CIMElement(), m_pdata(new METHData)
00103 {
00104 m_pdata->m_name = name;
00105 }
00107 CIMMethod::CIMMethod(const CIMMethod& x)
00108 : CIMElement(), m_pdata(x.m_pdata)
00109 {
00110 }
00112 CIMMethod::~CIMMethod()
00113 {
00114 }
00116 void
00117 CIMMethod::setNull()
00118 {
00119 m_pdata = NULL;
00120 }
00122 CIMMethod&
00123 CIMMethod::operator= (const CIMMethod& x)
00124 {
00125 m_pdata = x.m_pdata;
00126 return *this;
00127 }
00129 CIMMethod&
00130 CIMMethod::addQualifier(const CIMQualifier& qual)
00131 {
00132 m_pdata->m_qualifiers.append(qual);
00133 return *this;
00134 }
00136 CIMMethod&
00137 CIMMethod::setQualifiers(const CIMQualifierArray& quals)
00138 {
00139 m_pdata->m_qualifiers = quals;
00140 return *this;
00141 }
00143 CIMQualifierArray
00144 CIMMethod::getQualifiers() const
00145 {
00146 return m_pdata->m_qualifiers;
00147 }
00149 CIMQualifier
00150 CIMMethod::getQualifier(const CIMName& name) const
00151 {
00152 int tsize = m_pdata->m_qualifiers.size();
00153 for (int i = 0; i < tsize; i++)
00154 {
00155 CIMQualifier nq = m_pdata->m_qualifiers[i];
00156 if (nq.getName() == name)
00157 {
00158 return nq;
00159 }
00160 }
00161 return CIMQualifier(CIMNULL);
00162 }
00164 CIMName
00165 CIMMethod::getOriginClass() const
00166 {
00167 return m_pdata->m_originClass;
00168 }
00170 CIMMethod&
00171 CIMMethod::setOriginClass(const CIMName& originCls)
00172 {
00173 m_pdata->m_originClass = originCls;
00174 return *this;
00175 }
00177 CIMMethod&
00178 CIMMethod::addParameter(const CIMParameter& param)
00179 {
00180 m_pdata->m_parameters.append(param);
00181 return *this;
00182 }
00184 CIMMethod&
00185 CIMMethod::setParameters(const CIMParameterArray& inParms)
00186 {
00187 m_pdata->m_parameters = inParms;
00188 return *this;
00189 }
00191 CIMParameterArray
00192 CIMMethod::getParameters() const
00193 {
00194 return m_pdata->m_parameters;
00195 }
00197 CIMParameterArray
00198 CIMMethod::getINParameters() const
00199 {
00200 CIMParameterArray rval;
00201 for (size_t i = 0; i < m_pdata->m_parameters.size(); ++i)
00202 {
00203
00204
00205
00206
00207
00208 CIMQualifier q = m_pdata->m_parameters[i].getQualifier(CIMQualifier::CIM_QUAL_IN);
00209 if (!q || q.getValue() == CIMValue(true))
00210 {
00211 rval.push_back(m_pdata->m_parameters[i]);
00212 }
00213 }
00214
00215 return rval;
00216 }
00218 CIMParameterArray
00219 CIMMethod::getOUTParameters() const
00220 {
00221 CIMParameterArray rval;
00222 for (size_t i = 0; i < m_pdata->m_parameters.size(); ++i)
00223 {
00224 if (m_pdata->m_parameters[i].hasTrueQualifier(CIMQualifier::CIM_QUAL_OUT))
00225 {
00226 rval.push_back(m_pdata->m_parameters[i]);
00227 }
00228 }
00229
00230 return rval;
00231 }
00233 CIMMethod&
00234 CIMMethod::setReturnType(const CIMDataType& type)
00235 {
00236 m_pdata->m_returnDatatype = type;
00237 return *this;
00238 }
00240 CIMDataType
00241 CIMMethod::getReturnType() const
00242 {
00243 return m_pdata->m_returnDatatype;
00244 }
00246 Int32
00247 CIMMethod::getReturnDataSize() const
00248 {
00249 return m_pdata->m_returnDatatype.getSize();
00250 }
00252 CIMMethod&
00253 CIMMethod::setOverridingMethod(const CIMName& omname)
00254 {
00255 m_pdata->m_override = omname;
00256 return *this;
00257 }
00259 CIMName
00260 CIMMethod::getOverridingMethod() const
00261 {
00262 return m_pdata->m_override;
00263 }
00265 CIMMethod
00266 CIMMethod::clone(EIncludeQualifiersFlag includeQualifiers,
00267 EIncludeClassOriginFlag includeClassOrigin) const
00268 {
00269 if (!m_pdata)
00270 {
00271 return CIMMethod(CIMNULL);
00272 }
00273 CIMMethod theMethod;
00274 theMethod.m_pdata->m_name = m_pdata->m_name;
00275 theMethod.m_pdata->m_returnDatatype = m_pdata->m_returnDatatype;
00276 theMethod.m_pdata->m_parameters = m_pdata->m_parameters;
00277 theMethod.m_pdata->m_override = m_pdata->m_override;
00278 theMethod.m_pdata->m_propagated = m_pdata->m_propagated;
00279 if (includeQualifiers)
00280 {
00281 theMethod.m_pdata->m_qualifiers = m_pdata->m_qualifiers;
00282 }
00283 if (includeClassOrigin)
00284 {
00285 theMethod.m_pdata->m_originClass = m_pdata->m_originClass;
00286 }
00287 return theMethod;
00288 }
00290 CIMMethod&
00291 CIMMethod::setPropagated(bool propagated)
00292 {
00293 m_pdata->m_propagated = propagated;
00294 return *this;
00295 }
00297 bool
00298 CIMMethod::getPropagated() const
00299 {
00300 return m_pdata->m_propagated;
00301 }
00303 CIMName
00304 CIMMethod::getName() const
00305 {
00306 return m_pdata->m_name;
00307 }
00309 void
00310 CIMMethod::setName(const CIMName& name)
00311 {
00312 m_pdata->m_name = name;
00313 }
00315 void
00316 CIMMethod::readObject(istream &istrm)
00317 {
00318 CIMName name;
00319 CIMDataType returnDatatype(CIMNULL);
00320 CIMQualifierArray qualifiers;
00321 CIMParameterArray parameters;
00322 CIMName originClass;
00323 CIMName override;
00324 Bool propagated;
00325 CIMBase::readSig( istrm, OWBI1_CIMMETHODSIG );
00326 name.readObject(istrm);
00327 returnDatatype.readObject(istrm);
00328 BinarySerialization::readArray(istrm, qualifiers);
00329 BinarySerialization::readArray(istrm, parameters);
00330 originClass.readObject(istrm);
00331 override.readObject(istrm);
00332 propagated.readObject(istrm);
00333 if (!m_pdata)
00334 {
00335 m_pdata = new METHData;
00336 }
00337 m_pdata->m_name = name;
00338 m_pdata->m_originClass = originClass;
00339 m_pdata->m_override = override;
00340 m_pdata->m_parameters = parameters;
00341 m_pdata->m_propagated = propagated;
00342 m_pdata->m_qualifiers = qualifiers;
00343 m_pdata->m_returnDatatype = returnDatatype;
00344 }
00346 void
00347 CIMMethod::writeObject(ostream &ostrm) const
00348 {
00349 CIMBase::writeSig( ostrm, OWBI1_CIMMETHODSIG );
00350 m_pdata->m_name.writeObject(ostrm);
00351 m_pdata->m_returnDatatype.writeObject(ostrm);
00352 BinarySerialization::writeArray(ostrm, m_pdata->m_qualifiers);
00353 BinarySerialization::writeArray(ostrm, m_pdata->m_parameters);
00354 m_pdata->m_originClass.writeObject(ostrm);
00355 m_pdata->m_override.writeObject(ostrm);
00356 m_pdata->m_propagated.writeObject(ostrm);
00357 }
00359 String
00360 CIMMethod::toMOF() const
00361 {
00362 StringBuffer rv;
00363 size_t i;
00364 if (m_pdata->m_qualifiers.size() > 0)
00365 {
00366 rv += '[';
00367 for (i = 0; i < m_pdata->m_qualifiers.size(); i++)
00368 {
00369 CIMQualifier nq = m_pdata->m_qualifiers[i];
00370 if (i > 0)
00371 {
00372 rv += ',';
00373 }
00374 rv += nq.toMOF();
00375 }
00376 rv += ']';
00377 }
00378 rv += m_pdata->m_returnDatatype.toMOF();
00379 rv += ' ';
00380 rv += m_pdata->m_name.toString();
00381 rv += '(';
00382 if (m_pdata->m_parameters.size() > 0)
00383 {
00384 for (i = 0; i < m_pdata->m_parameters.size(); i++)
00385 {
00386 CIMParameter nq = m_pdata->m_parameters[i];
00387 if (i > 0)
00388 {
00389 rv += ',';
00390 }
00391 rv += nq.toMOF();
00392 }
00393 }
00394 rv += ");\n";
00395 return rv.releaseString();
00396 }
00398 String
00399 CIMMethod::toString() const
00400 {
00401 String rv("CIMMethod NAME = ");
00402 rv += m_pdata->m_name.toString();
00403 return rv;
00404 }
00406 bool operator<(const CIMMethod& x, const CIMMethod& y)
00407 {
00408 return *x.m_pdata < *y.m_pdata;
00409 }
00410
00411 }
00412