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 /****************************************************************************/
15 // A parser to retrieve information from a table with known columns
16 /****************************************************************************/
17 #ifndef NamedColumnsParser_h
18 #define NamedColumnsParser_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <map>
27 #include <string>
29 
30 
31 // ===========================================================================
32 // class definitions
33 // ===========================================================================
51 public:
57 
58 
71  NamedColumnsParser(const std::string& def, const std::string& defDelim = ";",
72  const std::string& lineDelim = ";", bool chomp = false,
73  bool ignoreCase = true);
74 
75 
78 
79 
91  void reinit(const std::string& def, const std::string& defDelim = ";",
92  const std::string& lineDelim = ";", bool chomp = false,
93  bool ignoreCase = true);
94 
95 
104  void parseLine(const std::string& line);
105 
106 
121  std::string get(const std::string& name,
122  bool prune = false) const;
123 
124 
130  bool know(const std::string& name) const;
131 
132 
137  bool hasFullDefinition() const;
138 
139 
140 private:
153  void reinitMap(std::string def, const std::string& delim = ";",
154  bool chomp = false);
155 
156 
165  void checkPrune(std::string& str, bool prune) const;
166 
167 
168 private:
170  typedef std::map<std::string, int> PosMap;
171 
174 
176  std::string myLineDelimiter;
177 
180 
183 
184 };
185 
186 
187 #endif
188 
189 /****************************************************************************/
190 
NamedColumnsParser::hasFullDefinition
bool hasFullDefinition() const
Returns whether the number of named columns matches the actual number.
Definition: NamedColumnsParser.cpp:104
NamedColumnsParser::parseLine
void parseLine(const std::string &line)
Parses the contents of the line.
Definition: NamedColumnsParser.cpp:61
NamedColumnsParser::myLineDelimiter
std::string myLineDelimiter
The delimiter to split the column items on.
Definition: NamedColumnsParser.h:176
NamedColumnsParser::get
std::string get(const std::string &name, bool prune=false) const
Returns the named information.
Definition: NamedColumnsParser.cpp:67
StringTokenizer
Definition: StringTokenizer.h:61
NamedColumnsParser::reinitMap
void reinitMap(std::string def, const std::string &delim=";", bool chomp=false)
Rebuilds the map of attribute names to their positions in a table.
Definition: NamedColumnsParser.cpp:110
NamedColumnsParser::reinit
void reinit(const std::string &def, const std::string &defDelim=";", const std::string &lineDelim=";", bool chomp=false, bool ignoreCase=true)
Reinitialises the parser.
Definition: NamedColumnsParser.cpp:50
NamedColumnsParser::know
bool know(const std::string &name) const
Returns the information whether the named column is known.
Definition: NamedColumnsParser.cpp:88
NamedColumnsParser::myAmCaseInsensitive
bool myAmCaseInsensitive
Information whether case insensitive match shall be done.
Definition: NamedColumnsParser.h:182
NamedColumnsParser::NamedColumnsParser
NamedColumnsParser()
Constructor.
Definition: NamedColumnsParser.cpp:34
NamedColumnsParser::~NamedColumnsParser
~NamedColumnsParser()
Destructor.
Definition: NamedColumnsParser.cpp:46
NamedColumnsParser::PosMap
std::map< std::string, int > PosMap
The map's definition of column item names to their positions within the table.
Definition: NamedColumnsParser.h:170
NamedColumnsParser::myDefinitionsMap
PosMap myDefinitionsMap
The map of column item names to their positions within the table.
Definition: NamedColumnsParser.h:173
NamedColumnsParser::myLineParser
StringTokenizer myLineParser
The contents of the current line.
Definition: NamedColumnsParser.h:179
config.h
StringTokenizer.h
NamedColumnsParser::checkPrune
void checkPrune(std::string &str, bool prune) const
Prunes the given string if it shall be done.
Definition: NamedColumnsParser.cpp:128
NamedColumnsParser
A parser to retrieve information from a table with known columns.
Definition: NamedColumnsParser.h:50