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.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
19 // A parser to retrieve information from a table with known columns
20 /****************************************************************************/
21 #pragma once
22 #include <config.h>
23 
24 #include <map>
25 #include <string>
27 
28 
29 // ===========================================================================
30 // class definitions
31 // ===========================================================================
49 public:
55 
56 
69  NamedColumnsParser(const std::string& def, const std::string& defDelim = ";",
70  const std::string& lineDelim = ";", bool chomp = false,
71  bool ignoreCase = true);
72 
73 
76 
77 
89  void reinit(const std::string& def, const std::string& defDelim = ";",
90  const std::string& lineDelim = ";", bool chomp = false,
91  bool ignoreCase = true);
92 
93 
102  void parseLine(const std::string& line);
103 
104 
119  std::string get(const std::string& name,
120  bool prune = false) const;
121 
122 
128  bool know(const std::string& name) const;
129 
130 
135  bool hasFullDefinition() const;
136 
137 
138 private:
151  void reinitMap(std::string def, const std::string& delim = ";",
152  bool chomp = false);
153 
154 
163  void checkPrune(std::string& str, bool prune) const;
164 
165 
166 private:
168  typedef std::map<std::string, int> PosMap;
169 
172 
174  std::string myLineDelimiter;
175 
178 
181 
182 };
A parser to retrieve information from a table with known columns.
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.
std::map< std::string, int > PosMap
The map's definition of column item names to their positions within the table.
void parseLine(const std::string &line)
Parses the contents of the line.
void reinitMap(std::string def, const std::string &delim=";", bool chomp=false)
Rebuilds the map of attribute names to their positions in a table.
PosMap myDefinitionsMap
The map of column item names to their positions within the table.
std::string myLineDelimiter
The delimiter to split the column items on.
bool myAmCaseInsensitive
Information whether case insensitive match shall be done.
std::string get(const std::string &name, bool prune=false) const
Returns the named information.
NamedColumnsParser()
Constructor.
StringTokenizer myLineParser
The contents of the current line.
~NamedColumnsParser()
Destructor.
void checkPrune(std::string &str, bool prune) const
Prunes the given string if it shall be done.