|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A parser to retrieve information from a table with known columns 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 #ifndef NamedColumnsParser_h 00020 #define NamedColumnsParser_h 00021 00022 00023 // =========================================================================== 00024 // included modules 00025 // =========================================================================== 00026 #ifdef _MSC_VER 00027 #include <windows_config.h> 00028 #else 00029 #include <config.h> 00030 #endif 00031 00032 #include <map> 00033 #include <string> 00034 #include <utils/common/StringTokenizer.h> 00035 00036 00037 // =========================================================================== 00038 // class definitions 00039 // =========================================================================== 00056 class NamedColumnsParser { 00057 public: 00062 NamedColumnsParser() throw(); 00063 00064 00077 NamedColumnsParser(const std::string& def, const std::string& defDelim=";", 00078 const std::string& lineDelim=";", bool chomp=false, 00079 bool ignoreCase=true) throw(); 00080 00081 00083 ~NamedColumnsParser() throw(); 00084 00085 00097 void reinit(const std::string& def, const std::string& defDelim=";", 00098 const std::string& lineDelim=";", bool chomp=false, 00099 bool ignoreCase=true) throw(); 00100 00101 00110 void parseLine(const std::string& line) throw(); 00111 00112 00127 std::string get(const std::string& name, 00128 bool prune=false) const throw(UnknownElement, OutOfBoundsException); 00129 00130 00136 bool know(const std::string& name) const throw(); 00137 00138 00143 bool hasFullDefinition() const throw(); 00144 00145 00146 private: 00159 void reinitMap(std::string def, const std::string& delim=";", 00160 bool chomp=false) throw(); 00161 00162 00171 void checkPrune(std::string& str, bool prune) const throw(); 00172 00173 00174 private: 00176 typedef std::map<std::string, size_t> PosMap; 00177 00179 PosMap myDefinitionsMap; 00180 00182 std::string myLineDelimiter; 00183 00185 StringTokenizer myLineParser; 00186 00188 bool myAmCaseInsensitive; 00189 00190 }; 00191 00192 00193 #endif 00194 00195 /****************************************************************************/ 00196