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

📄 wqlselectstatementrep.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//%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: Mike Brasher (mbrasher@bmc.com)//// Modified By: Carol Ann Krug Graves, Hewlett-Packard Company//                  (carolann_graves@hp.com)//              David Dillard, VERITAS Software Corp.//                  (david.dillard@veritas.com)////%/////////////////////////////////////////////////////////////////////////////#include <iostream>#include <Pegasus/Common/Stack.h>#include "WQLSelectStatementRep.h"#include <Pegasus/Query/QueryCommon/QueryContext.h>#include <Pegasus/Query/QueryCommon/QueryException.h>#include "WQLInstancePropertySource.h"PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGINtemplate<class T>inline static Boolean _Compare(const T& x, const T& y, WQLOperation op){    switch (op)    {	case WQL_EQ:	    return x == y;	case WQL_NE:	    return x != y;	case WQL_LT:	    return x < y;	case WQL_LE:	    return x <= y;	case WQL_GT:	    return x > y;	case WQL_GE:	    return x >= y;	default:	    PEGASUS_ASSERT(0);    }    return false;}static Boolean _Evaluate(    const WQLOperand& lhs,    const WQLOperand& rhs,    WQLOperation op){    switch (lhs.getType())    {	case WQLOperand::NULL_VALUE:	{#ifdef PEGASUS_SNIA_EXTENSIONS            return (rhs.getType() == WQLOperand::NULL_VALUE);#else	    // This cannot happen since expressions of the form	    // OPERAND OPERATOR NULL are converted to unary form.	    // For example: "count IS NULL" is treated as a unary	    // operation in which IS_NULL is the unary operation	    // and count is the the unary operand.	    PEGASUS_ASSERT(0);	    break;#endif	}	case WQLOperand::INTEGER_VALUE:	{	    return _Compare(		lhs.getIntegerValue(),		rhs.getIntegerValue(),		op);	}	case WQLOperand::DOUBLE_VALUE:	{	    return _Compare(		lhs.getDoubleValue(),		rhs.getDoubleValue(),		op);	}	case WQLOperand::BOOLEAN_VALUE:	{	    return _Compare(		lhs.getBooleanValue(),		rhs.getBooleanValue(),		op);	}	case WQLOperand::STRING_VALUE:	{	    return _Compare(		lhs.getStringValue(),		rhs.getStringValue(),		op);	}	default:	    PEGASUS_ASSERT(0);    }    return false;}WQLSelectStatementRep::WQLSelectStatementRep(String& queryLang, String& query)	:SelectStatementRep(queryLang,query){    _operations.reserveCapacity(16);    _operands.reserveCapacity(16);    _allProperties = false;}WQLSelectStatementRep::WQLSelectStatementRep(String& queryLang, String& query, QueryContext& inCtx)        :SelectStatementRep(queryLang,query,inCtx){    _operations.reserveCapacity(16);    _operands.reserveCapacity(16);    _allProperties = false;}WQLSelectStatementRep::WQLSelectStatementRep()	:SelectStatementRep(){    //    // Reserve space for a where clause with up to sixteen terms.    //    _operations.reserveCapacity(16);    _operands.reserveCapacity(16);    _allProperties = false;}WQLSelectStatementRep::WQLSelectStatementRep(const WQLSelectStatementRep& rep)  :SelectStatementRep(rep),   _className(rep._className),   _allProperties(rep._allProperties),   _selectPropertyNames(rep._selectPropertyNames),   _wherePropertyNames(rep._wherePropertyNames),   _operations(rep._operations),   _operands(rep._operands){}WQLSelectStatementRep::~WQLSelectStatementRep(){}void WQLSelectStatementRep::clear(){    _className.clear();    _allProperties = false;    _selectPropertyNames.clear();    _operations.clear();    _operands.clear();}Boolean WQLSelectStatementRep::getAllProperties() const{    return _allProperties;}void WQLSelectStatementRep::setAllProperties(const Boolean allProperties){    _allProperties = allProperties;}const CIMPropertyList WQLSelectStatementRep::getSelectPropertyList    (const CIMObjectPath& inClassName) const{    //    //  Check for "*"    //    if (_allProperties)    {        //        //  Return null CIMPropertyList for all properties        //        return CIMPropertyList ();    }    CIMName className = inClassName.getClassName();    if (className.isNull())    {        //        //  If the caller passed in an empty className, then the FROM class is        //  to be used        //        className = _className;    }    //    //  Check if inClassName is the FROM class    //    if (!(className == _className))    {        //        //  Check for NULL Query Context        //        if (_ctx == NULL)        {            MessageLoaderParms parms                ("WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL",                "Trying to process a query with a NULL Query Context.");            throw QueryRuntimeException(parms);        }        //        //  Check if inClassName is a subclass of the FROM class        //        if (!_ctx->isSubClass(_className,className))        {            MessageLoaderParms parms                ("WQL.WQLSelectStatementRep.CLASS_NOT_FROM_LIST_CLASS",                "Class $0 does not match the FROM class or any of its "                "subclasses.",                className.getString());            throw QueryRuntimeException(parms);        }    }    //    //  Return CIMPropertyList for properties referenced in the projection    //  list (SELECT clause)    //    return CIMPropertyList (_selectPropertyNames);}const CIMPropertyList WQLSelectStatementRep::getWherePropertyList    (const CIMObjectPath& inClassName) const{    CIMName className = inClassName.getClassName();    if (className.isNull())    {        //        //  If the caller passed in an empty className, then the FROM class is        //  to be used        //        className = _className;    }    //    //  Check if inClassName is the FROM class    //    if (!(className == _className))    {        //        //  Check for NULL Query Context        //        if (_ctx == NULL)        {            MessageLoaderParms parms                ("WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL",                "Trying to process a query with a NULL Query Context.");            throw QueryRuntimeException(parms);        }        //        //  Check if inClassName is a subclass of the FROM class        //        if (!_ctx->isSubClass(_className,className))        {            MessageLoaderParms parms                ("WQL.WQLSelectStatementRep.CLASS_NOT_FROM_LIST_CLASS",                "Class $0 does not match the FROM class or any of its "                "subclasses.",                className.getString());            throw QueryRuntimeException(parms);        }    }    //    //  Return CIMPropertyList for properties referenced in the condition    //  (WHERE clause)    //  The list may be empty, but may not be NULL    //    return CIMPropertyList (_wherePropertyNames);}Boolean WQLSelectStatementRep::appendWherePropertyName(const CIMName& x){    //    // Reject duplicate property names by returning false.    //    for (Uint32 i = 0, n = _wherePropertyNames.size(); i < n; i++)    {	if (_wherePropertyNames[i] == x)	    return false;    }    //    // Append the new property.    //    _wherePropertyNames.append(x);    return true;}static inline void _ResolveProperty(    WQLOperand& op,    const WQLPropertySource* source){    //    // Resolve the operand: if it's a property name, look up its value:    //    if (op.getType() == WQLOperand::PROPERTY_NAME)    {	const CIMName& propertyName = op.getPropertyName();	if (!source->getValue(propertyName, op))	    op = WQLOperand();    }}Boolean WQLSelectStatementRep::evaluateWhereClause(    const WQLPropertySource* source) const{    if (!hasWhereClause())	return true;    Stack<Boolean> stack;    stack.reserveCapacity(16);    //    // Counter for operands:    //    Uint32 j = 0;    //    // Process each of the operations:    //    for (Uint32 i = 0, n = _operations.size(); i < n; i++)    {	WQLOperation op = _operations[i];	switch (op)	{	    case WQL_OR:	    {		PEGASUS_ASSERT(stack.size() >= 2);		Boolean op1 = stack.top();		stack.pop();		Boolean op2 = stack.top();		stack.top() = op1 || op2;		break;

⌨️ 快捷键说明

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