OW_WQLCompile.hpp

Go to the documentation of this file.
00001 //%///////////////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
00003 // Portions Copyright (C) 2003-2004 Vintela, Inc. All rights reserved.
00004 //
00005 // Permission is hereby granted, free of charge, to any person obtaining a copy
00006 // of this software and associated documentation files (the "Software"), to 
00007 // deal in the Software without restriction, including without limitation the 
00008 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
00009 // sell copies of the Software, and to permit persons to whom the Software is
00010 // furnished to do so, subject to the following conditions:
00011 // 
00012 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN 
00013 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
00014 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
00015 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
00016 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
00017 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
00018 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00019 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00020 //
00021 //==============================================================================//
00022 // Author: Markus Mueller (sedgewick_de@yahoo.de)
00023 //
00024 // Modified By: Dan Nuffer
00025 //
00026 //%/////////////////////////////////////////////////////////////////////////////
00027 #ifndef OW_WQLCOMPILE_HPP_INCLUDE_GUARD_H_
00028 #define OW_WQLCOMPILE_HPP_INCLUDE_GUARD_H_
00029 #include "OW_config.h"
00030 #include "OW_Array.hpp"
00031 #include "OW_WQLOperation.hpp"
00032 #include "OW_WQLOperand.hpp"
00033 #include "OW_WQLSelectStatement.hpp"
00034 #include "OW_NoSuchPropertyException.hpp"
00035 
00036 namespace OW_NAMESPACE
00037 {
00038 
00039 class OW_WQLCOMMON_API WQLCompile
00040 {
00041 public:
00042    struct term_el
00043    {
00044       term_el()
00045       {}
00046       term_el(bool mark_, WQLOperation op_, const WQLOperand& opn1_, const WQLOperand& opn2_)
00047          : mark(mark_)
00048          , op(op_)
00049          , opn1(opn1_)
00050          , opn2(opn2_)
00051       {}
00052       
00053       bool mark;
00054       WQLOperation op;
00055       WQLOperand opn1;
00056       WQLOperand opn2;
00057    
00058       void negate();
00059    };
00060    
00061    enum el_type
00062    {
00063       EVAL_HEAP,
00064       TERMINAL_HEAP,
00065       OPERAND
00066    };
00067    struct stack_el
00068    {
00069       stack_el()
00070       {}
00071       stack_el(int opn_, el_type type_)
00072          : opn(opn_)
00073          , type(type_)
00074       {}
00075       int  opn;     // either to terminals or eval_heap
00076       el_type type;
00077    };
00078    
00079    
00080    struct eval_el
00081    {
00082       eval_el()
00083       {}
00084       eval_el(bool mark_, WQLOperation op_, int opn1_, el_type is_terminal1_, int opn2_, el_type is_terminal2_)
00085          : mark(mark_)
00086          , op(op_)
00087          , opn1(opn1_)
00088          , is_terminal1(is_terminal1_)
00089          , opn2(opn2_)
00090          , is_terminal2(is_terminal2_)
00091       {}
00092    
00093       bool mark;
00094       WQLOperation op;
00095       int opn1;
00096       el_type is_terminal1; // if yes, look in terminal Array
00097       int opn2;
00098       el_type is_terminal2; // if no, look in eval heap
00099    
00100       stack_el getFirst();
00101    
00102       stack_el getSecond();
00103    
00104       void setFirst(const stack_el s);
00105       
00106       void setSecond(const stack_el s);
00107       
00108       void assign_unary_to_first(const eval_el & assignee);
00109    
00110       void assign_unary_to_second(const eval_el & assignee);
00111    
00112       // Ordering operators, so that op1 > op2 for all non-terminals
00113       // and terminals appear in the second operand first
00114       void order();
00115    };
00116    
00117    typedef Array<term_el> TableauRow;
00118    
00119    typedef Array<TableauRow> Tableau;
00120    
00121    WQLCompile();
00122    // calls compile()
00123    WQLCompile(const WQLSelectStatement& wqs);
00124    ~WQLCompile();
00125    void compile (const WQLSelectStatement * wqs);
00126    const Tableau& getTableau() const {return _tableau;}
00135    bool evaluate(const WQLPropertySource& source) const;
00136    void print(std::ostream& ostr);
00137    void printTableau(std::ostream& ostr);
00138 private:
00139    void _buildEvalHeap(const WQLSelectStatement * wqs);
00140    void _pushNOTDown();
00141    void _factoring();
00142    void _gatherDisj(Array<stack_el>& stk);
00143    void _gatherConj(Array<stack_el>& stk, stack_el sel);
00144    void _gather(Array<stack_el>& stk, stack_el sel, bool or_flag);
00145    void _sortTableau();
00146    static inline void _ResolveProperty(
00147       WQLOperand& op,
00148       const WQLPropertySource& source)
00149    {
00150       //
00151       // Resolve the operand: if it's a property name, look up its value:
00152       //
00153       if (op.getType() == WQLOperand::PROPERTY_NAME)
00154       {
00155          const String& propertyName = op.getPropertyName();
00156          if (!source.getValue(propertyName, op))
00157             OW_THROW(NoSuchPropertyException, "No such property");
00158       }
00159    }
00160 
00161 #ifdef OW_WIN32
00162 #pragma warning (push)
00163 #pragma warning (disable: 4251)
00164 #endif
00165 
00166    // Structure to contain the compiled DNF form
00167    Tableau _tableau;
00168    //
00169    // The eval_heap structure contains an ordered tree of non-terminal
00170    // expressions, the term_heap structure the corresponding terminal
00171    // expressions
00172    //
00173    Array<term_el> terminal_heap;
00174    Array<eval_el> eval_heap;
00175 
00176 #ifdef OW_WIN32
00177 #pragma warning (pop)
00178 #endif
00179 
00180 };
00181 OW_WQLCOMMON_API bool operator==(const WQLCompile::term_el& x, const WQLCompile::term_el& y);
00182 OW_WQLCOMMON_API bool operator!=(const WQLCompile::term_el& x, const WQLCompile::term_el& y);
00183 
00184 } // end namespace OW_NAMESPACE
00185 
00186 #endif

Generated on Thu Feb 9 08:48:17 2006 for openwbem by  doxygen 1.4.6