Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // A parser to retrieve information from a table with known columns
17 /****************************************************************************/
18 #ifndef NamedColumnsParser_h
19 #define NamedColumnsParser_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <map>
28 #include <string>
30 
31 
32 // ===========================================================================
33 // class definitions
34 // ===========================================================================
52 public:
58 
59 
72  NamedColumnsParser(const std::string& def, const std::string& defDelim = ";",
73  const std::string& lineDelim = ";", bool chomp = false,
74  bool ignoreCase = true);
75 
76 
79 
80 
92  void reinit(const std::string& def, const std::string& defDelim = ";",
93  const std::string& lineDelim = ";", bool chomp = false,
94  bool ignoreCase = true);
95 
96 
105  void parseLine(const std::string& line);
106 
107 
122  std::string get(const std::string& name,
123  bool prune = false) const;
124 
125 
131  bool know(const std::string& name) const;
132 
133 
138  bool hasFullDefinition() const;
139 
140 
141 private:
154  void reinitMap(std::string def, const std::string& delim = ";",
155  bool chomp = false);
156 
157 
166  void checkPrune(std::string& str, bool prune) const;
167 
168 
169 private:
171  typedef std::map<std::string, int> PosMap;
172 
175 
177  std::string myLineDelimiter;
178 
181 
184 
185 };
186 
187 
188 #endif
189 
190 /****************************************************************************/
191 
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.