Eclipse SUMO - Simulation of Urban MObility
FileHelpers Class Reference

Functions for an easier usage of files and paths. More...

#include <FileHelpers.h>

Static Public Member Functions

file access functions
static bool isReadable (std::string path)
 Checks whether the given file is readable. More...
 
static bool isDirectory (std::string path)
 Checks whether the given file is a directory. More...
 
file path evaluating functions
static std::string getFilePath (const std::string &path)
 Removes the file information from the given path. More...
 
static std::string addExtension (const std::string &path, const std::string &extension)
 Add an extension to the given file path. More...
 
static std::string getConfigurationRelative (const std::string &configPath, const std::string &path)
 Returns the second path as a relative path to the first file. More...
 
static bool isSocket (const std::string &name)
 Returns the information whether the given name represents a socket. More...
 
static bool isAbsolute (const std::string &path)
 Returns the information whether the given path is absolute. More...
 
static std::string checkForRelativity (const std::string &filename, const std::string &basePath)
 Returns the path from a configuration so that it is accessable from the current working directory. More...
 
static std::string prependToLastPathComponent (const std::string &prefix, const std::string &path)
 prepend the given prefix to the last path component of the given file path More...
 
binary writing functions
static std::ostream & writeInt (std::ostream &strm, int value)
 Writes an integer binary. More...
 
static std::ostream & writeFloat (std::ostream &strm, double value)
 Writes a float binary. More...
 
static std::ostream & writeByte (std::ostream &strm, unsigned char value)
 Writes a byte binary. More...
 
static std::ostream & writeString (std::ostream &strm, const std::string &value)
 Writes a string binary. More...
 
static std::ostream & writeTime (std::ostream &strm, SUMOTime value)
 Writes a time description binary. More...
 
template<typename E >
static std::ostream & writeEdgeVector (std::ostream &os, const std::vector< E > &edges)
 Writes an edge vector binary. More...
 
template<typename E >
static void readEdgeVector (std::istream &in, std::vector< const E * > &edges, const std::string &rid)
 Reads an edge vector binary. More...
 

Detailed Description

Functions for an easier usage of files and paths.

Definition at line 37 of file FileHelpers.h.

Member Function Documentation

◆ addExtension()

std::string FileHelpers::addExtension ( const std::string &  path,
const std::string &  extension 
)
static

◆ checkForRelativity()

std::string FileHelpers::checkForRelativity ( const std::string &  filename,
const std::string &  basePath 
)
static

Returns the path from a configuration so that it is accessable from the current working directory.

If the path is absolute, it is returned. Otherwise, the file's position is computed regarding the configuration path (see getConfigurationRelative).

See also
isAbsolute
getConfigurationRelative
Parameters
[in]filenameThe path to the file to be examined
[in]basePathThe path the configuration file (including the config's file name)
Returns
The file's position

Definition at line 151 of file FileHelpers.cpp.

References getConfigurationRelative(), isAbsolute(), and isSocket().

Referenced by NLHandler::addE1Detector(), NLHandler::addE2Detector(), NLHandler::addEdgeLaneMeanData(), NLHandler::addInstantE1Detector(), NLHandler::addRouteProbeDetector(), NLHandler::addVTypeProbeDetector(), NLHandler::beginE3Detector(), NLDiscreteEventBuilder::buildSaveTLSProgramCommand(), NLDiscreteEventBuilder::buildSaveTLStateCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchesCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchStatesCommand(), MSDevice_SSM::getOutputFilename(), MSActuatedTrafficLightLogic::MSActuatedTrafficLightLogic(), MSDelayBasedTrafficLightLogic::MSDelayBasedTrafficLightLogic(), and OptionsCont::relocateFiles().

Here is the caller graph for this function:

◆ getConfigurationRelative()

std::string FileHelpers::getConfigurationRelative ( const std::string &  configPath,
const std::string &  path 
)
static

Returns the second path as a relative path to the first file.

Given the position of the configuration file, and the information where a second file is relative to the configuration file's position, we want to known where this second file can be found. This method gets the path to the configuration file (including the configuration file name) and the path to get the relative position of and returns this relative position.

Parameters
[in]configPathThe path the configuration file (including the config's file name)
[in]pathThe path to the references file (relativ to configuration path)
Returns
The file's position (relative to curent working directory)

Definition at line 114 of file FileHelpers.cpp.

References getFilePath().

Referenced by ShapeHandler::addPOI(), ShapeHandler::addPoly(), SUMOVehicleParserHelper::beginVTypeParsing(), checkForRelativity(), NWFrame::checkOptions(), NLTriggerBuilder::getFileName(), main(), GUISettingsHandler::myStartElement(), GNEAdditionalHandler::parseAndBuildPOI(), GNEAdditionalHandler::parseAndBuildPoly(), and GenericSAXHandler::startElement().

Here is the caller graph for this function:

◆ getFilePath()

std::string FileHelpers::getFilePath ( const std::string &  path)
static

Removes the file information from the given path.

Parameters
[in]pathThe path to the file to return the folder it is located in
Returns
The directory of the named file

Definition at line 75 of file FileHelpers.cpp.

Referenced by GNEAdditionalHandler::buildRerouter(), getConfigurationRelative(), GNEAdditional::writeAdditional(), RODFDetectorCon::writeEmitters(), RODFDetectorCon::writeSpeedTrigger(), SUMOPolygon::writeXML(), and PointOfInterest::writeXML().

Here is the caller graph for this function:

◆ isAbsolute()

bool FileHelpers::isAbsolute ( const std::string &  path)
static

Returns the information whether the given path is absolute.

A path is meant to be absolute, if

  • it is a socket
  • it starts with a "/" (Linux)
  • it has a ':' at the second position (Windows)
Parameters
[in]pathThe path to examine
Returns
Whether the path is absolute

Definition at line 128 of file FileHelpers.cpp.

References isSocket().

Referenced by ShapeHandler::addPOI(), ShapeHandler::addPoly(), SUMOVehicleParserHelper::beginVTypeParsing(), checkForRelativity(), NLTriggerBuilder::getFileName(), GUISettingsHandler::myStartElement(), GNEAdditionalHandler::parseAndBuildPOI(), GNEAdditionalHandler::parseAndBuildPoly(), and GenericSAXHandler::startElement().

Here is the caller graph for this function:

◆ isDirectory()

bool FileHelpers::isDirectory ( std::string  path)
static

Checks whether the given file is a directory.

Parameters
[in]pathThe path to the file that shall be examined
Returns
Whether the named file is a directory.

Definition at line 62 of file FileHelpers.cpp.

Referenced by OptionsIO::getRoot(), and SUMOSAXReader::parse().

Here is the caller graph for this function:

◆ isReadable()

◆ isSocket()

bool FileHelpers::isSocket ( const std::string &  name)
static

Returns the information whether the given name represents a socket.

A file name is meant to describe a socket address if a colon is found at a position larger than one.

Parameters
[in]nameThe name of a file
Returns
Whether the name names a socket

Definition at line 121 of file FileHelpers.cpp.

Referenced by checkForRelativity(), OutputDevice::getDevice(), and isAbsolute().

Here is the caller graph for this function:

◆ prependToLastPathComponent()

std::string FileHelpers::prependToLastPathComponent ( const std::string &  prefix,
const std::string &  path 
)
static

prepend the given prefix to the last path component of the given file path

Definition at line 169 of file FileHelpers.cpp.

Referenced by OutputDevice::getDevice().

Here is the caller graph for this function:

◆ readEdgeVector()

template<typename E >
void FileHelpers::readEdgeVector ( std::istream &  in,
std::vector< const E * > &  edges,
const std::string &  rid 
)
static

Reads an edge vector binary.

Parameters
[in]isThe stream to read from
[out]edgesThe edge vector to write into
Returns
Reference to the stream

Definition at line 259 of file FileHelpers.h.

◆ writeByte()

std::ostream & FileHelpers::writeByte ( std::ostream &  strm,
unsigned char  value 
)
static

Writes a byte binary.

Parameters
[in,out]strmThe stream to write into
[in]valueThe byte to write
Returns
Reference to the stream

Definition at line 197 of file FileHelpers.cpp.

◆ writeEdgeVector()

template<typename E >
std::ostream & FileHelpers::writeEdgeVector ( std::ostream &  os,
const std::vector< E > &  edges 
)
static

Writes an edge vector binary.

Parameters
[in,out]osThe stream to write into
[in]edgesThe edges to write
Returns
Reference to the stream

Definition at line 203 of file FileHelpers.h.

References writeInt().

◆ writeFloat()

std::ostream & FileHelpers::writeFloat ( std::ostream &  strm,
double  value 
)
static

Writes a float binary.

This method behaves differently depending on the definition of double at compile time.

Parameters
[in,out]strmThe stream to write into
[in]valueThe float to write
Returns
Reference to the stream

Definition at line 190 of file FileHelpers.cpp.

◆ writeInt()

std::ostream & FileHelpers::writeInt ( std::ostream &  strm,
int  value 
)
static

Writes an integer binary.

Parameters
[in,out]strmThe stream to write into
[in]valueThe integer to write
Returns
Reference to the stream

Definition at line 183 of file FileHelpers.cpp.

Referenced by writeEdgeVector(), and writeString().

Here is the caller graph for this function:

◆ writeString()

std::ostream & FileHelpers::writeString ( std::ostream &  strm,
const std::string &  value 
)
static

Writes a string binary.

Writes the length of the string, first, using writeInt. Writes then the string's characters.

See also
writeInt
Parameters
[in,out]strmThe stream to write into
[in]valueThe string to write
Returns
Reference to the stream

Definition at line 204 of file FileHelpers.cpp.

References writeInt().

◆ writeTime()

std::ostream & FileHelpers::writeTime ( std::ostream &  strm,
SUMOTime  value 
)
static

Writes a time description binary.

This method behaves differently depending on the definition of SUMOTime at compile time, which in turn depends on the enabling of subsecond timesteps.

Parameters
[in,out]strmThe stream to write into
[in]valueThe time to write
Returns
Reference to the stream

Definition at line 214 of file FileHelpers.cpp.


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