MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

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 {
40 typedef PathTraitsFS::Pointer Base;
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 {
96 assert(!IsNull());
97
98 return PathTraitsFS::GetLength(c_str());
99 }
100
106 gcc_pure
107 const_pointer_type c_str() const {
108 return Base::c_str();
109 }
110
115 gcc_pure
116 const_pointer_type data() const {
117 return c_str();
118 }
119
125 gcc_pure
126 bool HasNewline() const {
127 return PathTraitsFS::Find(c_str(), '\n') != nullptr;
128 }
129
135 gcc_pure
136 std::string ToUTF8() const;
137
142 gcc_pure
143 Path GetBase() const {
144 return FromFS(PathTraitsFS::GetBase(c_str()));
145 }
146
151 gcc_pure
152 AllocatedPath GetDirectoryName() const;
153
160 gcc_pure
161 const_pointer_type Relative(Path other_fs) const {
162 return PathTraitsFS::Relative(c_str(), other_fs.c_str());
163 }
164
165 gcc_pure
166 bool IsAbsolute() const {
167 return PathTraitsFS::IsAbsolute(c_str());
168 }
169
170 gcc_pure
171 const_pointer_type GetSuffix() const;
172 };
173
174 #endif
check.h
StringPointer
Simple OO wrapper for a const string pointer.
Definition: StringPointer.hxx:37
Traits.hxx
Path::GetBase
gcc_pure Path GetBase() const
Determine the "base" file name.
Definition: Path.hxx:143
Path::operator=
Path & operator=(const Path &)=default
Copy a Path object.
StringPointer::IsNull
constexpr bool IsNull() const
Check if this is a "nulled" instance.
Definition: StringPointer.hxx:59
Path::Relative
gcc_pure const_pointer_type Relative(Path other_fs) const
Determine the relative part of the given path to this object, not including the directory separator...
Definition: Path.hxx:161
Path::SetNull
void SetNull()
Clear this object's value, make it "nulled".
Definition: Path.hxx:86
AllocatedPath
A path name in the native file system character set.
Definition: AllocatedPath.hxx:38
Path::length
gcc_pure size_t length() const
Definition: Path.hxx:95
StringPointer::c_str
constexpr const_pointer_type c_str() const
Definition: StringPointer.hxx:63
PathTraitsFS::Relative
gcc_pure static gcc_nonnull_all const_pointer_type Relative(const_pointer_type base, const_pointer_type other)
Determine the relative part of the given path to this object, not including the directory separator...
Path::FromFS
static constexpr Path FromFS(const_pointer_type fs)
Create a new instance pointing to the specified path string.
Definition: Path.hxx:64
PathTraitsFS::GetBase
gcc_pure static gcc_nonnull_all const_pointer_type GetBase(const_pointer_type p)
Determine the "base" file name of the given native path.
Path
A path name in the native file system character set.
Definition: Path.hxx:39
Compiler.h
Path::IsNull
bool IsNull() const
Check if this is a "nulled" instance.
Definition: Path.hxx:77
PathTraitsFS::Find
gcc_pure static gcc_nonnull_all const_pointer_type Find(const_pointer_type p, value_type ch)
Definition: Traits.hxx:118
StringPointer::const_pointer_type
const T * const_pointer_type
Definition: StringPointer.hxx:43
Path::data
gcc_pure const_pointer_type data() const
Returns a pointer to the raw value, not necessarily null-terminated.
Definition: Path.hxx:116
Path::ToUTF8
gcc_pure std::string ToUTF8() const
Convert the path to UTF-8.
PathTraitsFS::GetLength
gcc_pure static gcc_nonnull_all size_t GetLength(const_pointer_type p)
Definition: Traits.hxx:113
Path::IsAbsolute
gcc_pure bool IsAbsolute() const
Definition: Path.hxx:166
Path::GetDirectoryName
gcc_pure AllocatedPath GetDirectoryName() const
Gets directory name of this path.
Path::HasNewline
gcc_pure bool HasNewline() const
Does the path contain a newline character? (Which is usually rejected by MPD because its protocol can...
Definition: Path.hxx:126
Path::Null
static constexpr Path Null()
Return a "nulled" instance.
Definition: Path.hxx:56
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
Path::c_str
gcc_pure const_pointer_type c_str() const
Returns the value as a const C string.
Definition: Path.hxx:107
PathTraitsFS::IsAbsolute
gcc_pure static gcc_nonnull_all bool IsAbsolute(const_pointer_type p)
Definition: Traits.hxx:99
Path::GetSuffix
gcc_pure const_pointer_type GetSuffix() const