SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
NamedColumnsParser.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // A parser to retrieve information from a table with known columns
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifndef NamedColumnsParser_h
22 #define NamedColumnsParser_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <map>
35 #include <string>
37 
38 
39 // ===========================================================================
40 // class definitions
41 // ===========================================================================
59 public:
65 
66 
79  NamedColumnsParser(const std::string& def, const std::string& defDelim = ";",
80  const std::string& lineDelim = ";", bool chomp = false,
81  bool ignoreCase = true);
82 
83 
86 
87 
99  void reinit(const std::string& def, const std::string& defDelim = ";",
100  const std::string& lineDelim = ";", bool chomp = false,
101  bool ignoreCase = true);
102 
103 
112  void parseLine(const std::string& line);
113 
114 
129  std::string get(const std::string& name,
130  bool prune = false) const;
131 
132 
138  bool know(const std::string& name) const;
139 
140 
145  bool hasFullDefinition() const;
146 
147 
148 private:
161  void reinitMap(std::string def, const std::string& delim = ";",
162  bool chomp = false);
163 
164 
173  void checkPrune(std::string& str, bool prune) const;
174 
175 
176 private:
178  typedef std::map<std::string, int> PosMap;
179 
182 
184  std::string myLineDelimiter;
185 
188 
191 
192 };
193 
194 
195 #endif
196 
197 /****************************************************************************/
198 
PosMap myDefinitionsMap
The map of column item names to their positions within the table.
void reinit(const std::string &def, const std::string &defDelim=";", const std::string &lineDelim=";", bool chomp=false, bool ignoreCase=true)
Reinitialises the parser.
NamedColumnsParser()
Constructor.
std::map< std::string, int > PosMap
The map's definition 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 checkPrune(std::string &str, bool prune) const
Prunes the given string if it shall be done.
bool know(const std::string &name) const
Returns the information whether the named column is known.
~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.
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.