![]() |
|
|
Generated: 8 Jan 2009 |
00001 // $Id: ParserUtils.h,v 1.7 2007/09/25 08:02:11 marcocle Exp $ 00002 // ============================================================================ 00003 // CVS tag $Name: $ 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 typedef std::map<std::string,double> UnitsStoreT; 00105 enum Sign 00106 { 00107 S_ASSIGN = 0 , 00108 S_PLUSASSIGN = 1 , 00109 S_MINUSASSIGN = 2 00110 }; 00112 Parser (Catalogue& catalogue, std::vector<std::string>& included, std::ostream& m = std::cout ) ; 00114 Parser (Catalogue& catalogue, std::vector<std::string>& included, 00115 const std::vector<std::string>& searchPath , 00116 std::ostream& m = std::cout ) ; 00118 Parser (Catalogue& catalogue, std::vector<std::string>& included, 00119 const std::string& searchPath , 00120 std::ostream& m = std::cout ) ; 00121 public: 00126 StatusCode parse(const std::string& fileName); 00128 const std::vector<Message>& messages(){return m_messages;} 00130 int errorsCount(); 00131 UnitsStoreT& units(void) {return m_units;} 00135 void matchInclude 00136 (const std::string& fileName,const Position& pos); 00140 void matchUnits 00141 (const std::string& fileName,const Position& pos); 00146 long double matchUnit 00147 (const std::string& unit,const Position& pos); 00153 void matchUnitEntry 00154 (const std::string& newUnit, 00155 double value, 00156 const Position& pos); 00164 void matchAssign 00165 (const std::string& objName, 00166 const std::string& propName, 00167 const Sign& oper, 00168 const std::vector<std::string>& vectorValues, 00169 const Position& pos, bool isVector); 00171 void setIsPrint(bool on, const Position& pos); 00173 void setIsPrintOptions(bool on, const Position& pos); 00174 private: 00175 bool m_isPrint; 00176 bool m_isPrintOptions; 00177 std::vector<std::string> m_searchPath; 00178 Catalogue& m_catalogue; 00179 std::vector<std::string>& m_included; 00180 MessagesStoreT m_messages; 00181 UnitsStoreT m_units; 00182 std::ostream& m_stream ; 00183 private: 00185 void initUnits(); 00191 StatusCode parseFile 00192 ( const std::string& fileName , 00193 const Position& pos, 00194 bool isUnitFile=false); 00196 void resolveReferences(); 00203 void addMessage 00204 ( const Message::Severity& severity, 00205 const Message::Code& code, 00206 const std::string& message, 00207 const Position& pos); 00212 std::string severityName 00213 (Message::Severity severity); 00218 bool isIncluded(const std::string& fileName); 00220 std::string sign(Sign aSign); 00222 std::string valueToString 00223 (std::vector<std::string> value, bool isVector); 00225 bool isPrint(){ return m_isPrint;} 00227 void printOptions(); 00233 std::string posString(int line, int column); 00234 }; 00235 00236 00241 StatusCode parse 00242 ( Parser parser , 00243 const std::string& fileName , 00244 std::vector<Message>& msgs ) ; 00245 00257 StatusCode parse 00258 ( const std::string& filename , 00259 const std::vector<std::string>& searchPath , 00260 Catalogue& catalogue , 00261 std::vector<std::string>& included, 00262 std::vector<Message>& messages ) ; 00263 00275 StatusCode parse 00276 ( const std::string& filename , 00277 const std::string& searchPath , 00278 Catalogue& catalogue , 00279 std::vector<std::string>& included, 00280 std::vector<Message>& messages ) ; 00281 00292 StatusCode parse 00293 ( const std::string& filename , 00294 Catalogue& catalogue , 00295 std::vector<std::string>& included, 00296 std::vector<Message>& messages ) ; 00297 00298 namespace Utils 00299 { 00300 // ====================================================================== 00306 StatusCode getEnv(const std::string& envName,std::string& envValue); 00307 // ====================================================================== 00315 StatusCode searchFile 00316 ( const std::string& fileInput , 00317 bool addCurrent , 00318 const std::vector<std::string>& dirs , 00319 std::string& fileOutput ) ; 00320 // ====================================================================== 00325 std::string removeEnvironment(const std::string& input); 00326 // ====================================================================== 00328 bool isWin(); 00330 std::string pathSeparator(); 00331 // ====================================================================== 00337 std::vector<std::string> 00338 extractPath ( const std::string& input , bool removeEnv = true ); 00339 // ====================================================================== 00345 StatusCode readFile ( const std::string& name , std::string& result ) ; 00346 // ====================================================================== 00353 StatusCode parseValue 00354 ( const std::string& input , 00355 std::string& stringResult , 00356 std::vector<std::string>& vectorResult ) ; 00357 // ====================================================================== 00358 00359 } // end of namespace Utils 00360 } // end of namespace Parsers 00361 } // end of namespace Gaudi 00362 00363 // ============================================================================ 00364 // The END 00365 // ============================================================================ 00366 #endif // JOBOPTIONSSVC_PARSERUTILS_H 00367 // ============================================================================