📄 cimobjectpath.cpp
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions://// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <cstring>#include <iostream>#include "HashTable.h"#include "CIMObjectPath.h"#include "Indentor.h"#include "CIMName.h"#include "XmlWriter.h"#include "XmlReader.h"#include "ArrayInternal.h"PEGASUS_NAMESPACE_BEGIN#define PEGASUS_ARRAY_T CIMKeyBinding# include "ArrayImpl.h"#undef PEGASUS_ARRAY_T#define PEGASUS_ARRAY_T CIMObjectPath# include "ArrayImpl.h"#undef PEGASUS_ARRAY_T// ATTN: KS May 2002 P0 Add resolve method to CIMObjectPath.// Add a resolve method to this class to verify that the// reference is correct (that the class name corresponds to a real// class and that the property names are really keys and that all keys// of the class or used. Also be sure that there is a valid conversion// between the string value and the value of that property).//// ATTN: also check to see that the reference refers to a class that is the// same or derived from the _className member.//////////////////////////////////////////////////////////////////////////////////// Local routines://////////////////////////////////////////////////////////////////////////////////static String _escapeSpecialCharacters(const String& str){ String result; for (Uint32 i = 0, n = str.size(); i < n; i++) { switch (str[i]) { case '\\': result.append("\\\\"); break; case '"': result.append("\\\""); break; default: result.append(str[i]); } } return result;}static void _BubbleSort(Array<CIMKeyBinding>& x){ Uint32 n = x.size(); // // If the key is a reference, the keys in the reference must also be // sorted // for (Uint32 k = 0; k < n ; k++) if (x[k].getType () == CIMKeyBinding::REFERENCE) { CIMObjectPath tmp (x[k].getValue ()); Array <CIMKeyBinding> keyBindings = tmp.getKeyBindings (); _BubbleSort (keyBindings); tmp.setKeyBindings (keyBindings); x[k].setValue (tmp.toString ()); } if (n < 2) return; for (Uint32 i = 0; i < n - 1; i++) { for (Uint32 j = 0; j < n - 1; j++) { if (String::compareNoCase(x[j].getName().getString(), x[j+1].getName().getString()) > 0) { CIMKeyBinding t = x[j]; x[j] = x[j+1]; x[j+1] = t; } } }}//////////////////////////////////////////////////////////////////////////////////// CIMKeyBinding//////////////////////////////////////////////////////////////////////////////////class CIMKeyBindingRep{public: CIMKeyBindingRep() { } CIMKeyBindingRep(const CIMKeyBindingRep& x) : _name(x._name), _value(x._value), _type(x._type) { } CIMKeyBindingRep( const CIMName& name, const String& value, CIMKeyBinding::Type type) : _name(name), _value(value), _type(type) { } ~CIMKeyBindingRep() { } CIMKeyBindingRep& operator=(const CIMKeyBindingRep& x) { if (&x != this) { _name = x._name; _value = x._value; _type = x._type; } return *this; } CIMName _name; String _value; CIMKeyBinding::Type _type;};CIMKeyBinding::CIMKeyBinding(){ _rep = new CIMKeyBindingRep();}CIMKeyBinding::CIMKeyBinding(const CIMKeyBinding& x){ _rep = new CIMKeyBindingRep(*x._rep);}CIMKeyBinding::CIMKeyBinding( const CIMName& name, const String& value, Type type){ _rep = new CIMKeyBindingRep(name, value, type);}CIMKeyBinding::CIMKeyBinding(const CIMName& name, const CIMValue& value){ if (value.isArray()) { throw TypeMismatchException(); } String kbValue = value.toString(); Type kbType; switch (value.getType()) { case CIMTYPE_BOOLEAN: kbType = BOOLEAN; break; case CIMTYPE_CHAR16: case CIMTYPE_STRING: case CIMTYPE_DATETIME: kbType = STRING; break; case CIMTYPE_REFERENCE: kbType = REFERENCE; break;// case CIMTYPE_REAL32:// case CIMTYPE_REAL64: case CIMTYPE_OBJECT:#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT case CIMTYPE_INSTANCE:#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT // From PEP 194: EmbeddedObjects cannot be keys. throw TypeMismatchException(); break; default: kbType = NUMERIC; break; } _rep = new CIMKeyBindingRep(name, kbValue, kbType);}CIMKeyBinding::~CIMKeyBinding(){ delete _rep;}CIMKeyBinding& CIMKeyBinding::operator=(const CIMKeyBinding& x){ *_rep = *x._rep; return *this;}const CIMName& CIMKeyBinding::getName() const{ return _rep->_name;}void CIMKeyBinding::setName(const CIMName& name){ _rep->_name = name;}const String& CIMKeyBinding::getValue() const{ return _rep->_value;}void CIMKeyBinding::setValue(const String& value){ _rep->_value = value;}CIMKeyBinding::Type CIMKeyBinding::getType() const{ return _rep->_type;}void CIMKeyBinding::setType(CIMKeyBinding::Type type){ _rep->_type = type;}Boolean CIMKeyBinding::equal(CIMValue value){ if (value.isArray()) { return false; } CIMValue kbValue; try { switch (value.getType()) { case CIMTYPE_CHAR16: if (getType() != STRING) return false; kbValue.set(getValue()[0]); break; case CIMTYPE_DATETIME: if (getType() != STRING) return false; kbValue.set(CIMDateTime(getValue())); break; case CIMTYPE_STRING: if (getType() != STRING) return false; kbValue.set(getValue()); break; case CIMTYPE_REFERENCE: if (getType() != REFERENCE) return false; kbValue.set(CIMObjectPath(getValue())); break; case CIMTYPE_BOOLEAN: if (getType() != BOOLEAN) return false; kbValue = XmlReader::stringToValue(0, getValue().getCString(), value.getType()); break;// case CIMTYPE_REAL32:// case CIMTYPE_REAL64: case CIMTYPE_OBJECT:#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT case CIMTYPE_INSTANCE:#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT // From PEP 194: EmbeddedObjects cannot be keys. return false; break; default: // Numerics if (getType() != NUMERIC) return false; kbValue = XmlReader::stringToValue(0, getValue().getCString(), value.getType()); break; } } catch (Exception&) { return false; } return value.equal(kbValue);}Boolean operator==(const CIMKeyBinding& x, const CIMKeyBinding& y){ // Check that the names and types match if (!(x.getName().equal(y.getName())) || !(x.getType() == y.getType())) { return false; } switch (x.getType()) { case CIMKeyBinding::REFERENCE: try { // References should be compared as CIMObjectPaths return (CIMObjectPath(x.getValue()) == CIMObjectPath(y.getValue())); } catch (Exception&) { // If CIMObjectPath parsing fails, just compare strings return String::equal(x.getValue(), y.getValue()); } break; case CIMKeyBinding::BOOLEAN: // Case-insensitive comparison is sufficient for booleans return String::equalNoCase(x.getValue(), y.getValue()); break; case CIMKeyBinding::NUMERIC: // Note: This comparison assumes XML syntax for integers // First try comparing as unsigned integers { Uint64 xValue; Uint64 yValue; if (XmlReader::stringToUnsignedInteger( x.getValue().getCString(), xValue) && XmlReader::stringToUnsignedInteger( y.getValue().getCString(), yValue)) { return (xValue == yValue); } } // Next try comparing as signed integers { Sint64 xValue; Sint64 yValue; if (XmlReader::stringToSignedInteger( x.getValue().getCString(), xValue) && XmlReader::stringToSignedInteger( y.getValue().getCString(), yValue)) { return (xValue == yValue); } } // Note: Keys may not be real values, so don't try comparing as reals // We couldn't parse the numbers, so just compare the strings return String::equal(x.getValue(), y.getValue()); break; default: // CIMKeyBinding::STRING return String::equal(x.getValue(), y.getValue()); break; } PEGASUS_UNREACHABLE(return false;)}//////////////////////////////////////////////////////////////////////////////////// CIMObjectPath//////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -