diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-01-12 23:49:43 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-01-12 23:49:43 (GMT) |
commit | a116aeb2cf5a84fa03f9814c3884561149029267 (patch) | |
tree | bdd7dfc15ec1e38edcc9a7532ffad03fe4f6f823 /src/uscxml/URL.cpp | |
parent | 6d0622c0bb8f0e52589c82252f2cc1eb847ad9bf (diff) | |
download | uscxml-a116aeb2cf5a84fa03f9814c3884561149029267.zip uscxml-a116aeb2cf5a84fa03f9814c3884561149029267.tar.gz uscxml-a116aeb2cf5a84fa03f9814c3884561149029267.tar.bz2 |
Refactored to PIMPL pattern
Diffstat (limited to 'src/uscxml/URL.cpp')
-rw-r--r-- | src/uscxml/URL.cpp | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/uscxml/URL.cpp b/src/uscxml/URL.cpp index 592c0c6..59fca34 100644 --- a/src/uscxml/URL.cpp +++ b/src/uscxml/URL.cpp @@ -19,6 +19,14 @@ #include "uscxml/config.h" +#include <stdio.h> /* defines FILENAME_MAX */ +#ifdef WIN32 +#include <direct.h> +#define getcwd _getcwd +#else +#include <unistd.h> +#endif + #include <cstdlib> // mkstemp #ifdef HAS_UNISTD_H #include <unistd.h> // mkstemp legacy @@ -26,38 +34,30 @@ namespace uscxml { -URL::~URL() { +URLImpl::~URLImpl() { if (_localFile.length() > 0) remove(_localFile.c_str()); } - -const bool URL::toAbsolute(const std::string& baseUrl) { + +const bool URLImpl::toAbsoluteCwd() { + char currPath[FILENAME_MAX]; + if (!getcwd(currPath, sizeof(currPath))) { + return false; + } + currPath[sizeof(currPath) - 1] = '\0'; /* not really required */ + return toAbsolute(std::string("file://" + std::string(currPath) + "/")); +} + +const bool URLImpl::toAbsolute(const std::string& baseUrl) { if (_uri.is_absolute()) return true; - - Arabica::io::URI baseUri(baseUrl); - if (!baseUri.is_absolute()) + _uri = Arabica::io::URI(baseUrl, _uri.as_string()); + if (!_uri.is_absolute()) return false; - - std::stringstream ssAbsoluteURI; - if (baseUri.scheme().size() > 0) - ssAbsoluteURI << baseUri.scheme() << "://"; - if (baseUri.host().size() > 0) { - ssAbsoluteURI << baseUri.host(); - if (!boost::iequals(baseUri.port(), "0")) - ssAbsoluteURI << ":" << baseUri.port(); - } - if (baseUri.path().size() > 0) { - ssAbsoluteURI << baseUri.path() << "/" << _uri.path(); - } else { - ssAbsoluteURI << "/" << _uri.path(); - } - _uri = Arabica::io::URI(ssAbsoluteURI.str()); - assert(_uri.is_absolute()); return true; } -const std::string URL::asLocalFile(const std::string& suffix, bool reload) { +const std::string URLImpl::asLocalFile(const std::string& suffix, bool reload) { // this is already a local file if (_uri.scheme().compare("file") == 0) return _uri.path(); @@ -69,7 +69,7 @@ const std::string URL::asLocalFile(const std::string& suffix, bool reload) { remove(_localFile.c_str()); // try hard to find a temporary directory - char* tmpDir = NULL; + const char* tmpDir = NULL; if (tmpDir == NULL) tmpDir = getenv("TMPDIR"); if (tmpDir == NULL) @@ -78,6 +78,8 @@ const std::string URL::asLocalFile(const std::string& suffix, bool reload) { tmpDir = getenv("TEMP"); if (tmpDir == NULL) tmpDir = getenv("USERPROFILE"); + if (tmpDir == NULL) + tmpDir = "/tmp"; char* tmpl = (char*)malloc(strlen(tmpDir) + 11 + suffix.length()); char* writePtr = tmpl; @@ -97,7 +99,7 @@ const std::string URL::asLocalFile(const std::string& suffix, bool reload) { std::ofstream file(tmpl, std::ios_base::out); if(file.is_open()) { - file << *this; + file << URL(this->shared_from_this()); file.close(); } else { _localFile = ""; |