#include <FileHelpers.h>
Definition at line 44 of file FileHelpers.h.
Static Public Member Functions | |
| static std::ostream & | writeTime (std::ostream &strm, SUMOTime value) |
| Writes a time description binary. | |
file path evaluating functions | |
| 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. | |
| 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 std::string | getFilePath (const std::string &path) |
| Removes the file information from the given path. | |
| static bool | isAbsolute (const std::string &path) |
| Returns the information whether the given path is absolute. | |
| static bool | isSocket (const std::string &name) |
| Returns the information whether the given name represents a socket. | |
file access functions | |
| static bool | exists (std::string path) |
| Checks whether the given file exists. | |
binary writing functions | |
| static std::ostream & | writeByte (std::ostream &strm, unsigned char value) |
| Writes a byte binary. | |
| static std::ostream & | writeFloat (std::ostream &strm, SUMOReal value) |
| Writes a float binary. | |
| static std::ostream & | writeInt (std::ostream &strm, int value) |
| Writes an integer binary. | |
| static std::ostream & | writeString (std::ostream &strm, const std::string &value) |
| Writes a string binary. | |
| static std::ostream & | writeUInt (std::ostream &strm, unsigned int value) |
| Writes an unsigned integer binary. | |
| 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).
| [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 118 of file FileHelpers.cpp.
References getConfigurationRelative(), and isAbsolute().
Referenced by OutputDevice::getDevice().
00119 { 00120 if (!isAbsolute(filename)) { 00121 filename = getConfigurationRelative(basePath, filename); 00122 } 00123 return filename; 00124 }
| bool FileHelpers::exists | ( | std::string | path | ) | [static] |
Checks whether the given file exists.
| [in] | path | The path to the file that shall be examined |
Definition at line 50 of file FileHelpers.cpp.
Referenced by NLBuilder::buildRouteLoaderControl(), OptionsCont::isUsableFileList(), OptionsIO::loadConfiguration(), loadDistricts(), PCNetProjectionLoader::loadIfSet(), PCLoaderXML::loadIfSet(), PCLoaderVisum::loadIfSet(), PCLoaderOSM::loadIfSet(), ROLoader::loadNet(), NIImporter_SUMO::loadNetwork(), NIImporter_RobocupRescue::loadNetwork(), NIImporter_OpenStreetMap::loadNetwork(), NIImporter_OpenDrive::loadNetwork(), NIImporter_ArcView::loadNetwork(), PCLoaderDlrNavteq::loadPOIFiles(), PCLoaderDlrNavteq::loadPolyFiles(), NILoader::loadXMLType(), readDetectorFlows(), and readDetectors().
00050 { 00051 if (path.length()==0) { 00052 return false; 00053 } 00054 while (path[path.length()-1]=='/'||path[path.length()-1]=='\\') { 00055 path.erase(path.end()-1); 00056 } 00057 if (path.length()==0) { 00058 return false; 00059 } 00060 struct stat st; 00061 bool ret = (stat(path.c_str(), &st) == 0); 00062 return ret; 00063 }
| 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.
| [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 80 of file FileHelpers.cpp.
References getFilePath().
Referenced by checkForRelativity(), NLTriggerBuilder::getFileName(), GUISettingsHandler::myStartElement(), OptionsCont::relocateFiles(), and GenericSAXHandler::startElement().
00081 { 00082 std::string retPath = getFilePath(configPath); 00083 return retPath + path; 00084 }
| std::string FileHelpers::getFilePath | ( | const std::string & | path | ) | [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 70 of file FileHelpers.cpp.
Referenced by getConfigurationRelative(), RODFDetectorCon::writeEmitters(), and RODFDetectorCon::writeSpeedTrigger().
00070 { 00071 size_t beg = path.find_last_of("\\/"); 00072 if (beg==std::string::npos||beg==0) { 00073 return ""; 00074 } 00075 return path.substr(0, beg+1); 00076 }
| 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
| [in] | path | The path to examine |
Definition at line 95 of file FileHelpers.cpp.
References isSocket().
Referenced by checkForRelativity(), NLTriggerBuilder::getFileName(), GUISettingsHandler::myStartElement(), OptionsCont::relocateFiles(), and GenericSAXHandler::startElement().
00095 { 00096 if (isSocket(path)) { 00097 return true; 00098 } 00099 // check UNIX - absolute paths 00100 if (path.length()>0&&path[0]=='/') { 00101 return true; 00102 } 00103 // check Windows - absolute paths 00104 if (path.length()>0&&path[0]=='\\') { 00105 return true; 00106 } 00107 if (path.length()>1&&path[1]==':') { 00108 return true; 00109 } 00110 if (path=="nul"||path=="NUL") { 00111 return true; 00112 } 00113 return false; 00114 }
| 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.
| [in] | name | The name of a file |
Definition at line 88 of file FileHelpers.cpp.
Referenced by OutputDevice::getDevice(), and isAbsolute().
00088 { 00089 size_t colonPos = name.find(":"); 00090 return (colonPos != std::string::npos) && (colonPos > 1); 00091 }
| std::ostream & FileHelpers::writeByte | ( | std::ostream & | strm, | |
| unsigned char | value | |||
| ) | [static] |
Writes a byte binary.
| [in,out] | strm | The stream to write into |
| [in] | value | The byte to write |
Definition at line 152 of file FileHelpers.cpp.
| 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.
| [in,out] | strm | The stream to write into |
| [in] | value | The float to write |
Definition at line 145 of file FileHelpers.cpp.
References SUMOReal.
Referenced by MSVehicleType::saveState(), and MSVehicle::saveState().
00145 { 00146 strm.write((char*) &value, sizeof(SUMOReal)); 00147 return strm; 00148 }
| std::ostream & FileHelpers::writeInt | ( | std::ostream & | strm, | |
| int | value | |||
| ) | [static] |
Writes an integer binary.
| [in,out] | strm | The stream to write into |
| [in] | value | The integer to write |
Definition at line 131 of file FileHelpers.cpp.
Referenced by MSVehicleType::saveState(), and MSVehicle::saveState().
| 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.
| [in,out] | strm | The stream to write into |
| [in] | value | The string to write |
Definition at line 159 of file FileHelpers.cpp.
References size, and writeUInt().
Referenced by MSVehicleType::saveState(), and MSVehicle::saveState().
00159 { 00160 size_t size = value.length(); 00161 const char *cstr = value.c_str(); 00162 writeUInt(strm, (unsigned int) size); 00163 strm.write((char*) cstr, (std::streamsize)(sizeof(char)*size)); 00164 return strm; 00165 }
| 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.
| [in,out] | strm | The stream to write into |
| [in] | value | The time to write |
Definition at line 169 of file FileHelpers.cpp.
Referenced by MSVehicle::saveState().
00169 { 00170 strm.write((char*) &value, sizeof(SUMOTime)); 00171 return strm; 00172 }
| std::ostream & FileHelpers::writeUInt | ( | std::ostream & | strm, | |
| unsigned int | value | |||
| ) | [static] |
Writes an unsigned integer binary.
| [in,out] | strm | The stream to write into |
| [in] | value | The unsigned integer to write |
Definition at line 138 of file FileHelpers.cpp.
Referenced by MSVehicle::saveState(), and writeString().
1.5.6