MPD  0.20.18
Path.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2003-2017 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef MPD_FS_PATH_HXX
21 #define MPD_FS_PATH_HXX
22 
23 #include "check.h"
24 #include "Compiler.h"
25 #include "Traits.hxx"
26 
27 #include <string>
28 
29 #include <assert.h>
30 
31 class AllocatedPath;
32 
39 class Path : public PathTraitsFS::Pointer {
41 
42  constexpr Path(const_pointer_type _value):Base(_value) {}
43 
44 public:
48  constexpr Path(const Path &) = default;
49 
56  static constexpr Path Null() {
57  return Path(nullptr);
58  }
59 
64  static constexpr Path FromFS(const_pointer_type fs) {
65  return Path(fs);
66  }
67 
71  Path &operator=(const Path &) = default;
72 
77  bool IsNull() const {
78  return Base::IsNull();
79  }
80 
86  void SetNull() {
87  *this = nullptr;
88  }
89 
94  gcc_pure
95  size_t length() const noexcept {
96  assert(!IsNull());
97 
99  }
100 
106  gcc_pure
107  const_pointer_type c_str() const noexcept {
108  return Base::c_str();
109  }
110 
115  gcc_pure
116  const_pointer_type data() const noexcept {
117  return c_str();
118  }
119 
125  gcc_pure
126  bool HasNewline() const noexcept {
127  return PathTraitsFS::Find(c_str(), '\n') != nullptr;
128  }
129 
135  gcc_pure
136  std::string ToUTF8() const noexcept;
137 
142  gcc_pure
143  Path GetBase() const noexcept {
145  }
146 
151  gcc_pure
152  AllocatedPath GetDirectoryName() const noexcept;
153 
160  gcc_pure
161  const_pointer_type Relative(Path other_fs) const noexcept {
162  return PathTraitsFS::Relative(c_str(), other_fs.c_str());
163  }
164 
165  gcc_pure
166  bool IsAbsolute() const noexcept {
168  }
169 
170  gcc_pure
171  const_pointer_type GetSuffix() const noexcept;
172 };
173 
174 #endif
Simple OO wrapper for a const string pointer.
gcc_pure const_pointer_type Relative(Path other_fs) const noexcept
Determine the relative part of the given path to this object, not including the directory separator...
Definition: Path.hxx:161
gcc_pure AllocatedPath GetDirectoryName() const noexcept
Gets directory name of this path.
Path & operator=(const Path &)=default
Copy a Path object.
constexpr bool IsNull() const
Check if this is a "nulled" instance.
void SetNull()
Clear this object's value, make it "nulled".
Definition: Path.hxx:86
gcc_pure const_pointer_type GetSuffix() const noexcept
A path name in the native file system character set.
gcc_pure size_t length() const noexcept
Definition: Path.hxx:95
gcc_pure static gcc_nonnull_all const_pointer_type Relative(const_pointer_type base, const_pointer_type other) noexcept
Determine the relative part of the given path to this object, not including the directory separator...
gcc_pure const_pointer_type c_str() const noexcept
Returns the value as a const C string.
Definition: Path.hxx:107
gcc_pure const_pointer_type data() const noexcept
Returns a pointer to the raw value, not necessarily null-terminated.
Definition: Path.hxx:116
constexpr const_pointer_type c_str() const
static constexpr Path FromFS(const_pointer_type fs)
Create a new instance pointing to the specified path string.
Definition: Path.hxx:64
gcc_pure static gcc_nonnull_all bool IsAbsolute(const_pointer_type p) noexcept
Definition: Traits.hxx:99
A path name in the native file system character set.
Definition: Path.hxx:39
bool IsNull() const
Check if this is a "nulled" instance.
Definition: Path.hxx:77
const T * const_pointer_type
gcc_pure static gcc_nonnull_all size_t GetLength(const_pointer_type p) noexcept
Definition: Traits.hxx:113
gcc_pure std::string ToUTF8() const noexcept
Convert the path to UTF-8.
static constexpr Path Null()
Return a "nulled" instance.
Definition: Path.hxx:56
gcc_pure static gcc_nonnull_all const_pointer_type Find(const_pointer_type p, value_type ch) noexcept
Definition: Traits.hxx:118
gcc_pure Path GetBase() const noexcept
Determine the "base" file name.
Definition: Path.hxx:143
#define gcc_pure
Definition: Compiler.h:116
gcc_pure bool IsAbsolute() const noexcept
Definition: Path.hxx:166
gcc_pure bool HasNewline() const noexcept
Does the path contain a newline character? (Which is usually rejected by MPD because its protocol can...
Definition: Path.hxx:126
gcc_pure static gcc_nonnull_all const_pointer_type GetBase(const_pointer_type p) noexcept
Determine the "base" file name of the given native path.