Eclipse SUMO - Simulation of Urban MObility
NamedColumnsParser Class Reference

A parser to retrieve information from a table with known columns. More...

#include <NamedColumnsParser.h>

Collaboration diagram for NamedColumnsParser:
[legend]

Public Member Functions

std::string get (const std::string &name, bool prune=false) const
 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, int > 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...
 

Detailed Description

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:

  • Initialise with "Name;PositionX;PositionY" (defDelim=default=";") (lineDelim=default=";")
  • Parse each line of a table using "parseLine" (parseLine("Dummy;0;0"))
  • get values using operations like: string posX = get("PositionX");
Todo:
What happens if an uninitialised NamedColumnsParser is used? exceptions?

Definition at line 48 of file NamedColumnsParser.h.

Member Typedef Documentation

◆ PosMap

typedef std::map<std::string, int> NamedColumnsParser::PosMap
private

The map's definition of column item names to their positions within the table.

Definition at line 168 of file NamedColumnsParser.h.

Constructor & Destructor Documentation

◆ NamedColumnsParser() [1/2]

NamedColumnsParser::NamedColumnsParser ( )

Constructor.

Does nothing, a later call to reinit is necessary

Definition at line 33 of file NamedColumnsParser.cpp.

◆ NamedColumnsParser() [2/2]

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).

Parameters
[in]defThe line that describes (names) the entries
[in]defDelimDelimiter for the entry names
[in]lineDelimDelimiter used within data lines
[in]chompWhether the lines shall be trimmed (white spaces shall be removed)
[in]ignoreCaseWhether the case shall be ignored when parsing the definitions

Definition at line 36 of file NamedColumnsParser.cpp.

References reinitMap().

◆ ~NamedColumnsParser()

NamedColumnsParser::~NamedColumnsParser ( )

Destructor.

Definition at line 45 of file NamedColumnsParser.cpp.

Member Function Documentation

◆ checkPrune()

void NamedColumnsParser::checkPrune ( std::string &  str,
bool  prune 
) const
private

Prunes the given string if it shall be done.

If prune==true, the given string is prunned (all leading/trailing spaces are removed).

Parameters
[in,out]strThe string to prune (optionally)
[in]pruneWhether the string shall be prunned

Definition at line 127 of file NamedColumnsParser.cpp.

Referenced by get(), and reinitMap().

Here is the caller graph for this function:

◆ get()

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).

Parameters
[in]nameThe name of the value to retrieve
[in]pruneWhether the returned value shall be trimmed (leading/trainling spaces removed)
Returns
The obtained value
Exceptions
UnknownElementwhen the element was not named during the initialisation
OutOfBoundsExceptionwhen 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::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().

Here is the caller graph for this function:

◆ hasFullDefinition()

bool NamedColumnsParser::hasFullDefinition ( ) const

Returns whether the number of named columns matches the actual number.

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().

Here is the caller graph for this function:

◆ know()

bool NamedColumnsParser::know ( const std::string &  name) const

◆ parseLine()

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"

Parameters
[in]lineThe 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().

Here is the caller graph for this function:

◆ reinit()

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

Parameters
[in]defThe line that describes (names) the entries
[in]defDelimDelimiter for the entry names
[in]lineDelimDelimiter used within data lines
[in]chompWhether the lines shall be trimmed (white spaces shall be removed)
[in]ignoreCaseWhether 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().

Here is the caller graph for this function:

◆ reinitMap()

void NamedColumnsParser::reinitMap ( std::string  def,
const std::string &  delim = ";",
bool  chomp = false 
)
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.

Parameters
[in]defThe definition string
[in]delimThe delimiter string
[in]chompWhether 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().

Here is the caller graph for this function:

Field Documentation

◆ myAmCaseInsensitive

bool NamedColumnsParser::myAmCaseInsensitive
private

Information whether case insensitive match shall be done.

Definition at line 180 of file NamedColumnsParser.h.

Referenced by get(), know(), reinit(), and reinitMap().

◆ myDefinitionsMap

PosMap NamedColumnsParser::myDefinitionsMap
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().

◆ myLineDelimiter

std::string NamedColumnsParser::myLineDelimiter
private

The delimiter to split the column items on.

Definition at line 174 of file NamedColumnsParser.h.

Referenced by parseLine(), and reinit().

◆ myLineParser

StringTokenizer NamedColumnsParser::myLineParser
private

The contents of the current line.

Definition at line 177 of file NamedColumnsParser.h.

Referenced by get(), hasFullDefinition(), know(), and parseLine().


The documentation for this class was generated from the following files: