aboutsummaryrefslogtreecommitdiffstats
path: root/src/fs/Path.hxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/fs/Path.hxx106
1 files changed, 19 insertions, 87 deletions
diff --git a/src/fs/Path.hxx b/src/fs/Path.hxx
index 558e2923f..6ea954577 100644
--- a/src/fs/Path.hxx
+++ b/src/fs/Path.hxx
@@ -24,50 +24,33 @@
#include "Compiler.h"
#include "Traits.hxx"
-#ifdef WIN32
-#include <glib.h>
-#endif
-
-#include <utility>
#include <string>
#include <assert.h>
+#include <string.h>
class Error;
/**
* A path name in the native file system character set.
+ *
+ * This class manages a pointer to an existing path string. While an
+ * instance lives, the string must not be invalidated.
*/
class Path {
- typedef std::string string;
-
typedef PathTraits::value_type value_type;
typedef PathTraits::pointer pointer;
typedef PathTraits::const_pointer const_pointer;
- string value;
-
- struct Donate {};
+ const char *value;
- /**
- * Donate the allocated pointer to a new #Path object.
- */
- Path(Donate, pointer _value);
-
- Path(const_pointer _value):value(_value) {}
+ constexpr Path(const_pointer _value):value(_value) {}
public:
/**
* Copy a #Path object.
*/
- Path(const Path &) = default;
-
- /**
- * Move a #Path object.
- */
- Path(Path &&other):value(std::move(other.value)) {}
-
- ~Path();
+ constexpr Path(const Path &) = default;
/**
* Return a "nulled" instance. Its IsNull() method will
@@ -75,70 +58,29 @@ public:
*
* @see IsNull()
*/
- gcc_const
- static Path Null() {
- return Path("");
+ static constexpr Path Null() {
+ return Path(nullptr);
}
/**
- * Join two path components with the path separator.
+ * Create a new instance pointing to the specified path
+ * string.
*/
- gcc_pure gcc_nonnull_all
- static Path Build(const_pointer a, const_pointer b);
-
- gcc_pure gcc_nonnull_all
- static Path Build(const_pointer a, const Path &b) {
- return Build(a, b.c_str());
- }
-
- gcc_pure gcc_nonnull_all
- static Path Build(const Path &a, const_pointer b) {
- return Build(a.c_str(), b);
- }
-
- gcc_pure
- static Path Build(const Path &a, const Path &b) {
- return Build(a.c_str(), b.c_str());
- }
-
- /**
- * Convert a C string that is already in the filesystem
- * character set to a #Path instance.
- */
- gcc_pure
- static Path FromFS(const_pointer fs) {
+ static constexpr Path FromFS(const_pointer fs) {
return Path(fs);
}
/**
- * Convert a UTF-8 C string to a #Path instance.
- * Returns return a "nulled" instance on error.
- */
- gcc_pure gcc_nonnull_all
- static Path FromUTF8(const char *path_utf8);
-
- gcc_pure gcc_nonnull_all
- static Path FromUTF8(const char *path_utf8, Error &error);
-
- /**
* Copy a #Path object.
*/
Path &operator=(const Path &) = default;
/**
- * Move a #Path object.
- */
- Path &operator=(Path &&other) {
- value = std::move(other.value);
- return *this;
- }
-
- /**
* Check if this is a "nulled" instance. A "nulled" instance
* must not be used.
*/
bool IsNull() const {
- return value.empty();
+ return value == nullptr;
}
/**
@@ -147,7 +89,7 @@ public:
* @see IsNull()
*/
void SetNull() {
- value.clear();
+ value = nullptr;
}
/**
@@ -156,7 +98,9 @@ public:
*/
gcc_pure
size_t length() const {
- return value.length();
+ assert(value != nullptr);
+
+ return strlen(value);
}
/**
@@ -166,7 +110,7 @@ public:
*/
gcc_pure
const_pointer c_str() const {
- return value.c_str();
+ return value;
}
/**
@@ -175,7 +119,7 @@ public:
*/
gcc_pure
const_pointer data() const {
- return value.data();
+ return value;
}
/**
@@ -187,13 +131,6 @@ public:
std::string ToUTF8() const;
/**
- * Gets directory name of this path.
- * Returns a "nulled" instance on error.
- */
- gcc_pure
- Path GetDirectoryName() const;
-
- /**
* Determine the relative part of the given path to this
* object, not including the directory separator. Returns an
* empty string if the given path equals this object or
@@ -202,11 +139,6 @@ public:
gcc_pure
const char *RelativeFS(const char *other_fs) const;
- /**
- * Chop trailing directory separators.
- */
- void ChopSeparators();
-
gcc_pure
bool IsAbsolute() {
return PathTraits::IsAbsoluteFS(c_str());