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

📄 cqlvaluerep.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.////==============================================================================//// Author: Dave Rosckes (rosckes@us.ibm.com)//// Modified By: Dan Gorey (djgorey@us.ibm.com)//              Vijay Eli, IBM (vijayeli@in.ibm.com) bug#3590////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/CQL/CQLValue.h>#include <Pegasus/CQL/CQLValueRep.h>#include <Pegasus/Repository/NameSpaceManager.h>#include <Pegasus/Common/CIMClass.h>#include <Pegasus/Common/Tracer.h>#include <Pegasus/CQL/CQLIdentifier.h>#include <Pegasus/CQL/CQLRegularExpression.h>#include <Pegasus/CQL/CQLFactory.h>#include <Pegasus/Query/QueryCommon/QueryException.h>#include <Pegasus/CQL/CQLUtilities.h>PEGASUS_NAMESPACE_BEGINPEGASUS_USING_STD;/*#define PEGASUS_ARRAY_T CQLValueRep#include <Pegasus/Common/ArrayImpl.h>#undef PEGASUS_ARRAY_T*/#define PEGASUS_SINT64_MIN (PEGASUS_SINT64_LITERAL(0x8000000000000000))#define PEGASUS_UINT64_MAX PEGASUS_UINT64_LITERAL(0xFFFFFFFFFFFFFFFF)CQLValueRep::CQLValueRep()  :_theValue(),_CQLChainId(),_isResolved(false),_valueType(CQLValue::Null_type){}CQLValueRep::~CQLValueRep(){}CQLValueRep::CQLValueRep(const CQLValueRep& val): _theValue(val._theValue), _CQLChainId(val._CQLChainId), _isResolved(val._isResolved), _valueType(val._valueType), _ArrayType(val._ArrayType){  }CQLValueRep::CQLValueRep(const CQLValueRep* val): _theValue(val->_theValue), _CQLChainId(val->_CQLChainId), _isResolved(val->_isResolved), _valueType(val->_valueType), _ArrayType(val->_ArrayType){}CQLValueRep::CQLValueRep(const String& inString, CQLValue::NumericType inValueType, Boolean inSign){   PEG_METHOD_ENTER(TRC_CQL, "CQLValueRep::CQLValueRep()");   switch(inValueType)   {   case CQLValue::Hex:     {       String tmp(inString);       if(inSign)	 {	   _theValue.set(CQLUtilities::stringToUint64(tmp));	   _valueType = CQLValue::Uint64_type;	 }       else	 {	   _theValue.set(CQLUtilities::stringToSint64(inString));	   _valueType = CQLValue::Sint64_type;	 }     }     break;   case CQLValue::Binary:     {       String tmp(inString);;       if(inSign)	 {	   _theValue.set(CQLUtilities::stringToUint64(tmp));	   _valueType = CQLValue::Uint64_type;	 }       else	 {	   _theValue.set(CQLUtilities::stringToSint64(tmp));	   _valueType = CQLValue::Sint64_type;	 }       break;     }   case CQLValue::Decimal:     {       String tmp(inString);       if(inSign)	 {	   _theValue.set(CQLUtilities::stringToUint64(tmp));	   _valueType = CQLValue::Uint64_type;	 }       else	 {	   _theValue.set(CQLUtilities::stringToSint64(tmp));	   _valueType = CQLValue::Sint64_type;	 }     }     break;   case CQLValue::Real:     {       String tmp(inString);       _theValue.set(CQLUtilities::stringToReal64(tmp));       _valueType = CQLValue::Real_type;     }     break;   default:     MessageLoaderParms mload(String("CQL.CQLValueRep.CONSTRUCTOR_FAILURE"),			      String("Undefined case:$0 in constructor."),			      inValueType);     throw CQLRuntimeException(mload);          break;   }      _isResolved = true;      PEG_METHOD_EXIT();}CQLValueRep::CQLValueRep(const CQLChainedIdentifier& inCQLIdent)  : _CQLChainId(inCQLIdent),     _isResolved(false),    _valueType(CQLValue::CQLIdentifier_type){   }CQLValueRep::CQLValueRep(const String& inString)  : _isResolved(true),     _valueType(CQLValue::String_type){   _theValue.set(inString);}CQLValueRep::CQLValueRep(const CIMInstance& inInstance)  : _isResolved(true),    _valueType(CQLValue::CIMObject_type){  _theValue.set((CIMObject)inInstance);}CQLValueRep::CQLValueRep(const CIMClass& inClass)  : _isResolved(true),    _valueType(CQLValue::CIMObject_type){  _theValue.set((CIMObject)inClass);}CQLValueRep::CQLValueRep(const CIMObject& inObject)  : _isResolved(true),    _valueType(CQLValue::CIMObject_type){  _theValue.set((CIMObject)inObject);}CQLValueRep::CQLValueRep(const CIMObjectPath& inObjPath)  : _isResolved(true),    _valueType(CQLValue::CIMReference_type){   _theValue.set(inObjPath);}CQLValueRep::CQLValueRep(const CIMDateTime& inDateTime)  : _isResolved(true),    _valueType(CQLValue::CIMDateTime_type){   _theValue.set(inDateTime);}CQLValueRep::CQLValueRep(Uint64 inUint)  : _isResolved(true),    _valueType(CQLValue::Uint64_type){   _theValue.set(inUint);}CQLValueRep::CQLValueRep(Boolean inBool)  : _isResolved(true),    _valueType(CQLValue::Boolean_type){   _theValue.set(inBool);}CQLValueRep::CQLValueRep(Sint64 inSint)  : _isResolved(true),    _valueType(CQLValue::Sint64_type){   _theValue.set(inSint);}CQLValueRep::CQLValueRep(Real64 inReal)  : _isResolved(true),    _valueType(CQLValue::Real_type){   _theValue.set(inReal);}CQLValueRep::CQLValueRep(const CIMValue& inVal)  : _isResolved(true){  // _valueType is set by _setValue  _setValue(inVal);}void CQLValueRep::resolve(const CIMInstance& CI, const  QueryContext& inQueryCtx){   if(_CQLChainId.size() == 0)    {      return;    }    Array<CQLIdentifier> Idstrings =     _CQLChainId.getSubIdentifiers(); // Array of Identifiers to process  Uint32 IdSize = Idstrings.size();  Uint32 index = 0;                // Counter for looping through Identifiers  CIMProperty propObj;      if(IdSize == 1)    {      // A class was passed in with no property indicated.      // Set the instance passed in, as a primitive.       _theValue.set((CIMObject)CI);      _valueType = CQLValue::CIMObject_type;      _isResolved = true;      return; // Done.    }  else    {      // Symbolic Constant processing      if(_CQLChainId.getLastIdentifier().isSymbolicConstant() &&	 IdSize == 2)	{	  _resolveSymbolicConstant(inQueryCtx);	  return;	}            // Need to increment index since the first Identifier is a class,      // and additional identifiers need processing.      ++index;     }    CIMName classContext = Idstrings[0].getName();  CIMObject objectContext = CI;     for(;index < IdSize; ++index)    {      // Now we need to verify that the property is in the class.      Uint32 propertyIndex = objectContext.findProperty(Idstrings[index].getName());            if(propertyIndex == PEG_NOT_FOUND)	{	  _valueType = CQLValue::Null_type;	  _isResolved = true;	  return;	}            // We will check the property type to determine what processing       // needs to be done.      propObj = objectContext.getProperty(propertyIndex);      try	{	  if((Idstrings[index].isScoped() && inQueryCtx.getClassRelation(Idstrings[index].getScope(),objectContext.getClassName())	      == QueryContext::NOTRELATED) || 	     (Idstrings[index].isScoped() && inQueryCtx.getClassRelation(Idstrings[index].getScope(),objectContext.getClassName())	      == QueryContext::SUPERCLASS)) 	    {	      // The chain is not inline with scope.	      _valueType = CQLValue::Null_type;              _isResolved = true;	      return;	    }	}      catch(const CIMException &)	{	  // The chain is not inline with scope.	  _valueType = CQLValue::Null_type;          _isResolved = true;	  return;	}#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT         CIMType propObjType = propObj.getType();       if(index == IdSize-1)    {        _process_value(propObj,Idstrings[index],inQueryCtx);        return;    }    else if((propObjType != CIMTYPE_OBJECT &&        propObjType != CIMTYPE_INSTANCE) ||        (propObj.getValue().isNull()))    {        // Object is not embedded.        _valueType = CQLValue::Null_type;        _isResolved = true;        return;    }    CIMValue propValue = propObj.getValue();    // If the property is an embeddedInstance, convert to an object    if(propObjType == CIMTYPE_INSTANCE)    {        CIMInstance tmpInst;        propValue.get(tmpInst);        propValue = CIMValue((CIMObject)tmpInst);    }    propValue.get(objectContext);#else    if(index == IdSize-1)    {        _process_value(propObj,Idstrings[index],inQueryCtx);        return;    }    else if((propObj.getType() != CIMTYPE_OBJECT) ||        (propObj.getValue().isNull()))    {        // Object is not embedded.        _valueType = CQLValue::Null_type;        _isResolved = true;        return;    }    propObj.getValue().get(objectContext);#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT		if(!objectContext.isInstance())		{			MessageLoaderParms mparms("CQL.CQLValueRep.OBJECT_CONTEXT_NOT_INSTANCE",			                          "The object context $0 is not an instance.",											  objectContext.getClassName().getString());			throw CQLRuntimeException(mparms);		}      classContext = objectContext.getClassName();    }  } // end of functionvoid CQLValueRep::_process_value(CIMProperty& propObj,				 CQLIdentifier& _id,				 const QueryContext& inQueryCtx){  if(propObj.getType() == CIMTYPE_OBJECT)     {      CIMObject cimObj;      propObj.getValue().get(cimObj);      _theValue.set(cimObj.clone());      _valueType = CQLValue::CIMObject_type;      _isResolved = true;    }#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT  else if(propObj.getType() == CIMTYPE_INSTANCE)   {      CIMInstance cimInstance;      propObj.getValue().get(cimInstance);      _theValue.set((CIMObject)cimInstance.clone());      _valueType = CQLValue::CIMObject_type;      _isResolved = true;  }#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT  else // Primitive    {      if(_id.isArray())	{	  // We have an array property.  All we need to do	  // Is get the index defined by CQLIdentifier.	  // NOTE: Basic CQL support only allows one index.	  _setValue(propObj.getValue(),		    _id.getSubRanges()[0].start);	  return;	}      else if(_id.isSymbolicConstant())	{	  // Symbolic Constant processing	  _resolveSymbolicConstant(inQueryCtx);	  return;	}      else	{	  // The property has no special charactors.	  if(propObj.isArray())	    {	      Uint32 qualIndex = propObj.findQualifier(CIMName(String("ArrayType")));	      if(qualIndex == PEG_NOT_FOUND)		{		  // Default Array type		  _ArrayType = String("Indexed");		}	      else		{		  propObj.getQualifier(qualIndex).getValue().get(_ArrayType);		}	    }	  _setValue(propObj.getValue());	  return;	}    }}CQLValueRep& CQLValueRep::operator=(const CQLValueRep& rhs){  if(&rhs != this)    {      _valueType = rhs._valueType;      _theValue = rhs._theValue;      _CQLChainId = rhs._CQLChainId;      _isResolved = rhs._isResolved;      _ArrayType = rhs._ArrayType;    }  return *this;}Boolean CQLValueRep::operator==(const CQLValueRep& x){  PEG_METHOD_ENTER(TRC_CQL, "CQLValueRep::operator==");  _validate(x);  if(_theValue.isNull() && x._theValue.isNull())    {      return true;    }  if(_theValue.isNull() || x._theValue.isNull())    {      return false;    }  if(_theValue.isArray())    {      return _compareArray(x);    }  else if((_theValue.getType() == x._theValue.getType()) &&     (_valueType != CQLValue::CIMObject_type) &&     (_valueType != CQLValue::CQLIdentifier_type))    {      return _theValue == x._theValue;    }  else    {      Uint64 tmpU64;      Sint64 tmpS64;      Real64 tmpR64;            switch(_valueType)	{	case CQLValue::Null_type:	  {	    if(x._valueType == CQLValue::Null_type)	      {		return true;	      }	  }	  break;	  	case CQLValue::Sint64_type:	  {	    _theValue.get(tmpS64);	    if(x._valueType == CQLValue::Uint64_type)	      {		x._theValue.get(tmpU64);				if(tmpU64 >= (Uint64)PEGASUS_SINT64_MIN)		  {		    return false;		  }		else		  {		    return (Sint64)tmpU64 == tmpS64;		  }	      }	    else 	      {		x._theValue.get(tmpR64);				return tmpR64 == tmpS64;	      }	    break;	  }	case CQLValue::Uint64_type:	  {	    _theValue.get(tmpU64);	    if(x._valueType == CQLValue::Sint64_type)	      {		x._theValue.get(tmpS64);				if(tmpU64 >= (Uint64)PEGASUS_SINT64_MIN)		  {		    return false;		  }		else		  {		    return (Sint64)tmpU64 == tmpS64;		  }	      }	    else 	      {		x._theValue.get(tmpR64);		if(tmpU64 >= (Uint64)PEGASUS_SINT64_MIN)		  {		    return false;		  }		else		  {		    return tmpR64 == (Sint64)tmpU64;		  }	      }	    break;	  }	case CQLValue::Real_type:	  {	    _theValue.get(tmpR64);	    if(x._valueType == CQLValue::Uint64_type)	      {		x._theValue.get(tmpU64);				if(tmpU64 >= (Uint64)PEGASUS_SINT64_MIN)		  {		    return false;		  }		else		  {		    return (Sint64)tmpU64 == tmpR64;		  }	      }	    else 	      {		x._theValue.get(tmpS64);				return tmpR64 == tmpS64;	      }	    break;	  }	case CQLValue::CIMObject_type: 	  { 	    CIMObject objBase;	    CIMObject objParm;	    _theValue.get(objBase);

⌨️ 快捷键说明

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