SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00008 // A parser to retrieve information from a table with known columns 00009 /****************************************************************************/ 00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00012 /****************************************************************************/ 00013 // 00014 // This file is part of SUMO. 00015 // SUMO is free software: you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation, either version 3 of the License, or 00018 // (at your option) any later version. 00019 // 00020 /****************************************************************************/ 00021 #ifndef NamedColumnsParser_h 00022 #define NamedColumnsParser_h 00023 00024 00025 // =========================================================================== 00026 // included modules 00027 // =========================================================================== 00028 #ifdef _MSC_VER 00029 #include <windows_config.h> 00030 #else 00031 #include <config.h> 00032 #endif 00033 00034 #include <map> 00035 #include <string> 00036 #include <utils/common/StringTokenizer.h> 00037 00038 00039 // =========================================================================== 00040 // class definitions 00041 // =========================================================================== 00058 class NamedColumnsParser { 00059 public: 00064 NamedColumnsParser() ; 00065 00066 00079 NamedColumnsParser(const std::string& def, const std::string& defDelim = ";", 00080 const std::string& lineDelim = ";", bool chomp = false, 00081 bool ignoreCase = true) ; 00082 00083 00085 ~NamedColumnsParser() ; 00086 00087 00099 void reinit(const std::string& def, const std::string& defDelim = ";", 00100 const std::string& lineDelim = ";", bool chomp = false, 00101 bool ignoreCase = true) ; 00102 00103 00112 void parseLine(const std::string& line) ; 00113 00114 00129 std::string get(const std::string& name, 00130 bool prune = false) const throw(UnknownElement, OutOfBoundsException); 00131 00132 00138 bool know(const std::string& name) const ; 00139 00140 00145 bool hasFullDefinition() const ; 00146 00147 00148 private: 00161 void reinitMap(std::string def, const std::string& delim = ";", 00162 bool chomp = false) ; 00163 00164 00173 void checkPrune(std::string& str, bool prune) const ; 00174 00175 00176 private: 00178 typedef std::map<std::string, size_t> PosMap; 00179 00181 PosMap myDefinitionsMap; 00182 00184 std::string myLineDelimiter; 00185 00187 StringTokenizer myLineParser; 00188 00190 bool myAmCaseInsensitive; 00191 00192 }; 00193 00194 00195 #endif 00196 00197 /****************************************************************************/ 00198