SUMO - Simulation of Urban MObility
|
A parser to retrieve information from a table with known columns. More...
#include <NamedColumnsParser.h>
Public Member Functions | |
std::string | get (const std::string &name, bool prune=false) const throw (UnknownElement, OutOfBoundsException) |
Returns the named information. More... | |
bool | hasFullDefinition () const |
Returns whether the number of named columns matches the actual number. More... | |
bool | know (const std::string &name) const |
Returns the information whether the named column is known. More... | |
NamedColumnsParser () | |
Constructor. More... | |
NamedColumnsParser (const std::string &def, const std::string &defDelim=";", const std::string &lineDelim=";", bool chomp=false, bool ignoreCase=true) | |
Constructor. More... | |
void | parseLine (const std::string &line) |
Parses the contents of the line. More... | |
void | reinit (const std::string &def, const std::string &defDelim=";", const std::string &lineDelim=";", bool chomp=false, bool ignoreCase=true) |
Reinitialises the parser. More... | |
~NamedColumnsParser () | |
Destructor. More... | |
Private Types | |
typedef std::map< std::string, size_t > | PosMap |
The map's definition of column item names to their positions within the table. More... | |
Private Member Functions | |
void | checkPrune (std::string &str, bool prune) const |
Prunes the given string if it shall be done. More... | |
void | reinitMap (std::string def, const std::string &delim=";", bool chomp=false) |
Rebuilds the map of attribute names to their positions in a table. More... | |
Private Attributes | |
bool | myAmCaseInsensitive |
Information whether case insensitive match shall be done. More... | |
PosMap | myDefinitionsMap |
The map of column item names to their positions within the table. More... | |
std::string | myLineDelimiter |
The delimiter to split the column items on. More... | |
StringTokenizer | myLineParser |
The contents of the current line. More... | |
A parser to retrieve information from a table with known columns.
When initialised, this parser stores the given information about the order of the named elements and allows the retrieval of lines using the names of these elements. Use it like this:
Definition at line 58 of file NamedColumnsParser.h.
|
private |
The map's definition of column item names to their positions within the table.
Definition at line 178 of file NamedColumnsParser.h.
NamedColumnsParser::NamedColumnsParser | ( | ) |
Constructor.
Does nothing, a later call to reinit is necessary
Definition at line 46 of file NamedColumnsParser.cpp.
NamedColumnsParser::NamedColumnsParser | ( | const std::string & | def, |
const std::string & | defDelim = ";" , |
||
const std::string & | lineDelim = ";" , |
||
bool | chomp = false , |
||
bool | ignoreCase = true |
||
) |
Constructor.
Initialises the parser (mainly using "reinitMap", only "ignoreCase" and "lineDelim" are saved directly into member variables - "reinit" does the same).
[in] | def | The line that describes (names) the entries |
[in] | defDelim | Delimiter for the entry names |
[in] | lineDelim | Delimiter used within data lines |
[in] | chomp | Whether the lines shall be trimmed (white spaces shall be removed) |
[in] | ignoreCase | Whether the case shall be ignored when parsing the definitions |
Definition at line 49 of file NamedColumnsParser.cpp.
References reinitMap().
NamedColumnsParser::~NamedColumnsParser | ( | ) |
Destructor.
Definition at line 58 of file NamedColumnsParser.cpp.
|
private |
Prunes the given string if it shall be done.
If prune==true, the given string is prunned (all leading/trailing spaces are removed).
[in,out] | str | The string to prune (optionally) |
[in] | prune | Whether the string shall be prunned |
Definition at line 140 of file NamedColumnsParser.cpp.
Referenced by reinitMap().
std::string NamedColumnsParser::get | ( | const std::string & | name, |
bool | prune = false |
||
) | const throw (UnknownElement, OutOfBoundsException) |
Returns the named information.
Tries to find the given variable name within the parsed definition line ("myDefinitionsMap"). If the value was not within the definition, an UnknownElement exception is thrown. Otherwise, the method tries to return the element from the parsed value line that is at the obtained position. If the value line had less tokens than the position assumes, an OutOfBoundsException is thrown, otherwise the value at the position returned (optionally prunned).
[in] | name | The name of the value to retrieve |
[in] | prune | Whether the returned value shall be trimmed (leading/trainling spaces removed) |
UnknownElement | when the element was not named during the initialisation |
OutOfBoundsException | when the line was too short and did not contain the item |
Definition at line 79 of file NamedColumnsParser.cpp.
References StringUtils::to_lower_case().
Referenced by NIImporter_VISUM::getNamedFloat(), NIImporter_VISUM::getWeightedBool(), NIImporter_VISUM::getWeightedFloat(), PCLoaderVisum::load(), NIImporter_VISUM::parse_AreaSubPartElement(), NIImporter_VISUM::parse_Connectors(), NIImporter_VISUM::parse_Districts(), NIImporter_VISUM::parse_EdgePolys(), NIImporter_VISUM::parse_Edges(), NIImporter_VISUM::parse_Kante(), NIImporter_VISUM::parse_Lanes(), NIImporter_VISUM::parse_LanesConnections(), NIImporter_VISUM::parse_Nodes(), NIImporter_VISUM::parse_NodesToTrafficLights(), NIImporter_VISUM::parse_PartOfArea(), NIImporter_VISUM::parse_Phases(), NIImporter_VISUM::parse_Point(), NIImporter_VISUM::parse_SignalGroups(), NIImporter_VISUM::parse_SignalGroupsToPhases(), NIImporter_VISUM::parse_TrafficLights(), NIImporter_VISUM::parse_Turns(), NIImporter_VISUM::parse_Types(), and NIImporter_VISUM::parse_VSysTypes().
bool NamedColumnsParser::hasFullDefinition | ( | ) | const |
Returns whether the number of named columns matches the actual number.
Definition at line 116 of file NamedColumnsParser.cpp.
References myDefinitionsMap, myLineParser, and StringTokenizer::size().
bool NamedColumnsParser::know | ( | const std::string & | name | ) | const |
Returns the information whether the named column is known.
[in] | name | The name of the value to check |
Definition at line 100 of file NamedColumnsParser.cpp.
References myAmCaseInsensitive, myDefinitionsMap, myLineParser, StringTokenizer::size(), and StringUtils::to_lower_case().
Referenced by NIImporter_VISUM::getNamedFloat(), NIImporter_VISUM::parse_Connectors(), NIImporter_VISUM::parse_Districts(), NIImporter_VISUM::parse_Edges(), NIImporter_VISUM::parse_Lanes(), NIImporter_VISUM::parse_Phases(), NIImporter_VISUM::parse_SignalGroups(), NIImporter_VISUM::parse_TrafficLights(), NIImporter_VISUM::parse_Turns(), NIImporter_VISUM::parse_TurnsToSignalGroups(), and NIImporter_VISUM::parse_VSysTypes().
void NamedColumnsParser::parseLine | ( | const std::string & | line | ) |
Parses the contents of the line.
Parses the line by tokenizing it using a StringTokenizer and the set line delimiter ("myLineDelimiter"). Stores the tokenized line into "myLineParser"
[in] | line | The line to parse |
Definition at line 73 of file NamedColumnsParser.cpp.
References myLineDelimiter, and myLineParser.
Referenced by PCLoaderVisum::load(), and NIImporter_VISUM::load().
void NamedColumnsParser::reinit | ( | const std::string & | def, |
const std::string & | defDelim = ";" , |
||
const std::string & | lineDelim = ";" , |
||
bool | chomp = false , |
||
bool | ignoreCase = true |
||
) |
Reinitialises the parser.
Initialises the parser (mainly using "reinitMap", only "ignoreCase" and "lineDelim" are saved directly into member variables
[in] | def | The line that describes (names) the entries |
[in] | defDelim | Delimiter for the entry names |
[in] | lineDelim | Delimiter used within data lines |
[in] | chomp | Whether the lines shall be trimmed (white spaces shall be removed) |
[in] | ignoreCase | Whether the case shall be ignored when parsing the definitions |
Definition at line 62 of file NamedColumnsParser.cpp.
References myAmCaseInsensitive, myLineDelimiter, and reinitMap().
Referenced by PCLoaderVisum::load(), and NIImporter_VISUM::load().
|
private |
Rebuilds the map of attribute names to their positions in a table.
The given definition string is split using the given delimiter. The obtained tokens are stired in "" together with their positions within the tokenized string. If wished (myAmCaseInsensitive==true), the definition string is converted into lower case, first. Also, if chomp==true, each token ist prunned.
[in] | def | The definition string |
[in] | delim | The delimiter string |
[in] | chomp | Whether the tokens shall be prunned |
Definition at line 122 of file NamedColumnsParser.cpp.
References checkPrune(), StringTokenizer::hasNext(), myAmCaseInsensitive, myDefinitionsMap, StringTokenizer::next(), and StringUtils::to_lower_case().
Referenced by NamedColumnsParser(), and reinit().
|
private |
Information whether case insensitive match shall be done.
Definition at line 190 of file NamedColumnsParser.h.
Referenced by know(), reinit(), and reinitMap().
|
private |
The map of column item names to their positions within the table.
Definition at line 181 of file NamedColumnsParser.h.
Referenced by hasFullDefinition(), know(), and reinitMap().
|
private |
The delimiter to split the column items on.
Definition at line 184 of file NamedColumnsParser.h.
Referenced by parseLine(), and reinit().
|
private |
The contents of the current line.
Definition at line 187 of file NamedColumnsParser.h.
Referenced by hasFullDefinition(), know(), and parseLine().