Eclipse SUMO - Simulation of Urban MObility
|
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. | |
static bool | isDirectory (std::string path) |
Checks whether the given file is a directory. | |
file path evaluating functions | |
static std::string | getFilePath (const std::string &path) |
Removes the file information from the given path. | |
static std::string | getFileFromPath (std::string path, const bool removeExtension) |
Removes the path information from the given path. | |
static std::string | addExtension (const std::string &path, const std::string &extension) |
Add an extension to the given file 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 (const std::string &filename, const std::string &basePath) |
Returns the path from a configuration so that it is accessable from the current working directory. | |
static std::string | getCurrentDir () |
Get the current working directory. | |
static std::vector< std::string > | splitDirs (const std::string &filename) |
Splits the given file path into directory components. | |
static std::string | fixRelative (const std::string &filename, const std::string &basePath, const bool force, std::string curDir="") |
Fixes the relative path for the given filename in relation to the basePath (usually a config file). | |
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 | |
binary writing functions | |
static std::ostream & | writeInt (std::ostream &strm, int value) |
Writes an integer binary. | |
static std::ostream & | writeFloat (std::ostream &strm, double 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. | |
static std::ostream & | writeTime (std::ostream &strm, SUMOTime value) |
Writes a time description binary. | |
template<typename E > | |
static std::ostream & | writeEdgeVector (std::ostream &os, const std::vector< E > &edges) |
Writes an edge vector binary. | |
template<typename E > | |
static void | readEdgeVector (std::istream &in, std::vector< const E * > &edges, const std::string &rid) |
Reads an edge vector binary. | |
Functions for an easier usage of files and paths.
Definition at line 38 of file FileHelpers.h.
|
static |
Add an extension to the given file path.
[in] | path | The path to the file |
[in] | extension | new extension (with dot, example: '.xml') |
Definition at line 111 of file FileHelpers.cpp.
Referenced by GNETLSEditorFrame::TLSFile::onCmdSaveTLSProgram().
|
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).
[in] | filename | The path to the file to be examined |
[in] | basePath | The path the configuration file (including the config's file name) |
Definition at line 177 of file FileHelpers.cpp.
References getConfigurationRelative(), and isAbsolute().
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(), NEMALogic::NEMALogic(), and OptionsCont::relocateFiles().
|
static |
Fixes the relative path for the given filename in relation to the basePath (usually a config file).
[in] | filename | The path of a file |
[in] | basePath | The path of another file referring to the former |
[in] | force | whether the replacement should be made even if the filename is absolute |
[in] | curDir | the current working dir (mainly for easier testing), "" will trigger a call of getCurrentDir |
Definition at line 220 of file FileHelpers.cpp.
References getCurrentDir(), isAbsolute(), isSocket(), joinToString(), and splitDirs().
Referenced by OptionsCont::writeConfiguration().
|
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.
[in] | configPath | The path the configuration file (including the config's file name) |
[in] | path | The path to the references file (relativ to configuration path) |
Definition at line 140 of file FileHelpers.cpp.
References getFilePath().
Referenced by ShapeHandler::addPOI(), ShapeHandler::addPoly(), SUMOVehicleParserHelper::beginVTypeParsing(), checkForRelativity(), NWFrame::checkOptions(), NLTriggerBuilder::getFileName(), main(), NIImporter_OpenDrive::myStartElement(), GUISettingsHandler::myStartElement(), GenericHandler::startElement(), and GenericSAXHandler::startElement().
|
static |
Get the current working directory.
Definition at line 195 of file FileHelpers.cpp.
Referenced by fixRelative().
|
static |
Removes the path information from the given path.
[in] | path | The path to the file to return the file (with extension) |
Definition at line 93 of file FileHelpers.cpp.
|
static |
Removes the file information from the given path.
[in] | path | The path to the file to return the folder it is located in |
Definition at line 83 of file FileHelpers.cpp.
Referenced by getConfigurationRelative(), GNEApplicationWindow::onCmdSaveNeteditConfig(), GNENetDiffTool::setCurrentValues(), RODFDetectorCon::writeEmitters(), RODFDetectorCon::writeSpeedTrigger(), SUMOPolygon::writeXML(), and PointOfInterest::writeXML().
|
static |
Returns the information whether the given path is absolute.
A path is meant to be absolute, if
[in] | path | The path to examine |
Definition at line 154 of file FileHelpers.cpp.
References isSocket().
Referenced by ShapeHandler::addPOI(), ShapeHandler::addPoly(), SUMOVehicleParserHelper::beginVTypeParsing(), checkForRelativity(), fixRelative(), NLTriggerBuilder::getFileName(), NIImporter_OpenDrive::myStartElement(), GUISettingsHandler::myStartElement(), GenericHandler::startElement(), and GenericSAXHandler::startElement().
|
static |
Checks whether the given file is a directory.
[in] | path | The path to the file that shall be examined |
Definition at line 65 of file FileHelpers.cpp.
References TLF, and StringUtils::transcodeToLocal().
Referenced by OptionsIO::getRoot(), SUMOSAXReader::parse(), and SUMOSAXReader::parseFirst().
|
static |
Checks whether the given file is readable.
[in] | path | The path to the file that shall be examined |
Definition at line 51 of file FileHelpers.cpp.
References StringUtils::transcodeToLocal().
Referenced by NIImporter_SUMO::_loadNetwork(), NLBuilder::buildRouteLoaderControl(), OptionsIO::getRoot(), OptionsCont::isUsableFileList(), NIImporter_OpenStreetMap::load(), PCNetProjectionLoader::load(), NITypeLoader::load(), GNEApplicationWindow::loadAdditionalElements(), OptionsIO::loadConfiguration(), GNEApplicationWindow::loadDataElements(), GNEApplicationWindow::loadDemandElements(), ODDistrictCont::loadDistricts(), PCLoaderOSM::loadIfSet(), PCLoaderVisum::loadIfSet(), PCLoaderXML::loadIfSet(), ODMatrix::loadMatrix(), GNEApplicationWindow::loadMeanDataElements(), loadNet(), ROLoader::loadNet(), NIImporter_ArcView::loadNetwork(), NIImporter_ITSUMO::loadNetwork(), PCLoaderDlrNavteq::loadPOIFiles(), PCLoaderDlrNavteq::loadPolyFiles(), ODMatrix::loadRoutes(), GUIApplicationWindow::onCmdNewWindow(), GNEApplicationWindow::onCmdNewWindow(), GUIApplicationWindow::onCmdOpenInNetedit(), GNEApplicationWindow::onCmdOpenSUMOGUI(), SUMOSAXReader::parse(), SUMOSAXReader::parseFirst(), readDetectorFlows(), readDetectors(), SUMOSAXReader::LocalSchemaResolver::resolveEntity(), and XMLSubSys::setValidation().
|
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.
[in] | name | The name of a file |
Definition at line 147 of file FileHelpers.cpp.
Referenced by fixRelative(), OutputDevice::getDevice(), and isAbsolute().
|
static |
prepend the given prefix to the last path component of the given file path
Definition at line 264 of file FileHelpers.cpp.
Referenced by OutputDevice::getDevice().
|
static |
Reads an edge vector binary.
[in] | is | The stream to read from |
[out] | edges | The edge vector to write into |
Definition at line 293 of file FileHelpers.h.
References TLF.
|
static |
Splits the given file path into directory components.
The path gets normalized such that redundant "." and empty components are removed. Furthermore it will not contain a ".." after a directory name.
[in] | filename | The path of a file |
Definition at line 206 of file FileHelpers.cpp.
References StringTokenizer::getVector().
Referenced by fixRelative().
|
static |
Writes a byte binary.
[in,out] | strm | The stream to write into |
[in] | value | The byte to write |
Definition at line 292 of file FileHelpers.cpp.
|
static |
Writes an edge vector binary.
[in,out] | os | The stream to write into |
[in] | edges | The edges to write |
Definition at line 237 of file FileHelpers.h.
References writeInt().
|
static |
Writes a float binary.
This method behaves differently depending on the definition of double at compile time.
[in,out] | strm | The stream to write into |
[in] | value | The float to write |
Definition at line 285 of file FileHelpers.cpp.
|
static |
Writes an integer binary.
[in,out] | strm | The stream to write into |
[in] | value | The integer to write |
Definition at line 278 of file FileHelpers.cpp.
Referenced by writeEdgeVector(), and writeString().
|
static |
Writes a string binary.
Writes the length of the string, first, using writeInt. Writes then the string's characters.
[in,out] | strm | The stream to write into |
[in] | value | The string to write |
Definition at line 299 of file FileHelpers.cpp.
References writeInt().
|
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.
[in,out] | strm | The stream to write into |
[in] | value | The time to write |
Definition at line 309 of file FileHelpers.cpp.