📄 cqlfunctionrep.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.////==============================================================================//// Authors: David Rosckes (rosckes@us.ibm.com)// Bert Rivero (hurivero@us.ibm.com)// Chuck Carmack (carmack@us.ibm.com)// Brian Lucier (lucier@us.ibm.com)//// Modified By: Vijay Eli, IBM (vijayeli@in.ibm.com) bug#3590////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/CQL/CQLFunctionRep.h>// CQL includes#include <Pegasus/CQL/CQLFactory.h>#include <Pegasus/CQL/CQLUtilities.h>#include <Pegasus/CQL/CQLValue.h>#include <Pegasus/CQL/CQLValueRep.h>// Common Query includes#include <Pegasus/Query/QueryCommon/QueryContext.h>// Common Pegasus includes#include <Pegasus/Common/CIMName.h>#include <Pegasus/Common/CIMObjectPath.h>#include <Pegasus/Common/Tracer.h>PEGASUS_NAMESPACE_BEGINCQLFunctionRep::CQLFunctionRep(): _funcOpType(UNKNOWN), _parms() {}CQLFunctionRep::CQLFunctionRep(CQLIdentifier inOpType, Array<CQLPredicate> inParms): _funcOpType(UNKNOWN), _parms(inParms){ PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::CQLFunctionRep()"); String opType(inOpType.getName().getString()); if(String::compareNoCase(opType,String("DATETIMETOMICROSECOND")) == 0){ _funcOpType = DATETIMETOMICROSECOND; } else if(String::compareNoCase(opType, String("STRINGTOUINT")) == 0){ _funcOpType = STRINGTOUINT; } else if(String::compareNoCase(opType, String("STRINGTOSINT")) == 0){ _funcOpType = STRINGTOSINT; } else if(String::compareNoCase(opType, String("STRINGTOREAL")) == 0){ _funcOpType = STRINGTOREAL; } else if(String::compareNoCase(opType, String("STRINGTONUMERIC")) == 0){ _funcOpType = STRINGTONUMERIC; } else if(String::compareNoCase(opType, String("UPPERCASE")) == 0){ _funcOpType = UPPERCASE; } else if(String::compareNoCase(opType, String("NUMERICTOSTRING")) == 0){ _funcOpType = NUMERICTOSTRING; } else if(String::compareNoCase(opType, String("REFERENCETOSTRING")) == 0){ _funcOpType = REFERENCETOSTRING; } else if(String::compareNoCase(opType, String("CLASSNAME")) == 0){ _funcOpType = CLASSNAME; } else if(String::compareNoCase(opType, String("NAMESPACENAME")) == 0){ _funcOpType = NAMESPACENAME; } else if(String::compareNoCase(opType, String("NAMESPACETYPE")) == 0){ _funcOpType = NAMESPACETYPE; } else if(String::compareNoCase(opType, String("HOSTPORT")) == 0){ _funcOpType = HOSTPORT; } else if(String::compareNoCase(opType, String("MODELPATH")) == 0){ _funcOpType = MODELPATH; } else if(String::compareNoCase(opType, String("CLASSPATH")) == 0){ _funcOpType = CLASSPATH; } else if(String::compareNoCase(opType, String("OBJECTPATH")) == 0){ _funcOpType = OBJECTPATH; } else if(String::compareNoCase(opType, String("INSTANCETOREFERENCE")) == 0){ _funcOpType = INSTANCETOREFERENCE; } else if(String::compareNoCase(opType, String("CURRENTDATETIME")) == 0){ _funcOpType = CURRENTDATETIME; } else if(String::compareNoCase(opType, String("DATETIME")) == 0){ _funcOpType = DATETIME; } else if(String::compareNoCase(opType, String("MICROSECONDTOTIMESTAMP")) == 0){ _funcOpType = MICROSECONDTOTIMESTAMP; } else if(String::compareNoCase(opType, String("MICROSECONDTOINTERVAL")) == 0){ _funcOpType = MICROSECONDTOINTERVAL; } else { // Unknown function MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_FUNCTION"), String("Function: $0 is not a supported function."), opType); throw CQLSyntaxErrorException(mload); } PEG_METHOD_EXIT();}CQLFunctionRep::CQLFunctionRep(const CQLFunctionRep* rep) : _funcOpType(rep->_funcOpType), _parms(rep->_parms){}CQLFunctionRep::~CQLFunctionRep(){}CQLValue CQLFunctionRep::resolveValue(const CIMInstance& CI,const QueryContext& queryCtx){ switch(_funcOpType) { case DATETIMETOMICROSECOND: return dateTimeToMicrosecond(CI, queryCtx); case STRINGTOUINT: return stringToUint(CI, queryCtx); case STRINGTOSINT: return stringToSint(CI, queryCtx); case STRINGTOREAL: return stringToReal(CI, queryCtx); case STRINGTONUMERIC: return stringToNumeric(CI, queryCtx); case UPPERCASE: return upperCase(CI, queryCtx); case NUMERICTOSTRING: return numericToString(CI, queryCtx); case REFERENCETOSTRING: return referenceToString(CI, queryCtx); case CLASSNAME: return className(CI, queryCtx); case NAMESPACENAME: return nameSpaceName(CI, queryCtx); case NAMESPACETYPE: return nameSpaceType(CI, queryCtx); case HOSTPORT: return hostPort(CI, queryCtx); case MODELPATH: return modelPath(CI, queryCtx); case CLASSPATH: return classPath(CI, queryCtx); case OBJECTPATH: return objectPath(CI, queryCtx); case INSTANCETOREFERENCE: return instanceToReference(CI, queryCtx); case CURRENTDATETIME: return currentDateTime(); case DATETIME: return dateTime(CI, queryCtx); case MICROSECONDTOTIMESTAMP: return microsecondToTimestamp(CI, queryCtx); case MICROSECONDTOINTERVAL: return microsecondToInterval(CI, queryCtx); case UNKNOWN: { // Unknown function char buf[10]; sprintf(buf, "%d", _funcOpType); MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_FUNCTION_ID"), String("Function ID: $0 is not a supported function ID."), String(buf)); throw CQLSyntaxErrorException(mload); } } // Unknown function char buf[10]; sprintf(buf, "%d", _funcOpType); MessageLoaderParms mload(String("CQL.CQLFunctionRep.INVALID_FUNCTION_ID"), String("Function ID: $0 is not a supported function ID."), String(buf)); throw CQLSyntaxErrorException(mload);}String CQLFunctionRep::toString() const{ String returnStr = functionTypeToString(); returnStr.append("("); Uint32 parmSize = _parms.size(); for(Uint32 i = 0; i < parmSize; ++i) { returnStr.append(_parms[i].toString()); if (i+1 < parmSize) returnStr.append(", "); } returnStr.append(")"); return returnStr;}String CQLFunctionRep::functionTypeToString() const{ String returnStr; switch(_funcOpType) { case DATETIMETOMICROSECOND: returnStr.append("DATETIMETOMICROSECOND"); break; case STRINGTOUINT: returnStr.append("STRINGTOUINT"); break; case STRINGTOSINT: returnStr.append("STRINGTOSINT"); break; case STRINGTOREAL: returnStr.append("STRINGTOREAL"); break; case STRINGTONUMERIC: returnStr.append("STRINGTONUMERIC"); break; case UPPERCASE: returnStr.append("UPPERCASE"); break; case NUMERICTOSTRING: returnStr.append("NUMERICTOSTRING"); break; case REFERENCETOSTRING: returnStr.append("REFERENCETOSTRING"); break; case CLASSNAME: returnStr.append("CLASSNAME"); break; case NAMESPACENAME: returnStr.append("NAMESPACENAME"); break; case NAMESPACETYPE: returnStr.append("NAMESPACETYPE"); break; case HOSTPORT: returnStr.append("HOSTPORT"); break; case MODELPATH: returnStr.append("MODELPATH"); break; case CLASSPATH: returnStr.append("CLASSPATH"); break; case OBJECTPATH: returnStr.append("OBJECTPATH"); break; case INSTANCETOREFERENCE: returnStr.append("INSTANCETOREFERENCE"); break; case CURRENTDATETIME: returnStr.append("CURRENTDATETIME"); break; case DATETIME: returnStr.append("DATETIME"); break; case MICROSECONDTOTIMESTAMP: returnStr.append("MICROSECONDTOTIMESTAMP"); break; case MICROSECONDTOINTERVAL: returnStr.append("MICROSECONDTOINTERVAL"); break; case UNKNOWN: returnStr.append("UNKNOWN"); default: returnStr.append("UNKNOWN"); break; } return returnStr;}Array<CQLPredicate> CQLFunctionRep::getParms()const{ return _parms;}FunctionOpType CQLFunctionRep::getFunctionType()const{ return _funcOpType;} void CQLFunctionRep::applyContext(const QueryContext& inContext){ PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::applyContext()"); for(Uint32 i = 0; i < _parms.size(); ++i) { _parms[i].applyContext(inContext); } PEG_METHOD_EXIT();}/*Boolean CQLFunctionRep::operator==(const CQLFunctionRep& func)const{ if(_funcOpType != func._funcOpType || _parms.size() != func._parms.size()) { return false; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -