|
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. | |
| bool | hasFullDefinition () const throw () |
| Returns whether the number of named columns matches the actual number. | |
| bool | know (const std::string &name) const throw () |
| Returns the information whether the named column is known. | |
| NamedColumnsParser (const std::string &def, const std::string &defDelim=";", const std::string &lineDelim=";", bool chomp=false, bool ignoreCase=true) throw () | |
| Constructor. | |
| NamedColumnsParser () throw () | |
| Constructor. | |
| void | parseLine (const std::string &line) throw () |
| 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) throw () |
| Reinitialises the parser. | |
| ~NamedColumnsParser () throw () | |
| Destructor. | |
Private Types | |
| typedef std::map< std::string, size_t > | 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 throw () |
| Prunes the given string if it shall be done. | |
| void | reinitMap (std::string def, const std::string &delim=";", bool chomp=false) throw () |
| 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 56 of file NamedColumnsParser.h.
typedef std::map<std::string, size_t> NamedColumnsParser::PosMap [private] |
The map's definition of column item names to their positions within the table.
Definition at line 176 of file NamedColumnsParser.h.
| NamedColumnsParser::NamedColumnsParser | ( | ) | throw () |
Constructor.
Does nothing, a later call to reinit is necessary
Definition at line 44 of file NamedColumnsParser.cpp.
| NamedColumnsParser::NamedColumnsParser | ( | const std::string & | def, |
| const std::string & | defDelim = ";", |
||
| const std::string & | lineDelim = ";", |
||
| bool | chomp = false, |
||
| bool | ignoreCase = true |
||
| ) | throw () |
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 47 of file NamedColumnsParser.cpp.
| NamedColumnsParser::~NamedColumnsParser | ( | ) | throw () |
Destructor.
Definition at line 56 of file NamedColumnsParser.cpp.
| void NamedColumnsParser::checkPrune | ( | std::string & | str, |
| bool | prune | ||
| ) | const throw () [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 138 of file NamedColumnsParser.cpp.
| 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 77 of file NamedColumnsParser.cpp.
References StringUtils::to_lower_case().
Referenced by 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 throw () |
Returns whether the number of named columns matches the actual number.
Definition at line 114 of file NamedColumnsParser.cpp.
References myDefinitionsMap, myLineParser, and StringTokenizer::size().
| bool NamedColumnsParser::know | ( | const std::string & | name | ) | const throw () |
Returns the information whether the named column is known.
| [in] | name | The name of the value to check |
Definition at line 98 of file NamedColumnsParser.cpp.
References StringUtils::to_lower_case().
Referenced by NIImporter_VISUM::parse_Connectors(), NIImporter_VISUM::parse_Districts(), NIImporter_VISUM::parse_Edges(), NIImporter_VISUM::parse_Lanes(), NIImporter_VISUM::parse_TrafficLights(), NIImporter_VISUM::parse_Turns(), NIImporter_VISUM::parse_TurnsToSignalGroups(), and NIImporter_VISUM::parse_VSysTypes().
| void NamedColumnsParser::parseLine | ( | const std::string & | line | ) | throw () |
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 71 of file NamedColumnsParser.cpp.
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 |
||
| ) | throw () |
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 60 of file NamedColumnsParser.cpp.
Referenced by PCLoaderVisum::load(), and NIImporter_VISUM::load().
| void NamedColumnsParser::reinitMap | ( | std::string | def, |
| const std::string & | delim = ";", |
||
| bool | chomp = false |
||
| ) | throw () [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 120 of file NamedColumnsParser.cpp.
References StringTokenizer::hasNext(), StringTokenizer::next(), and StringUtils::to_lower_case().
bool NamedColumnsParser::myAmCaseInsensitive [private] |
Information whether case insensitive match shall be done.
Definition at line 188 of file NamedColumnsParser.h.
PosMap NamedColumnsParser::myDefinitionsMap [private] |
The map of column item names to their positions within the table.
Definition at line 179 of file NamedColumnsParser.h.
Referenced by hasFullDefinition().
std::string NamedColumnsParser::myLineDelimiter [private] |
The delimiter to split the column items on.
Definition at line 182 of file NamedColumnsParser.h.
The contents of the current line.
Definition at line 185 of file NamedColumnsParser.h.
Referenced by hasFullDefinition().