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

📄 cqlfunctionrep.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//  for(Uint32 i = 0; i < _parms.size(); ++i)//  {//    if(!(_parms[i] == func._parms[i]))//    {//      return false;//    }//  }  return true;}Boolean CQLFunctionRep::operator!=(const CQLFunctionRep& func)const{	return (!operator==(func));}*/CQLValue CQLFunctionRep::dateTimeToMicrosecond(const CIMInstance& CI, const QueryContext& queryCtx) const{  PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::dateTimeToMicrosecond()");    if(_parms.size() != 1)  {    char buf[10];    sprintf(buf, "%d", _parms.size());    MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_COUNT"),                             String("Function $0 has $1 parameters.  It must have between $2 and $3."),                             functionTypeToString(),                             String(buf),                             String("1"), String("1"));    throw CQLRuntimeException(mload);  }  // resolve the parameter  CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().resolveValue(CI,queryCtx);  if(cqlVal.getValueType() != CQLValue::CIMDateTime_type)  {    MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_TYPE"),                             String("Parameter $0 for function $1 has type $2.  It must be type $3."),                             String("1"),                             functionTypeToString(),                             CQLValueRep::valueTypeToString(cqlVal.getValueType()),                             CQLValueRep::valueTypeToString(CQLValue::CIMDateTime_type));    throw CQLRuntimeException(mload);  }  PEG_METHOD_EXIT();  return CQLValue(cqlVal.getDateTime().toMicroSeconds()); }CQLValue CQLFunctionRep::stringToUint(const CIMInstance& CI, const QueryContext& queryCtx) const{  PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::stringToUint()");  if(_parms.size() != 1)  {    char buf[10];    sprintf(buf, "%d", _parms.size());    MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_COUNT"),                             String("Function $0 has $1 parameters.  It must have between $2 and $3."),                             functionTypeToString(),                             String(buf),                             String("1"), String("1"));    throw CQLRuntimeException(mload);  }  CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().resolveValue(CI,queryCtx);  if(cqlVal.getValueType() != CQLValue::String_type)  {    MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_TYPE"),                             String("Parameter $0 for function $1 has type $2.  It must be type $3."),                             String("1"),                             functionTypeToString(),                             CQLValueRep::valueTypeToString(cqlVal.getValueType()),                             CQLValueRep::valueTypeToString(CQLValue::String_type));    throw CQLRuntimeException(mload);  }  PEG_METHOD_EXIT();  return CQLValue(CQLUtilities::stringToUint64(cqlVal.getString()));}CQLValue CQLFunctionRep::stringToSint(const CIMInstance& CI, const QueryContext& queryCtx) const{  PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::stringToSint()");  if(_parms.size() != 1)  {    char buf[10];    sprintf(buf, "%d", _parms.size());    MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_COUNT"),                             String("Function $0 has $1 parameters.  It must have between $2 and $3."),                             functionTypeToString(),                             String(buf),                             String("1"), String("1"));    throw CQLRuntimeException(mload);  }  CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().resolveValue(CI,queryCtx);  if(cqlVal.getValueType() != CQLValue::String_type)  {    MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_TYPE"),                             String("Parameter $0 for function $1 has type $2.  It must be type $3."),                             String("1"),                             functionTypeToString(),                             CQLValueRep::valueTypeToString(cqlVal.getValueType()),                             CQLValueRep::valueTypeToString(CQLValue::String_type));    throw CQLRuntimeException(mload);  }  PEG_METHOD_EXIT();  return CQLValue(CQLUtilities::stringToSint64(cqlVal.getString()));}CQLValue CQLFunctionRep::stringToReal(const CIMInstance& CI, const QueryContext& queryCtx) const{  PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::stringToReal()");  if(_parms.size() != 1)  {    char buf[10];    sprintf(buf, "%d", _parms.size());    MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_COUNT"),                             String("Function $0 has $1 parameters.  It must have between $2 and $3."),                             functionTypeToString(),                             String(buf),                             String("1"), String("1"));    throw CQLRuntimeException(mload);  }  CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().resolveValue(CI,queryCtx);  if(cqlVal.getValueType() != CQLValue::String_type)  {    MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_TYPE"),                             String("Parameter $0 for function $1 has type $2.  It must be type $3."),                             String("1"),                             functionTypeToString(),                             CQLValueRep::valueTypeToString(cqlVal.getValueType()),                             CQLValueRep::valueTypeToString(CQLValue::String_type));    throw CQLRuntimeException(mload);  }    PEG_METHOD_EXIT();  return CQLValue(CQLUtilities::stringToReal64(cqlVal.getString()));}CQLValue CQLFunctionRep::stringToNumeric(const CIMInstance& CI, const QueryContext& queryCtx) const{   return stringToReal(CI, queryCtx);}CQLValue CQLFunctionRep::upperCase(const CIMInstance& CI, const QueryContext& queryCtx) const{  PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::upperCase()");  if(_parms.size() != 1)  {    char buf[10];    sprintf(buf, "%d", _parms.size());    MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_COUNT"),                             String("Function $0 has $1 parameters.  It must have between $2 and $3."),                             functionTypeToString(),                             String(buf),                             String("1"), String("1"));    throw CQLRuntimeException(mload);  }  CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().resolveValue(CI,queryCtx);  if(cqlVal.getValueType() != CQLValue::String_type)  {    MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_TYPE"),                             String("Parameter $0 for function $1 has type $2.  It must be type $3."),                             String("1"),                             functionTypeToString(),                             CQLValueRep::valueTypeToString(cqlVal.getValueType()),                             CQLValueRep::valueTypeToString(CQLValue::String_type));    throw CQLRuntimeException(mload);  }  String tmpStr = cqlVal.getString();  tmpStr.toUpper();  PEG_METHOD_EXIT();  return CQLValue(tmpStr);}CQLValue CQLFunctionRep::numericToString(const CIMInstance& CI, const QueryContext& queryCtx) const{  PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::numericToString()");  char buffer[128];  if(_parms.size() != 1)  {    char buf[10];    sprintf(buf, "%d", _parms.size());    MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_COUNT"),                             String("Function $0 has $1 parameters.  It must have between $2 and $3."),                             functionTypeToString(),                             String(buf),                             String("1"), String("1"));    throw CQLRuntimeException(mload);  }  CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().resolveValue(CI,queryCtx);    CQLValue::CQLValueType valType = cqlVal.getValueType();    if (valType == CQLValue::Sint64_type)  {    sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "d", cqlVal.getSint());  }  else if (valType == CQLValue::Uint64_type)  {    sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", cqlVal.getUint());  }  else if (valType == CQLValue::Real_type)    sprintf(buffer, "%.16E", cqlVal.getReal());  else  {    MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_TYPE"),                             String("Parameter $0 for function $1 has type $2.  It must be type $3."),                             String("1"),                             functionTypeToString(),                             CQLValueRep::valueTypeToString(cqlVal.getValueType()),                             String("Integer or Real"));    throw CQLRuntimeException(mload);  }  String num(buffer);  if (valType == CQLValue::Real_type)  {    // format the exponent    num = CQLUtilities::formatRealStringExponent(num);  }    PEG_METHOD_EXIT();  return CQLValue(num);}CQLValue CQLFunctionRep::referenceToString(const CIMInstance& CI, const QueryContext& queryCtx) const{  PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::referenceToString()");  if(_parms.size() != 1)  {    char buf[10];    sprintf(buf, "%d", _parms.size());    MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_COUNT"),                             String("Function $0 has $1 parameters.  It must have between $2 and $3."),                             functionTypeToString(),                             String(buf),                             String("1"), String("1"));    throw CQLRuntimeException(mload);  }  CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().resolveValue(CI,queryCtx);  if (cqlVal.getValueType() == CQLValue::CIMReference_type)  {    PEG_METHOD_EXIT();    return CQLValue(cqlVal.getReference().toString());  }    if (cqlVal.getValueType() == CQLValue::CIMObject_type)  {    PEG_METHOD_EXIT();    return CQLValue(cqlVal.getObject().getPath().toString());  }    // If it makes it to this block of code, then no valid type was found, and hence no return was made.  Throw invalid parameter type exception.  {    MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_TYPE"),                             String("Parameter $0 for function $1 has type $2.  It must be type $3."),                             String("1"),                             functionTypeToString(),                             CQLValueRep::valueTypeToString(cqlVal.getValueType()),                             String("Reference, or Object"));    throw CQLRuntimeException(mload);  }}CQLValue CQLFunctionRep::className(const CIMInstance& CI, const QueryContext& queryCtx) const{  PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::className()");  int parmSize = _parms.size();  if(parmSize != 0 && parmSize != 1)  {    char buf[10];    sprintf(buf, "%d", _parms.size());    MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_PARM_COUNT"),                             String("Function $0 has $1 parameters.  It must have between $2 and $3."),                             functionTypeToString(),                             String(buf),                             String("0"), String("1"));    throw CQLRuntimeException(mload);  }  // If there are no parameters, the default behavior is to return the class name for the instance being examined (CI).  if (parmSize == 0)  {    PEG_METHOD_EXIT();    //printf("ClassName --> %s\n", (const char *)CI.getClassName().getString().getCString());    return CQLValue(CI.getClassName().getString());  }  // We have a parameter, so resolve it first before we use it.  CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().resolveValue(CI,queryCtx);  // If we have a String parameter, then we'll use it to create a CIMObjectPath in order to verify the format is correct.  We will then get the class from the object path and return it.  if (cqlVal.getValueType() == CQLValue::String_type)  {    CIMObjectPath objPath(cqlVal.getString());    PEG_METHOD_EXIT();    //printf("ClassName --> %s\n", (const char *)objPath.getClassName().getString().getCString());    return CQLValue(objPath.getClassName().getString());  }  // If we have a CIMReference parameter, then we will just get the class name from the reference and return it.  A refernce is a CIMObjectPath.  if (cqlVal.getValueType() == CQLValue::CIMReference_type)  {    PEG_METHOD_EXIT();    //printf("ClassName --> %s\n", (const char *)cqlVal.getReference().getClassName().getString().getCString());    return CQLValue(cqlVal.getReference().getClassName().getString());  }  // If we have a CIMObject, then we return the class name of the obejct  if (cqlVal.getValueType() == CQLValue::CIMObject_type)  {    PEG_METHOD_EXIT();

⌨️ 快捷键说明

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