/search.css" rel="stylesheet" type="text/css"/> /search.js">
00001 // $Id: ParserUtils.h,v 1.7 2007/09/25 08:02:11 marcocle Exp $ 00002 // ============================================================================ 00003 // CVS tag $Name: GAUDI_v20r4-pre $ 00004 // ============================================================================ 00005 #ifndef JOBOPTIONSSVC_PARSERUTILS_H 00006 #define JOBOPTIONSSVC_PARSERUTILS_H 1 00007 // ============================================================================ 00008 // Include files 00009 // ============================================================================ 00010 // STD & STL 00011 // ============================================================================ 00012 #include <string> 00013 #include <vector> 00014 #include <map> 00015 #include <iostream> 00016 // ============================================================================ 00017 // local 00018 // ============================================================================ 00019 #include "Catalogue.h" 00020 #include "Position.h" 00021 // ============================================================================ 00022 00030 // ============================================================================ 00031 00032 namespace Gaudi 00033 { 00034 namespace Parsers 00035 { 00043 class Message 00044 { 00045 public: 00046 enum Severity 00047 { 00048 E_ERROR = 1 , 00049 E_WARNING = 2 , 00050 E_NOTICE = 3 , 00051 E_VERBOSE = 4 00052 }; 00053 enum Code 00054 { 00055 C_OK = 0 , 00056 C_FILENOTFOUND = 1 , 00057 C_FILENOTOPENED = 2 , 00058 C_SYNTAXERROR = 3 , 00059 C_UNITNOTFOUND = 4 , 00060 C_PROPERTYNOTFOUND = 5 , 00061 C_CANNOTADDTONOTVECTOR = 6 , 00062 C_CANNOTREMOVEFROMNOTVECTOR = 7 , 00063 C_ZEROREMOVED = 8 , 00064 C_BADREFERENCE = 9 00065 }; 00066 public: 00072 Message 00073 ( const Severity& severity, 00074 const Code& code, 00075 const std::string& message) 00076 : m_severity ( severity ) 00077 , m_code ( code ) 00078 , m_message ( message ) 00079 {}; 00081 const std::string& message(void) const{return m_message;} 00083 const Severity& severity(void) const{return m_severity;} 00085 const Code& code(void) const{return m_code;}; 00086 private: 00087 Severity m_severity ; 00088 Code m_code ; 00089 std::string m_message ; 00090 }; 00091 00092 00100 class Parser 00101 { 00102 public: 00103 typedef std::vector<Gaudi::Parsers::Message> MessagesStoreT; 00104 enum Sign 00105 { 00106 S_ASSIGN = 0 , 00107 S_PLUSASSIGN = 1 , 00108 S_MINUSASSIGN = 2 00109 }; 00111 Parser (Catalogue& catalogue, std::vector<std::string>& included, std::ostream& m = std::cout ) ; 00112 00113 public: 00118 bool parse(const std::string& fileName); 00120 const std::vector<Message>& messages(){return m_messages;} 00122 int errorsCount(); 00126 void matchInclude 00127 (const std::string& fileName,const Position& pos); 00135 void matchAssign 00136 (const std::string& objName, 00137 const std::string& propName, 00138 const Sign& oper, 00139 const std::vector<std::string>& vectorValues, 00140 const Position& pos, bool isVector); 00142 void setIsPrint(bool on, const Position& pos); 00144 void setIsPrintOptions(bool on, const Position& pos); 00145 private: 00146 bool m_isPrint; 00147 bool m_isPrintOptions; 00148 Catalogue& m_catalogue; 00149 std::vector<std::string>& m_included; 00150 MessagesStoreT m_messages; 00151 std::ostream& m_stream ; 00152 private: 00158 bool parseFile 00159 ( const std::string& fileName , 00160 const Position& pos); 00162 void resolveReferences(); 00169 void addMessage 00170 ( const Message::Severity& severity, 00171 const Message::Code& code, 00172 const std::string& message, 00173 const Position& pos); 00178 std::string severityName 00179 (Message::Severity severity); 00184 bool isIncluded(const std::string& fileName); 00186 std::string sign(Sign aSign); 00188 std::string valueToString 00189 (std::vector<std::string> value, bool isVector); 00195 std::string posString(int line, int column); 00196 }; 00197 00198 00199 namespace Utils 00200 { 00201 // ====================================================================== 00207 bool getEnv(const std::string& envName,std::string& envValue); 00208 // ====================================================================== 00216 bool searchFile 00217 ( const std::string& fileInput , 00218 std::string& fileOutput ) ; 00219 // ====================================================================== 00224 std::string removeEnvironment(const std::string& input); 00225 // ====================================================================== 00231 bool readFile ( const std::string& name , std::string& result ) ; 00232 // ====================================================================== 00239 bool parseValue 00240 ( const std::string& input , 00241 std::string& stringResult , 00242 std::vector<std::string>& vectorResult ) ; 00243 // ====================================================================== 00244 00245 } // end of namespace Utils 00246 } // end of namespace Parsers 00247 } // end of namespace Gaudi 00248 00249 // ============================================================================ 00250 // The END 00251 // ============================================================================ 00252 #endif // JOBOPTIONSSVC_PARSERUTILS_H 00253 // ============================================================================