Enzo
Loading...
Searching...
No Matches
Path.h
1
2#pragma once
3
4#include <ostream>
5#include <string>
6#include <string_view>
7#include <vector>
8
9namespace enzo {
13class Path
14{
15 public:
17 Path();
19 Path(const std::string& path);
21 Path(const char* path);
22
24 static std::string strip(const std::string& str);
25
27 bool isEmpty() const;
28
30 bool isRoot() const;
31
33 bool isAbsolute() const;
34
36 bool isRelative() const;
37
52 virtual bool isValid() const;
53
55 std::string getName() const;
56
58 Path getParent() const;
59
69 std::vector<Path> getPrefixes() const;
70
72 std::vector<std::string> split() const;
73
75 const std::string& getString() const;
76
86 static bool isValidFormatting(const std::string& pathString);
87
97 static bool isValidName(const std::string& name);
98
110 Path append(const enzo::Path& path) const;
111
122 virtual Path increment(int increment = 1) const;
123
129 Path makeRelative() const;
130
136 Path makeAbsolute() const;
137
146 Path makeRelativeTo(const Path& anchor) const;
147
153 bool hasPrefix(const Path& prefix) const;
154
157 operator std::string_view() const;
158
159 bool operator==(std::string_view other) const;
160 bool operator!=(std::string_view other) const;
161
162 protected:
163 std::string path_;
164};
165
166std::ostream& operator<<(std::ostream& os, const enzo::Path& other);
167} // namespace enzo
A default path class for creation and manipulation of tree-based paths.
Definition Path.h:14
Path makeRelativeTo(const Path &anchor) const
Makes a path relative to a given anchor path.
Definition Path.cpp:205
Path makeRelative() const
Converts an absolute path to relative, stripping the root character.
Definition Path.cpp:191
static std::string strip(const std::string &str)
Returns the string with surrounding whitespace removed.
Definition Path.cpp:25
std::string getName() const
Returns the name of the Path, ie, the last component of the path.
Definition Path.cpp:89
bool hasPrefix(const Path &prefix) const
Checks if the Path has any additional prefixes.
Definition Path.cpp:219
bool isAbsolute() const
Returns true if the Path is an absolute path.
Definition Path.cpp:40
static bool isValidName(const std::string &name)
Checks the given name to make sure it fits the alphanumeric guidelines.
Definition Path.cpp:44
std::vector< Path > getPrefixes() const
Returns every ancestor path leading up to this path, ordered from shortest to longest....
Definition Path.cpp:136
Path makeAbsolute() const
Converts a relative path to absolute, adding a root character.
Definition Path.cpp:198
bool isEmpty() const
Checks if the Path has no characters.
Definition Path.cpp:36
Path()
Constructs an empty enzo::Path object.
Definition Path.cpp:6
virtual bool isValid() const
Runs every validation check and returns true if the path is fully valid.
Definition Path.cpp:87
Path append(const enzo::Path &path) const
Returns a new path formed by appending the given path to this one.
Definition Path.cpp:158
bool isRoot() const
Returns true if the Path is "/".
Definition Path.cpp:38
std::vector< std::string > split() const
Splits all of the components of a Path and returns them as a vector of strings.
Definition Path.cpp:113
Path getParent() const
Returns the parent path as a Path if it exists.
Definition Path.cpp:100
static bool isValidFormatting(const std::string &pathString)
Checks the path to make sure it fits the alphanumeric guidelines.
Definition Path.cpp:57
bool isRelative() const
Returns true if the Path is a relative path.
Definition Path.cpp:42
const std::string & getString() const
Return the path of the Path as an std::string.
Definition Path.cpp:156
virtual Path increment(int increment=1) const
Increments the numerical suffix of the path's name by a given amount.
Definition Path.cpp:170