SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FileHelpers Class Reference

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

#include <FileHelpers.h>

Static Public Member Functions

static std::ostream & writeTime (std::ostream &strm, SUMOTime value)
 Writes a time description binary.
file access functions
static bool exists (std::string path)
 Checks whether the given file exists.
file path evaluating functions
static std::string getFilePath (const std::string &path)
 Removes the file information from the given path.
static std::string getConfigurationRelative (const std::string &configPath, const std::string &path)
 Returns the second path as a relative path to the first file.
static bool isSocket (const std::string &name)
 Returns the information whether the given name represents a socket.
static bool isAbsolute (const std::string &path)
 Returns the information whether the given path is absolute.
static std::string checkForRelativity (std::string filename, const std::string &basePath)
 Returns the path from a configuration so that it is accessable from the current working directory.
binary writing functions
static std::ostream & writeInt (std::ostream &strm, int value)
 Writes an integer binary.
static std::ostream & writeUInt (std::ostream &strm, unsigned int value)
 Writes an unsigned integer binary.
static std::ostream & writeFloat (std::ostream &strm, SUMOReal value)
 Writes a float binary.
static std::ostream & writeByte (std::ostream &strm, unsigned char value)
 Writes a byte binary.
static std::ostream & writeString (std::ostream &strm, const std::string &value)
 Writes a string binary.

Detailed Description

Functions for an easier usage of files and paths.

Definition at line 46 of file FileHelpers.h.

Member Function Documentation

std::string FileHelpers::checkForRelativity ( 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 120 of file FileHelpers.cpp.

References getConfigurationRelative(), and isAbsolute().

Referenced by OutputDevice::getDevice().

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 82 of file FileHelpers.cpp.

References getFilePath().

Referenced by checkForRelativity(), NLTriggerBuilder::getFileName(), GUISettingsHandler::myStartElement(), OptionsCont::relocateFiles(), and GenericSAXHandler::startElement().

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 72 of file FileHelpers.cpp.

Referenced by getConfigurationRelative(), RODFDetectorCon::writeEmitters(), and RODFDetectorCon::writeSpeedTrigger().

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 97 of file FileHelpers.cpp.

References isSocket().

Referenced by checkForRelativity(), NLTriggerBuilder::getFileName(), GUISettingsHandler::myStartElement(), OptionsCont::relocateFiles(), and GenericSAXHandler::startElement().

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 90 of file FileHelpers.cpp.

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

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 154 of file FileHelpers.cpp.

Referenced by BinaryFormatter::closeTag(), BinaryFormatter::openTag(), BinaryFormatter::writeAttr(), BinaryFormatter::writeAttrHeader(), BinaryFormatter::writeStringList(), and BinaryFormatter::writeXMLHeader().

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

Writes a float binary.

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

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

Definition at line 147 of file FileHelpers.cpp.

References SUMOReal.

Referenced by MSVehicleType::saveState(), and BinaryFormatter::writeAttr().

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 133 of file FileHelpers.cpp.

Referenced by BinaryFormatter::closeTag(), BinaryFormatter::openTag(), MSVehicleType::saveState(), BinaryFormatter::writeAttr(), BinaryFormatter::writeAttrHeader(), and BinaryFormatter::writeStringList().

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 161 of file FileHelpers.cpp.

References writeUInt().

Referenced by MSVehicleType::saveState(), BinaryFormatter::writeAttr(), BinaryFormatter::writeStringList(), and BinaryFormatter::writeXMLHeader().

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 171 of file FileHelpers.cpp.

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

Writes an unsigned integer binary.

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

Definition at line 140 of file FileHelpers.cpp.

Referenced by writeString().


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