Dev Essential
Loading...
Searching...
No Matches
path.h
Go to the documentation of this file.
1
14
15#ifndef _A_UTILS_UTIL_FILESYSTEM_PATH_INCLUDED_
16#define _A_UTILS_UTIL_FILESYSTEM_PATH_INCLUDED_
17
19
20#include <memory>
21#include <stdexcept>
22#include <string>
23
24namespace a_util {
25namespace filesystem {
26// forward declarations
27class Path;
29
31class PathException : public std::runtime_error {
32public:
37 PathException(const std::string& message);
38};
39
46class Path {
47public:
54
55public:
58
63 Path(const Path& path);
64
70 Path& operator=(const Path& path);
71
77 Path(const std::string& path);
78
84 Path(const char* path);
85
88
94 operator std::string() const;
95
101 std::string toString(PathSeparator separator = PS_Native) const;
102
108 bool setPath(const std::string& path);
109
117 Path& append(const Path& path);
118
127 DEV_ESSENTIAL_DEPRECATED("Use Path::getRootName() instead.")
128 Path getRoot() const; // expected-note {{'getRoot' has been explicitly marked deprecated here}}
129
139
149
157
164
170 std::string getExtension() const;
171
179 Path& appendToBasename(const std::string& str);
180
188 Path& replaceExtension(const std::string& extension);
189
196
205
211
217 Path& makeAbsolute(Path base_path);
218
224
231 Path& makeRelative(Path input_path);
232
233 // Makes the current path relative to a specified parent directory (default: working directory)
234 // @note If the path is already relative, no changes are made!
235 // @param [in] oParent The parent directory
236 // @return Returns *this, to be able to chain additional method calls
237 // Path& MakeRelative(const Path& oParent = filesystem::getWorkingDirectory());
238
239 // Makes the current path absolute, using a specified parent directory (default: working
240 // directory)
241 // @note If the path is already absolute, no changes are made!
242 // @param [in] oParent The parent directory
243 // @return Returns *this, to be able to chain additional method calls
244 // Path& MakeAbsolute(const Path& oParent = filesystem::getWorkingDirectory());
245
251 bool isRelative() const;
252
258 bool isAbsolute() const;
259
265 bool isBaseOf(const Path& path) const;
266
271 bool isEmpty() const;
272
278
279private:
280 class Implementation;
281 std::unique_ptr<Implementation> _impl;
282 friend bool operator==(const Path& lhs, const Path& rhs);
283};
284
292bool operator==(const Path& lhs, const Path& rhs);
293
301bool operator!=(const Path& lhs, const Path& rhs);
302
311std::ostream& operator<<(std::ostream& os, const Path& p);
312
319Path operator+(const Path& a, const Path& b);
320
321} // namespace filesystem
322} // namespace a_util
323
324#endif // _A_UTILS_UTIL_FILESYSTEM_PATH_INCLUDED_
PathException(const std::string &message)
Definition path.h:46
Path(const char *path)
Path()
Default CTOR for an empty path.
Path(const std::string &path)
Path & operator=(const Path &path)
Path getLastElement() const
std::string toString(PathSeparator separator=PS_Native) const
bool isBaseOf(const Path &path) const
Path & appendToBasename(const std::string &str)
std::string getExtension() const
bool setPath(const std::string &path)
Path(const Path &path)
Path & append(const Path &path)
Path & replaceExtension(const std::string &extension)
PathSeparator
Path separator types.
Definition path.h:49
@ PS_ForwardSlash
Unix slash.
Definition path.h:50
@ PS_Native
Native slash, depending on the current platform.
Definition path.h:52
@ PS_BackwardSlash
Windows slash.
Definition path.h:51
#define DEV_ESSENTIAL_DEPRECATED(msg)
Definition deprecated.h:44
Serves as component for path and filesystem functionality.
Definition filesystem.h:20
Path getWorkingDirectory()
Serves as the root component, with common functionality documented in core functionality.
Definition base.h:24