ComplementExpression.cpp

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #include <fesa-core/Sorting/ComplementExpression.h>
00004 
00005 #include <cmw-log/Logger.h>
00006 
00007 #include <iostream>
00008 
00009 namespace
00010 {
00011 CMW::Log::Logger& logger = CMW::Log::LoggerFactory::getLogger("FESA.FWK.fesa-core.Sorting.ComplementExpression");
00012 }
00013 
00014 namespace fesa
00015 {
00016 
00017 std::set<HomogeneousDevCol *> ComplementExpression::evaluate()
00018 {
00019     LOG_WARNING_IF(logger, "NOT IMPLEMENTED!");
00020     std::set<HomogeneousDevCol *> referenceSet = pNegatedExpression_->evaluate();
00021     std::set<HomogeneousDevCol *> complementedSet;
00022     return complementedSet;
00023 }
00024 
00025 bool ComplementExpression::match(SortingContext sc)
00026 {
00027     std::string complementExprCandidate = sc.formula_;
00028 
00029     typedef enum
00030     {
00031         initState, parenthesesRemovalState, negateState, endState
00032     } automaton;
00033 
00034     automaton state = initState, newState = initState;
00035     std::string::size_type pos;
00036     while (state != endState)
00037     {
00038         switch (state)
00039         {
00040             case initState:
00041                 newState = parenthesesRemovalState;
00042                 break;
00043             case parenthesesRemovalState:
00044                 // Note: parenthesis-removal shall be made
00045                 // a specific SortingExpression::removeParenthesesAround()
00046                 // function since it is used over and over again...
00047 
00048                 pos = complementExprCandidate.find("(");
00049                 if (pos != 0)
00050                 {
00051                     return false;
00052                 }
00053                 complementExprCandidate.erase(pos, 1);
00054 
00055                 pos = complementExprCandidate.rfind(")");
00056                 if (pos != (complementExprCandidate.length() - 1))
00057                 {
00058                     return false;
00059                 }
00060                 complementExprCandidate.erase(pos, 1);
00061 
00062                 newState = negateState;
00063                 break;
00064             case negateState:
00065             {
00066                 pos = complementExprCandidate.find("not");
00067                 if (pos != 0)
00068                 {
00069                     return false;
00070                 }
00071                 complementExprCandidate.erase(pos, 3);
00072 
00073                 SortingContext aSc;
00074                 aSc.formula_ = complementExprCandidate;
00075                 aSc.className_ = sc.className_;
00076 
00077                 pNegatedExpression_ = SortingExpression::tryMatch(aSc);
00078                 if (pNegatedExpression_ == 0)
00079                 {
00080                     return false;
00081                 }
00082                 newState = endState;
00083                 break;
00084             }
00085             case endState:
00086                 break;
00087         }
00088         state = newState;
00089     }
00090     return true;
00091 }
00092 
00093 ComplementExpression::ComplementExpression():pNegatedExpression_(0){}
00094 
00095 ComplementExpression::~ComplementExpression()
00096 {
00097     if (pNegatedExpression_ != NULL)
00098     {
00099         delete pNegatedExpression_;
00100     }
00101 }
00102 } // fesa

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1