CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/CommonTools/Utils/interface/expressionParser.h

Go to the documentation of this file.
00001 #ifndef CommonTools_Utils_expressionParset_h
00002 #define CommonTools_Utils_expressionParset_h
00003 #include "CommonTools/Utils/src/ExpressionPtr.h"
00004 #include "CommonTools/Utils/src/Grammar.h"
00005 #include "FWCore/Utilities/interface/EDMException.h"
00006 #include <string>
00007 
00008 namespace reco {
00009   namespace parser {
00010     template<typename T>
00011     bool expressionParser( const std::string & value, ExpressionPtr & expr, bool lazy=false) {
00012       using namespace boost::spirit::classic;
00013       Grammar grammar(expr, (const T*)(0), lazy);
00014       bool returnValue = false;
00015       const char* startingFrom = value.c_str();
00016       try {
00017          returnValue=parse(startingFrom, grammar.use_parser<1>() >> end_p, space_p).full;
00018       } catch(BaseException&e){
00019          throw edm::Exception(edm::errors::Configuration)<<"Expression parser error:"<<baseExceptionWhat(e)<<" (char "<<e.where-startingFrom<<")\n";
00020       }
00021       return returnValue;
00022     }
00023   }
00024 }
00025 
00026 #endif