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

📄 wqlselectstatementrep.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	    }	    case WQL_AND:	    {		PEGASUS_ASSERT(stack.size() >= 2);		Boolean op1 = stack.top();		stack.pop();		Boolean op2 = stack.top();		stack.top() = op1 && op2;		break;	    }	    case WQL_NOT:	    {		PEGASUS_ASSERT(stack.size() >= 1);		Boolean op = stack.top();		stack.top() = !op;		break;	    }	    case WQL_EQ:	    case WQL_NE:	    case WQL_LT:	    case WQL_LE:	    case WQL_GT:	    case WQL_GE:	    {		Array<WQLOperand> whereOperands(_operands);		PEGASUS_ASSERT(whereOperands.size() >= 2);		//		// Resolve the left-hand-side to a value (if not already		// a value).		//		WQLOperand& lhs = whereOperands[j++];		_ResolveProperty(lhs, source);		//		// Resolve the right-hand-side to a value (if not already		// a value).		//		WQLOperand& rhs = whereOperands[j++];		_ResolveProperty(rhs, source);		//		// Check for a type mismatch:		//		// PEGASUS_OUT(lhs.toString());		// PEGASUS_OUT(rhs.toString());		if (rhs.getType() != lhs.getType())		    throw TypeMismatchException();		//		// Now that the types are known to be alike, apply the		// operation:		//		stack.push(_Evaluate(lhs, rhs, op));		break;	    }	    case WQL_IS_TRUE:	    case WQL_IS_NOT_FALSE:	    {		PEGASUS_ASSERT(stack.size() >= 1);		break;	    }	    case WQL_IS_FALSE:	    case WQL_IS_NOT_TRUE:	    {		PEGASUS_ASSERT(stack.size() >= 1);		stack.top() = !stack.top();		break;	    }	    case WQL_IS_NULL:	    {		Array<WQLOperand> whereOperands(_operands);		PEGASUS_ASSERT(whereOperands.size() >= 1);		WQLOperand& op = whereOperands[j++];		_ResolveProperty(op, source);		stack.push(op.getType() == WQLOperand::NULL_VALUE);		break;	    }	    case WQL_IS_NOT_NULL:	    {		Array<WQLOperand> whereOperands(_operands);		PEGASUS_ASSERT(whereOperands.size() >= 1);		WQLOperand& op = whereOperands[j++];		_ResolveProperty(op, source);		stack.push(op.getType() != WQLOperand::NULL_VALUE);		break;	    }	}    }    PEGASUS_ASSERT(stack.size() == 1);    return stack.top();}template<class T>inline void wqlSelectStatementApplyProjection(    T& object,    Boolean allowMissing,    const Array<CIMName>& selectPropertyNames){    for (int i=object.getPropertyCount(); i!=0; i--)    {        CIMName pn=object.getProperty(i-1).getName();        Boolean foundInSel = false;        for (int ii=0,mm=selectPropertyNames.size(); ii<mm; ii++)        {            if (selectPropertyNames[ii]==pn)            {               foundInSel = true;               break;            }        }        if (!foundInSel)        {            object.removeProperty(i-1);        }    }    //check for properties on select list missing from the instance    if (!allowMissing)    {        Boolean foundInInst;        for (Uint32 i=0; i < selectPropertyNames.size(); i++)        {            foundInInst = false;            CIMName sn=selectPropertyNames[i];            for (Uint32 j = object.getPropertyCount(); j != 0; j--)            {                CIMName in = object.getProperty(j-1).getName();                if (sn == in) foundInInst = true;            }            if(!foundInInst)            {                MessageLoaderParms parms                    ("WQL.WQLSelectStatementRep.MISSING_PROPERTY_ON_INSTANCE",                    "A property in the Select list is missing from the "                    "instance");                throw QueryRuntimePropertyException(parms);            }        }    }}void WQLSelectStatementRep::applyProjection(CIMInstance& ci,    Boolean allowMissing){    if (_allProperties)    {        return;    }    wqlSelectStatementApplyProjection(ci, allowMissing, _selectPropertyNames);}void WQLSelectStatementRep::applyProjection(CIMObject& ci,    Boolean allowMissing){    if (_allProperties)    {        return;    }    wqlSelectStatementApplyProjection(ci, allowMissing, _selectPropertyNames);}void WQLSelectStatementRep::print() const{    //    // Print the header:    //    cout << "WQLSelectStatement" << endl;    cout << "{" << endl;    //    // Print the class name:    //    cout << "    _className: \"" << _className.getString() << '"' << endl;    //    // Print the select properties:    //    if (_allProperties)    {        cout << endl;        cout << "    _allProperties: TRUE" << endl;    }    else for (Uint32 i = 0; i < _selectPropertyNames.size(); i++)    {	if (i == 0)	    cout << endl;	cout << "    _selectPropertyNames[" << i << "]: ";	cout << '"' << _selectPropertyNames[i].getString() << '"' << endl;    }    //    // Print the operations:    //    for (Uint32 i = 0; i < _operations.size(); i++)    {        if (i == 0)            cout << endl;        cout << "    _operations[" << i << "]: ";        cout << '"' << WQLOperationToString(_operations[i]) << '"' << endl;    }    //    // Print the operands:    //    for (Uint32 i = 0; i < _operands.size(); i++)    {        if (i == 0)	    cout << endl;	cout << "    _operands[" << i << "]: ";	cout << '"' << _operands[i].toString() << '"' << endl;    }    //    // Print the trailer:    //    cout << "}" << endl;}Boolean WQLSelectStatementRep::evaluate(const CIMInstance& inCI){	WQLInstancePropertySource source(inCI);	return evaluateWhereClause(&source);}void WQLSelectStatementRep::validate(){	if(_ctx == NULL){		MessageLoaderParms parms("WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL",                               "Trying to process a query with a NULL Query Context.");      throw QueryValidationException(parms);   }	CIMClass fromClass;	try   {     fromClass = _ctx->getClass(_className);    CIMObjectPath className (String::EMPTY, _ctx->getNamespace (), _className);     Array<CIMName> whereProps =        getWherePropertyList(className).getPropertyNameArray();     Array<CIMName> selectProps =        getSelectPropertyList(className).getPropertyNameArray();     // make sure all properties match properties on the from class     for(Uint32 i = 0; i < whereProps.size(); i++){         Uint32 index = fromClass.findProperty(whereProps[i]);			if(index == PEG_NOT_FOUND){				MessageLoaderParms parms("WQL.WQLSelectStatementRep.PROP_NOT_FOUND",                                     "The property $0 was not found in the FROM class $1",                                     whereProps[i].getString(),                                     fromClass.getClassName().getString());            throw QueryMissingPropertyException(parms);			}         else         {           //           //  Property exists in class           //  Verify it is not an array property           //           CIMProperty classProperty = fromClass.getProperty(index);           if (classProperty.isArray ())           {             MessageLoaderParms parms("WQL.WQLSelectStatementRep.WHERE_PROP_IS_ARRAY",                                      "Array property $0 is not supported in the WQL WHERE clause.",                                     whereProps[i].getString());             throw QueryValidationException(parms);           }         }		}     for(Uint32 i = 0; i < selectProps.size(); i++){       if(fromClass.findProperty(selectProps[i]) == PEG_NOT_FOUND){         MessageLoaderParms parms("WQL.WQLSelectStatementRep.PROP_NOT_FOUND",                                  "The property $0 was not found in the FROM class $1",                                  selectProps[i].getString(),                                  fromClass.getClassName().getString());         throw QueryMissingPropertyException(parms);       }     }   }   catch (const CIMException& ce)   {     if (ce.getCode() == CIM_ERR_INVALID_CLASS ||         ce.getCode() == CIM_ERR_NOT_FOUND)     {       MessageLoaderParms parms("WQL.WQLSelectStatementRep.CLASSNAME_NOT_IN_REPOSITORY",                                                 "The class name $0 was not found in the repository.",                                                 _className.getString());       throw QueryValidationException(parms);     }     else     {       throw;     }   }}CIMPropertyList WQLSelectStatementRep::getPropertyList(const CIMObjectPath& inClassName){	if(_ctx == NULL){		MessageLoaderParms parms("WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL",                               "Trying to process a query with a NULL Query Context.");      throw QueryRuntimeException(parms);	}	if(_allProperties)     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 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);		}	}	Array<CIMName> names =            getWherePropertyList(inClassName).getPropertyNameArray();	Array<CIMName> selectList =            getSelectPropertyList(inClassName).getPropertyNameArray();	// check for duplicates and remove them	for(Uint32 i = 0; i < names.size(); i++){		for(Uint32 j = 0; j < selectList.size(); j++){			if(names[i] == selectList[j])				selectList.remove(j);        	}	}	names.appendArray(selectList);	CIMPropertyList list = CIMPropertyList();	list.set(names);	return list;}Array<CIMObjectPath> WQLSelectStatementRep::getClassPathList(){	if(_ctx == NULL){		MessageLoaderParms parms("WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL",                                         "Trying to process a query with a NULL Query Context.");      throw QueryRuntimeException(parms);   }	CIMObjectPath path(String::EMPTY, _ctx->getNamespace(), _className);  	Array<CIMObjectPath> paths;  	paths.append(path);  	return paths;}PEGASUS_NAMESPACE_END

⌨️ 快捷键说明

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