⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cimvalue.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//%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 <cstring>#include <cstdio>#include <cctype>#include "CIMValue.h"#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT#include "CIMInstance.h"#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT#include "Union.h"#include "Indentor.h"#include "XmlWriter.h"#include "CommonUTF.h"#include "CIMValueRep.h"#include "Config.h"#include "CIMType.h"#include "String.h"#include "CIMDateTime.h"#include "CIMObjectPath.h"#include "CIMObject.h"#include "Array.h"#include <Pegasus/Common/PegasusAssert.h>PEGASUS_NAMESPACE_BEGIN#define PEGASUS_ARRAY_T CIMValue# include "ArrayImpl.h"#undef PEGASUS_ARRAY_T// ATTN: By getting a CIMObject from a CIMValue, the client of CIMValue can// modify the internals of that CIMObject and thus change what CIMValue// itself refers to. There are two solutions: clone() at ever juncture or// force CIMValue to make its own unique copy when the client calls get()// to get a CIMObject.//==============================================================================//// _toString() routines:////==============================================================================inline void _toString(Buffer& out, Boolean x){    XmlWriter::append(out, x);}inline void _toString(Buffer& out, Uint8 x){    XmlWriter::append(out, Uint32(x));}inline void _toString(Buffer& out, Sint8 x){    XmlWriter::append(out, Sint32(x));}inline void _toString(Buffer& out, Uint16 x){    XmlWriter::append(out, Uint32(x));}inline void _toString(Buffer& out, Sint16 x){    XmlWriter::append(out, Sint32(x));}inline void _toString(Buffer& out, Uint32 x){    XmlWriter::append(out, x);}inline void _toString(Buffer& out, Sint32 x){    XmlWriter::append(out, x);}inline void _toString(Buffer& out, Uint64 x){    XmlWriter::append(out, x);}inline void _toString(Buffer& out, Sint64 x){    XmlWriter::append(out, x);}inline void _toString(Buffer& out, Real32 x){    XmlWriter::append(out, Real64(x));}inline void _toString(Buffer& out, Real64 x){    XmlWriter::append(out, x);}inline void _toString(Buffer& out, Char16 x){    // We need to convert the Char16 to UTF8 then append the UTF8    // character into the array.    // NOTE: The UTF8 character could be several bytes long.    // WARNING: This function will put in replacement character for    // all characters that have surogate pairs.    char str[6];    memset(str,0x00,sizeof(str));    char* charIN = (char *)&x;    const Uint16 *strsrc = (Uint16 *)charIN;    Uint16 *endsrc = (Uint16 *)&charIN[1];    Uint8 *strtgt = (Uint8 *)str;    Uint8 *endtgt = (Uint8 *)&str[5];    UTF16toUTF8(&strsrc, endsrc, &strtgt, endtgt);    out.append(str, UTF_8_COUNT_TRAIL_BYTES(str[0]) +1);}inline void _toString(Buffer& out, const String& x){    out << x;}inline void _toString(Buffer& out, const CIMDateTime& x){    out << x.toString();}inline void _toString(Buffer& out, const CIMObjectPath& x){    out << x.toString();}inline void _toString(Buffer& out, const CIMObject& x){    out << x.toString();}#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORTinline void _toString(Buffer& out, const CIMInstance& x){    out << CIMObject(x).toString();}#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORTtemplate<class T>void _toString(Buffer& out, const T* p, Uint32 size){    while (size--)    {        _toString(out, *p++);        out.append(' ');    }}//==============================================================================//// CIMValueRep////==============================================================================CIMValueRep CIMValueRep::_emptyRep((int*)0);void CIMValueRep::release(){    if (isArray)    {        switch (type)        {            case CIMTYPE_BOOLEAN:                CIMValueType<Boolean>::destructArray(this);                break;            case CIMTYPE_UINT8:                CIMValueType<Uint8>::destructArray(this);                break;            case CIMTYPE_SINT8:                CIMValueType<Sint8>::destructArray(this);                break;            case CIMTYPE_UINT16:                CIMValueType<Uint16>::destructArray(this);                break;            case CIMTYPE_SINT16:                CIMValueType<Sint16>::destructArray(this);                break;            case CIMTYPE_UINT32:                CIMValueType<Uint32>::destructArray(this);                break;            case CIMTYPE_SINT32:                CIMValueType<Sint32>::destructArray(this);                break;            case CIMTYPE_UINT64:                CIMValueType<Uint64>::destructArray(this);                break;            case CIMTYPE_SINT64:                CIMValueType<Sint64>::destructArray(this);                break;            case CIMTYPE_REAL32:                CIMValueType<Real32>::destructArray(this);                break;            case CIMTYPE_REAL64:                CIMValueType<Real64>::destructArray(this);                break;            case CIMTYPE_CHAR16:                CIMValueType<Char16>::destructArray(this);                break;            case CIMTYPE_STRING:                CIMValueType<String>::destructArray(this);                break;            case CIMTYPE_DATETIME:                CIMValueType<CIMDateTime>::destructArray(this);                break;            case CIMTYPE_REFERENCE:                CIMValueType<CIMObjectPath>::destructArray(this);                break;            case CIMTYPE_OBJECT:                CIMValueType<CIMObject>::destructArray(this);                break;#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT            case CIMTYPE_INSTANCE:                CIMValueType<CIMInstance>::destructArray(this);                break;#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT        }    }    else    {        switch (type)        {            case CIMTYPE_BOOLEAN:            case CIMTYPE_UINT8:            case CIMTYPE_SINT8:            case CIMTYPE_UINT16:            case CIMTYPE_SINT16:            case CIMTYPE_UINT32:            case CIMTYPE_SINT32:            case CIMTYPE_UINT64:            case CIMTYPE_SINT64:            case CIMTYPE_REAL32:            case CIMTYPE_REAL64:            case CIMTYPE_CHAR16:                break;            case CIMTYPE_STRING:                CIMValueType<String>::destruct(this);                break;            case CIMTYPE_DATETIME:                CIMValueType<CIMDateTime>::destruct(this);                break;            case CIMTYPE_REFERENCE:                CIMValueType<CIMObjectPath>::destruct(this);                break;            case CIMTYPE_OBJECT:                CIMValueType<CIMObject>::destruct(this);                break;#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT            case CIMTYPE_INSTANCE:                CIMValueType<CIMInstance>::destruct(this);                break;#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT        }    }}//==============================================================================//// CIMValue////==============================================================================static inline void _release(CIMValueRep*& rep){    if (rep->refs.get() == 1)        rep->release();    else    {        CIMValueRep::unref(rep);        rep = new CIMValueRep;    }}CIMValue::CIMValue(CIMType type, Boolean isArray, Uint32 arraySize){    _rep = new CIMValueRep;    switch (type)    {        case CIMTYPE_BOOLEAN:            CIMValueType<Boolean>::setNull(_rep, type, isArray, arraySize);            break;        case CIMTYPE_UINT8:            CIMValueType<Uint8>::setNull(_rep, type, isArray, arraySize);            break;        case CIMTYPE_SINT8:            CIMValueType<Sint8>::setNull(_rep, type, isArray, arraySize);            break;        case CIMTYPE_UINT16:            CIMValueType<Uint16>::setNull(_rep, type, isArray, arraySize);            break;        case CIMTYPE_SINT16:            CIMValueType<Sint16>::setNull(_rep, type, isArray, arraySize);            break;        case CIMTYPE_UINT32:            CIMValueType<Uint32>::setNull(_rep, type, isArray, arraySize);            break;        case CIMTYPE_SINT32:            CIMValueType<Sint32>::setNull(_rep, type, isArray, arraySize);            break;        case CIMTYPE_UINT64:            CIMValueType<Uint64>::setNull(_rep, type, isArray, arraySize);            break;        case CIMTYPE_SINT64:            CIMValueType<Sint64>::setNull(_rep, type, isArray, arraySize);            break;        case CIMTYPE_REAL32:            CIMValueType<Real32>::setNull(_rep, type, isArray, arraySize);            break;        case CIMTYPE_REAL64:            CIMValueType<Real64>::setNull(_rep, type, isArray, arraySize);            break;        case CIMTYPE_CHAR16:            CIMValueType<Char16>::setNull(_rep, type, isArray, arraySize);            break;        case CIMTYPE_STRING:            CIMValueType<String>::setNull(_rep, type, isArray, arraySize);            break;        case CIMTYPE_DATETIME:            CIMValueType<CIMDateTime>::setNull(_rep, type, isArray, arraySize);            break;        case CIMTYPE_REFERENCE:            CIMValueType<CIMObjectPath>::setNull(_rep, type, isArray,arraySize);            break;        case CIMTYPE_OBJECT:            CIMValueType<CIMObject>::setNull(_rep, type, isArray, arraySize);            break;#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT        case CIMTYPE_INSTANCE:            CIMValueType<CIMInstance>::setNull(_rep, type, isArray, arraySize);            break;#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT        default:            PEGASUS_ASSERT(0);    }}CIMValue::CIMValue(Boolean x){    _rep = new CIMValueRep;    CIMValueType<Boolean>::set(_rep, x);}CIMValue::CIMValue(Uint8 x){    _rep = new CIMValueRep;    CIMValueType<Uint8>::set(_rep, x);}CIMValue::CIMValue(Sint8 x){    _rep = new CIMValueRep;    CIMValueType<Sint8>::set(_rep, x);}CIMValue::CIMValue(Uint16 x){    _rep = new CIMValueRep;    CIMValueType<Uint16>::set(_rep, x);}CIMValue::CIMValue(Sint16 x){    _rep = new CIMValueRep;    CIMValueType<Sint16>::set(_rep, x);}CIMValue::CIMValue(Uint32 x){    _rep = new CIMValueRep;    CIMValueType<Uint32>::set(_rep, x);}CIMValue::CIMValue(Sint32 x){    _rep = new CIMValueRep;    CIMValueType<Sint32>::set(_rep, x);}CIMValue::CIMValue(Uint64 x){    _rep = new CIMValueRep;    CIMValueType<Uint64>::set(_rep, x);}CIMValue::CIMValue(Sint64 x){    _rep = new CIMValueRep;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -