TGUI  0.8.9
Filesystem.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2020 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25
26#ifndef TGUI_FILESYSTEM_HPP
27#define TGUI_FILESYSTEM_HPP
28
29#include <TGUI/String.hpp>
30#include <vector>
31
32#ifdef TGUI_USE_STD_FILESYSTEM
33 #include <filesystem>
34#endif
35
37
38namespace tgui
39{
46 class TGUI_API Filesystem
47 {
48 public:
49
53 class TGUI_API Path
54 {
55 public:
56
60 Path() = default;
61
62
68 Path(const String& path);
69
70
76 bool isEmpty() const;
77
78
87
88
97
98
107#ifdef TGUI_SYSTEM_WINDOWS
108 std::wstring asNativeString() const;
109#else
110 std::string asNativeString() const;
111#endif
112
113#ifdef TGUI_USE_STD_FILESYSTEM
117 operator const std::filesystem::path&() const
118 {
119 return m_path;
120 }
121#endif
122
130 Path operator/(const Path& path) const;
131
132
140 Path operator/(const String& path) const
141 {
142 return *this / Path(path);
143 }
144
145
153 Path& operator/=(const Path& path);
154
155
163 Path& operator/=(const String& path)
164 {
165 return *this /= Path(path);
166 }
167
168
170 private:
171
172#ifdef TGUI_USE_STD_FILESYSTEM
173 std::filesystem::path m_path;
174#else
175 std::vector<String> m_parts;
176 String m_root; // Drive letter or empty
177 bool m_absolute = false;
178#endif
179 };
180
181
189 static bool directoryExists(const Path& path);
190
191
199 static bool directoryExists(const String& path)
200 {
201 return directoryExists(Path{path});
202 }
203
204
212 static bool fileExists(const Path& path);
213
214
222 static bool fileExists(const String& path)
223 {
224 return fileExists(Path{path});
225 }
226
227
237 static bool createDirectory(const Path& path);
238
239
249 static bool createDirectory(const String& path)
250 {
251 return createDirectory(Path{path});
252 }
253
254
265 };
266
268}
269
271
272#endif // TGUI_FILESYSTEM_HPP
Object to represent paths on a filesystem.
Definition: Filesystem.hpp:54
bool isEmpty() const
Check if this object is empty.
std::string asNativeString() const
Returns the path as a string, but with a string type and contents that depends on the OS.
Path()=default
Default constructor that creates an empty path object.
String asString() const
Returns the path as a string.
Path getParentPath() const
Returns to path to the parent directory.
Path operator/(const Path &path) const
Returns a new path that consists of this object joined with another path.
Path & operator/=(const Path &path)
Joins this object with another path.
Path & operator/=(const String &path)
Joins this object with another path.
Definition: Filesystem.hpp:163
Path(const String &path)
Default constructor that creates an empty path object.
Path operator/(const String &path) const
Returns a new path that consists of this object joined with another path.
Definition: Filesystem.hpp:140
Helper functionality for filesystem access.
Definition: Filesystem.hpp:47
static bool directoryExists(const Path &path)
Checks if a directory exists.
static Path getLocalDataDirectory()
Returns the directory to store application data.
static bool fileExists(const String &path)
Checks if a file exists.
Definition: Filesystem.hpp:222
static bool directoryExists(const String &path)
Checks if a directory exists.
Definition: Filesystem.hpp:199
static bool fileExists(const Path &path)
Checks if a file exists.
static bool createDirectory(const Path &path)
Create a directory.
static bool createDirectory(const String &path)
Create a directory.
Definition: Filesystem.hpp:249
Wrapper class to store strings.
Definition: String.hpp:119
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37