52 if (path.length() == 0) {
55 while (path[path.length() - 1] ==
'/' || path[path.length() - 1] ==
'\\') {
56 path.erase(path.end() - 1);
58 if (path.length() == 0) {
67 struct _stat64 fileInfo;
73 throw ProcessError(
"Cannot get file attributes for file '" + path +
"'!");
75 return (fileInfo.st_mode & S_IFMT) == S_IFDIR;
84 const std::string::size_type beg = path.find_last_of(
"\\/");
85 if (beg == std::string::npos) {
88 return path.substr(0, beg + 1);
96 }
else if (extension.empty()) {
98 }
else if (path == extension) {
100 }
else if (path.size() < extension.size()) {
101 return path + extension;
104 std::string::const_reverse_iterator it_path = path.rbegin();
105 std::string::const_reverse_iterator it_extension = extension.rbegin();
107 while (it_extension != extension.rend()) {
109 if (*it_path != *it_extension) {
110 return path + extension;
124 return retPath + path;
130 const std::string::size_type colonPos = name.find(
":");
131 return (colonPos != std::string::npos) && (colonPos > 1);
141 if (path.length() > 0 && path[0] ==
'/') {
145 if (path.length() > 0 && path[0] ==
'\\') {
148 if (path.length() > 1 && path[1] ==
':') {
151 if (path ==
"nul" || path ==
"NUL") {
160 if (filename ==
"stdout" || filename ==
"STDOUT" || filename ==
"-") {
163 if (filename ==
"stderr" || filename ==
"STDERR") {
166 if (filename ==
"nul" || filename ==
"NUL") {
179 char* answer = getcwd(buffer,
sizeof(buffer));
187std::vector<std::string>
189 std::vector<std::string> result;
190 for (
const std::string& d :
StringTokenizer(filename,
"\\/",
true).getVector()) {
191 if (d ==
".." && !result.empty() && result.back() !=
"..") {
193 }
else if ((d ==
"" && result.empty()) || (d !=
"" && d !=
".")) {
203 if (filename ==
"stdout" || filename ==
"STDOUT" || filename ==
"-") {
206 if (filename ==
"stderr" || filename ==
"STDERR") {
209 if (filename ==
"nul" || filename ==
"NUL" || filename ==
"/dev/null") {
215 std::vector<std::string> filePathSplit =
splitDirs(filename);
216 std::vector<std::string> basePathSplit =
splitDirs(basePath);
224 filePathSplit =
splitDirs(curDir +
"/" + filename);
227 basePathSplit =
splitDirs(curDir +
"/" + basePath);
229 if (filePathSplit[0] != basePathSplit[0]) {
234 while (!filePathSplit.empty() && !basePathSplit.empty() && filePathSplit[0] == basePathSplit[0]) {
235 filePathSplit.erase(filePathSplit.begin());
236 basePathSplit.erase(basePathSplit.begin());
238 for (
int i = 0; i < (int)basePathSplit.size() - 1; i++) {
239 filePathSplit.insert(filePathSplit.begin(),
"..");
247 const std::string::size_type sep_index = path.find_last_of(
"\\/");
248 if (sep_index == std::string::npos) {
249 return prefix + path;
251 return path.substr(0, sep_index + 1) + prefix + path.substr(sep_index + 1);
261 strm.write((
char*) &value,
sizeof(
int));
268 strm.write((
char*) &value,
sizeof(
double));
275 strm.write((
char*) &value,
sizeof(
char));
282 int size = (int)value.length();
283 const char* cstr = value.c_str();
285 strm.write((
char*) cstr, (std::streamsize)(
sizeof(
char)*size));
292 strm.write((
char*) &value,
sizeof(
SUMOTime));
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
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 bool isAbsolute(const std::string &path)
Returns the information whether the given path is absolute.
static std::ostream & writeFloat(std::ostream &strm, double value)
Writes a float binary.
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 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 addExtension(const std::string &path, const std::string &extension)
Add an extension to the given file path.
static std::ostream & writeString(std::ostream &strm, const std::string &value)
Writes a string binary.
static bool isReadable(std::string path)
Checks whether the given file is readable.
static std::vector< std::string > splitDirs(const std::string &filename)
Splits the given file path into directory components.
static std::string getFilePath(const std::string &path)
Removes the file information from the given path.
static std::ostream & writeTime(std::ostream &strm, SUMOTime value)
Writes a time description binary.
static std::ostream & writeInt(std::ostream &strm, int value)
Writes an integer binary.
static bool isSocket(const std::string &name)
Returns the information whether the given name represents a socket.
static bool isDirectory(std::string path)
Checks whether the given file is a directory.
static std::string getCurrentDir()
Get the current working directory.
static std::ostream & writeByte(std::ostream &strm, unsigned char value)
Writes a byte binary.
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
static std::string transcodeToLocal(const std::string &utf8String)
convert a string from UTF-8 to the local codepage