Eclipse 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 |
Returns the named information. | |
bool | hasFullDefinition () const |
Returns whether the number of named columns matches the actual number. | |
bool | know (const std::string &name) const |
Returns the information whether the named column is known. | |
NamedColumnsParser () | |
Constructor. | |
NamedColumnsParser (const std::string &def, const std::string &defDelim=";", const std::string &lineDelim=";", bool chomp=false, bool ignoreCase=true) | |
Constructor. | |
void | parseLine (const std::string &line) |
Parses the contents of the line. | |
void | reinit (const std::string &def, const std::string &defDelim=";", const std::string &lineDelim=";", bool chomp=false, bool ignoreCase=true) |
Reinitialises the parser. | |
~NamedColumnsParser () | |
Destructor. | |
Private Types | |
typedef std::map< std::string, int > | PosMap |
The map's definition of column item names to their positions within the table. | |
Private Member Functions | |
void | checkPrune (std::string &str, bool prune) const |
Prunes the given string if it shall be done. | |
void | reinitMap (std::string def, const std::string &delim=";", bool chomp=false) |
Rebuilds the map of attribute names to their positions in a table. | |
Private Attributes | |
bool | myAmCaseInsensitive |
Information whether case insensitive match shall be done. | |
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. | |
StringTokenizer | myLineParser |
The contents of the current line. | |
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 48 of file NamedColumnsParser.h.
|
private |
The map's definition of column item names to their positions within the table.
Definition at line 168 of file NamedColumnsParser.h.
NamedColumnsParser::NamedColumnsParser | ( | ) |
Constructor.
Does nothing, a later call to reinit is necessary
Definition at line 33 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 36 of file NamedColumnsParser.cpp.
References reinitMap().
NamedColumnsParser::~NamedColumnsParser | ( | ) |
Destructor.
Definition at line 45 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 127 of file NamedColumnsParser.cpp.
Referenced by get(), and reinitMap().
std::string NamedColumnsParser::get | ( | const std::string & | name, |
bool | prune = false |
||
) | const |
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 66 of file NamedColumnsParser.cpp.
References checkPrune(), StringTokenizer::get(), myAmCaseInsensitive, myDefinitionsMap, myLineParser, StringTokenizer::size(), and StringUtils::to_lower_case().
Referenced by NIImporter_VISUM::getNamedEdge(), NIImporter_VISUM::getNamedEdgeContinuating(), NIImporter_VISUM::getNamedFloat(), NIImporter_VISUM::getNamedFloat(), NIImporter_VISUM::getNamedNode(), NIImporter_VISUM::getNamedNodeSecure(), NIImporter_VISUM::getNamedString(), NIImporter_VISUM::getPermissions(), NIImporter_VISUM::getWeightedBool(), NIImporter_VISUM::getWeightedFloat(), PCLoaderVisum::load(), NIImporter_VISUM::parse_AreaSubPartElement(), NIImporter_VISUM::parse_Connectors(), NIImporter_VISUM::parse_Connectors_legacy(), 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_stopPoints(), NIImporter_VISUM::parse_TrafficLights(), NIImporter_VISUM::parse_Turns(), NIImporter_VISUM::parse_Types(), NIImporter_VISUM::parse_VSysTypes(), and RODFDetFlowLoader::read().
bool NamedColumnsParser::hasFullDefinition | ( | ) | const |
Returns whether the number of named columns matches the actual number.
Definition at line 103 of file NamedColumnsParser.cpp.
References myDefinitionsMap, myLineParser, and StringTokenizer::size().
Referenced by RODFDetFlowLoader::read().
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 87 of file NamedColumnsParser.cpp.
References myAmCaseInsensitive, myDefinitionsMap, myLineParser, StringTokenizer::size(), and StringUtils::to_lower_case().
Referenced by NIImporter_VISUM::getNamedEdge(), NIImporter_VISUM::getNamedEdgeContinuating(), NIImporter_VISUM::getNamedFloat(), NIImporter_VISUM::getNamedFloat(), NIImporter_VISUM::getNamedNode(), NIImporter_VISUM::getNamedString(), NIImporter_VISUM::parse_Connectors(), NIImporter_VISUM::parse_Connectors_legacy(), 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(), NIImporter_VISUM::parse_VSysTypes(), and RODFDetFlowLoader::read().
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 60 of file NamedColumnsParser.cpp.
References myLineDelimiter, and myLineParser.
Referenced by NIImporter_VISUM::load(), PCLoaderVisum::load(), and RODFDetFlowLoader::read().
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 49 of file NamedColumnsParser.cpp.
References myAmCaseInsensitive, myLineDelimiter, and reinitMap().
Referenced by NIImporter_VISUM::load(), PCLoaderVisum::load(), and RODFDetFlowLoader::read().
|
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 109 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 180 of file NamedColumnsParser.h.
Referenced by get(), know(), reinit(), and reinitMap().
|
private |
The map of column item names to their positions within the table.
Definition at line 171 of file NamedColumnsParser.h.
Referenced by get(), hasFullDefinition(), know(), and reinitMap().
|
private |
The delimiter to split the column items on.
Definition at line 174 of file NamedColumnsParser.h.
Referenced by parseLine(), and reinit().
|
private |
The contents of the current line.
Definition at line 177 of file NamedColumnsParser.h.
Referenced by get(), hasFullDefinition(), know(), and parseLine().