aboutsummaryrefslogtreecommitdiffstats
path: root/src/fs/AllocatedPath.hxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/fs/AllocatedPath.hxx74
1 files changed, 56 insertions, 18 deletions
diff --git a/src/fs/AllocatedPath.hxx b/src/fs/AllocatedPath.hxx
index 36d8a1598..c345470c8 100644
--- a/src/fs/AllocatedPath.hxx
+++ b/src/fs/AllocatedPath.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -28,8 +28,6 @@
#include <utility>
#include <string>
-#include <assert.h>
-
class Error;
/**
@@ -39,11 +37,10 @@ class Error;
* stored.
*/
class AllocatedPath {
- typedef std::string string;
-
- typedef PathTraits::value_type value_type;
- typedef PathTraits::pointer pointer;
- typedef PathTraits::const_pointer const_pointer;
+ typedef PathTraitsFS::string string;
+ typedef PathTraitsFS::value_type value_type;
+ typedef PathTraitsFS::pointer pointer;
+ typedef PathTraitsFS::const_pointer const_pointer;
string value;
@@ -56,17 +53,25 @@ class AllocatedPath {
AllocatedPath(const_pointer _value):value(_value) {}
+ AllocatedPath(string &&_value):value(std::move(_value)) {}
+
+ static AllocatedPath Build(const_pointer a, size_t a_size,
+ const_pointer b, size_t b_size) {
+ return AllocatedPath(PathTraitsFS::Build(a, a_size, b, b_size));
+ }
public:
/**
- * Copy a #AllocatedPath object.
+ * Copy an #AllocatedPath object.
*/
AllocatedPath(const AllocatedPath &) = default;
/**
- * Move a #AllocatedPath object.
+ * Move an #AllocatedPath object.
*/
AllocatedPath(AllocatedPath &&other):value(std::move(other.value)) {}
+ explicit AllocatedPath(Path other):value(other.c_str()) {}
+
~AllocatedPath();
/**
@@ -89,22 +94,38 @@ public:
* Join two path components with the path separator.
*/
gcc_pure gcc_nonnull_all
- static AllocatedPath Build(const_pointer a, const_pointer b);
+ static AllocatedPath Build(const_pointer a, const_pointer b) {
+ return Build(a, PathTraitsFS::GetLength(a),
+ b, PathTraitsFS::GetLength(b));
+ }
gcc_pure gcc_nonnull_all
- static AllocatedPath Build(const_pointer a, const AllocatedPath &b) {
+ static AllocatedPath Build(Path a, const_pointer b) {
+ return Build(a.c_str(), b);
+ }
+
+ gcc_pure gcc_nonnull_all
+ static AllocatedPath Build(Path a, Path b) {
return Build(a, b.c_str());
}
gcc_pure gcc_nonnull_all
+ static AllocatedPath Build(const_pointer a, const AllocatedPath &b) {
+ return Build(a, PathTraitsFS::GetLength(a),
+ b.value.c_str(), b.value.size());
+ }
+
+ gcc_pure gcc_nonnull_all
static AllocatedPath Build(const AllocatedPath &a, const_pointer b) {
- return Build(a.c_str(), b);
+ return Build(a.value.c_str(), a.value.size(),
+ b, PathTraitsFS::GetLength(b));
}
gcc_pure
static AllocatedPath Build(const AllocatedPath &a,
const AllocatedPath &b) {
- return Build(a.c_str(), b.c_str());
+ return Build(a.value.c_str(), a.value.size(),
+ b.value.c_str(), b.value.size());
}
/**
@@ -117,7 +138,16 @@ public:
}
/**
- * Convert a UTF-8 C string to a #AllocatedPath instance.
+ * Convert a C++ string that is already in the filesystem
+ * character set to a #Path instance.
+ */
+ gcc_pure
+ static AllocatedPath FromFS(string &&fs) {
+ return AllocatedPath(std::move(fs));
+ }
+
+ /**
+ * Convert a UTF-8 C string to an #AllocatedPath instance.
* Returns return a "nulled" instance on error.
*/
gcc_pure gcc_nonnull_all
@@ -127,12 +157,12 @@ public:
static AllocatedPath FromUTF8(const char *path_utf8, Error &error);
/**
- * Copy a #AllocatedPath object.
+ * Copy an #AllocatedPath object.
*/
AllocatedPath &operator=(const AllocatedPath &) = default;
/**
- * Move a #AllocatedPath object.
+ * Move an #AllocatedPath object.
*/
AllocatedPath &operator=(AllocatedPath &&other) {
value = std::move(other.value);
@@ -140,6 +170,14 @@ public:
}
/**
+ * Allows the caller to "steal" the internal value by
+ * providing a rvalue reference to the std::string attribute.
+ */
+ std::string &&Steal() {
+ return std::move(value);
+ }
+
+ /**
* Check if this is a "nulled" instance. A "nulled" instance
* must not be used.
*/
@@ -215,7 +253,7 @@ public:
gcc_pure
bool IsAbsolute() {
- return PathTraits::IsAbsoluteFS(c_str());
+ return PathTraitsFS::IsAbsolute(c_str());
}
};