SUMO - Simulation of Urban MObility
NamedColumnsParser.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // A parser to retrieve information from a table with known columns
19 /****************************************************************************/
20 #ifndef NamedColumnsParser_h
21 #define NamedColumnsParser_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <map>
34 #include <string>
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
58 public:
64 
65 
78  NamedColumnsParser(const std::string& def, const std::string& defDelim = ";",
79  const std::string& lineDelim = ";", bool chomp = false,
80  bool ignoreCase = true);
81 
82 
85 
86 
98  void reinit(const std::string& def, const std::string& defDelim = ";",
99  const std::string& lineDelim = ";", bool chomp = false,
100  bool ignoreCase = true);
101 
102 
111  void parseLine(const std::string& line);
112 
113 
128  std::string get(const std::string& name,
129  bool prune = false) const;
130 
131 
137  bool know(const std::string& name) const;
138 
139 
144  bool hasFullDefinition() const;
145 
146 
147 private:
160  void reinitMap(std::string def, const std::string& delim = ";",
161  bool chomp = false);
162 
163 
172  void checkPrune(std::string& str, bool prune) const;
173 
174 
175 private:
177  typedef std::map<std::string, int> PosMap;
178 
181 
183  std::string myLineDelimiter;
184 
187 
190 
191 };
192 
193 
194 #endif
195 
196 /****************************************************************************/
197 
PosMap myDefinitionsMap
The map of column item names to their positions within the table.
bool hasFullDefinition() const
Returns whether the number of named columns matches the actual number.
void reinit(const std::string &def, const std::string &defDelim=";", const std::string &lineDelim=";", bool chomp=false, bool ignoreCase=true)
Reinitialises the parser.
bool know(const std::string &name) const
Returns the information whether the named column is known.
NamedColumnsParser()
Constructor.
std::map< std::string, int > PosMap
The map&#39;s definition of column item names to their positions within the table.
~NamedColumnsParser()
Destructor.
StringTokenizer myLineParser
The contents of the current line.
A parser to retrieve information from a table with known columns.
void reinitMap(std::string def, const std::string &delim=";", bool chomp=false)
Rebuilds the map of attribute names to their positions in a table.
void checkPrune(std::string &str, bool prune) const
Prunes the given string if it shall be done.
bool myAmCaseInsensitive
Information whether case insensitive match shall be done.
void parseLine(const std::string &line)
Parses the contents of the line.
std::string myLineDelimiter
The delimiter to split the column items on.