27
27
28
28
#pragma once
29
29
30
+ #include < filesystem> // for path
30
31
#include < functional> // for function
31
32
#include < string> // for string
32
33
#include < vector> // for vector<>
33
34
34
- #include < boost/filesystem/path.hpp> // for path, operator/
35
-
36
- namespace cloe {
37
- namespace utility {
35
+ namespace cloe ::utility {
38
36
39
37
/* *
40
38
* This enum class contains all the exceptions that can be thrown.
@@ -69,30 +67,28 @@ enum class XdgError {
69
67
// The following xdg_* functions are implementation functions, and aren't meant
70
68
// to be used directly.
71
69
#ifdef __linux__
72
- boost ::filesystem::path xdg_temp_dir ();
70
+ std ::filesystem::path xdg_temp_dir ();
73
71
#endif
74
72
75
- boost::filesystem::path xdg_getenv_path (const std::string& env);
76
- boost::filesystem::path xdg_path (const std::string& env,
77
- const boost::filesystem::path& default_path);
78
- std::vector<boost::filesystem::path> xdg_paths (const std::string& env,
79
- const std::string& default_paths);
73
+ std::filesystem::path xdg_getenv_path (const std::string& env);
74
+ std::filesystem::path xdg_path (const std::string& env, const std::filesystem::path& default_path);
75
+ std::vector<std::filesystem::path> xdg_paths (const std::string& env,
76
+ const std::string& default_paths);
80
77
81
78
/*
82
79
* Make sure to ask `is_empty()` on the result.
83
80
*/
84
- boost ::filesystem::path xdg_find (const boost ::filesystem::path& file,
85
- const std::vector<boost ::filesystem::path>& dirs);
81
+ std ::filesystem::path xdg_find (const std ::filesystem::path& file,
82
+ const std::vector<std ::filesystem::path>& dirs);
86
83
87
- std::vector<boost ::filesystem::path> xdg_findall (const boost ::filesystem::path& file,
88
- const std::vector<boost ::filesystem::path>& dirs);
84
+ std::vector<std ::filesystem::path> xdg_findall (const std ::filesystem::path& file,
85
+ const std::vector<std ::filesystem::path>& dirs);
89
86
90
- void xdg_merge (const boost::filesystem::path& file,
91
- const std::vector<boost::filesystem::path>& dirs, bool reverse,
92
- std::function<bool (const boost::filesystem::path&)> mergefn);
87
+ void xdg_merge (const std::filesystem::path& file, const std::vector<std::filesystem::path>& dirs,
88
+ bool reverse, const std::function<bool (const std::filesystem::path&)>& mergefn);
93
89
94
90
// / User configuration base directory, e.g., `~./config`.
95
- inline boost ::filesystem::path config_home () {
91
+ inline std ::filesystem::path config_home () {
96
92
#ifdef __linux__
97
93
return xdg_path (" XDG_CONFIG_HOME" , " ~/.config" );
98
94
#elif WIN32
@@ -101,7 +97,7 @@ inline boost::filesystem::path config_home() {
101
97
}
102
98
103
99
// / User data files base directory, e.g., `~/.local/share`.
104
- inline boost ::filesystem::path data_home () {
100
+ inline std ::filesystem::path data_home () {
105
101
#ifdef __linux__
106
102
return xdg_path (" XDG_DATA_HOME" , " ~/.local/share" );
107
103
#elif WIN32
@@ -110,7 +106,7 @@ inline boost::filesystem::path data_home() {
110
106
}
111
107
112
108
// / User cache files base directory, e.g., `~/.cache`.
113
- inline boost ::filesystem::path cache_home () {
109
+ inline std ::filesystem::path cache_home () {
114
110
#ifdef __linux__
115
111
return xdg_path (" XDG_CACHE_HOME" , " ~/.cache" );
116
112
#elif WIN32
@@ -119,7 +115,7 @@ inline boost::filesystem::path cache_home() {
119
115
}
120
116
121
117
// / User runtime files base directory, e.g., `/run/user/1000`
122
- inline boost ::filesystem::path runtime_dir () {
118
+ inline std ::filesystem::path runtime_dir () {
123
119
#ifdef __linux__
124
120
return xdg_path (" XDG_RUNTIME_DIR" , xdg_temp_dir ());
125
121
#elif WIN32
@@ -128,7 +124,7 @@ inline boost::filesystem::path runtime_dir() {
128
124
}
129
125
130
126
// / Global configuration directories, e.g., `/etc/xdg`.
131
- inline std::vector<boost ::filesystem::path> config_dirs () {
127
+ inline std::vector<std ::filesystem::path> config_dirs () {
132
128
#ifdef __linux__
133
129
return xdg_paths (" XDG_CONFIG_DIRS" , " /etc/xdg" );
134
130
#elif WIN32
@@ -137,7 +133,7 @@ inline std::vector<boost::filesystem::path> config_dirs() {
137
133
}
138
134
139
135
// / Global data files directories, e.g., `/usr/local/share`.
140
- inline std::vector<boost ::filesystem::path> data_dirs () {
136
+ inline std::vector<std ::filesystem::path> data_dirs () {
141
137
#ifdef __linux__
142
138
return xdg_paths (" XDG_DATA_DIRS" , " /usr/local/share:/usr/share" );
143
139
#elif WIN32
@@ -146,14 +142,14 @@ inline std::vector<boost::filesystem::path> data_dirs() {
146
142
}
147
143
148
144
// / User and global configuration directories
149
- inline std::vector<boost ::filesystem::path> all_config_dirs () {
145
+ inline std::vector<std ::filesystem::path> all_config_dirs () {
150
146
auto xs = config_dirs ();
151
147
xs.insert (xs.begin (), config_home ());
152
148
return xs;
153
149
}
154
150
155
151
// / User and global data directories
156
- inline std::vector<boost ::filesystem::path> all_data_dirs () {
152
+ inline std::vector<std ::filesystem::path> all_data_dirs () {
157
153
auto xs = data_dirs ();
158
154
xs.insert (xs.begin (), data_home ());
159
155
return xs;
@@ -164,16 +160,16 @@ inline std::vector<boost::filesystem::path> all_data_dirs() {
164
160
*
165
161
* This is useful if you want to create a file.
166
162
*/
167
- inline boost ::filesystem::path user_config (const boost ::filesystem::path& file) {
163
+ inline std ::filesystem::path user_config (const std ::filesystem::path& file) {
168
164
return config_home () / file;
169
165
}
170
- inline boost ::filesystem::path user_data (const boost ::filesystem::path& file) {
166
+ inline std ::filesystem::path user_data (const std ::filesystem::path& file) {
171
167
return data_home () / file;
172
168
}
173
- inline boost ::filesystem::path user_cache (const boost ::filesystem::path& file) {
169
+ inline std ::filesystem::path user_cache (const std ::filesystem::path& file) {
174
170
return cache_home () / file;
175
171
}
176
- inline boost ::filesystem::path user_runtime (const boost ::filesystem::path& file) {
172
+ inline std ::filesystem::path user_runtime (const std ::filesystem::path& file) {
177
173
return runtime_dir () / file;
178
174
}
179
175
@@ -183,17 +179,17 @@ inline boost::filesystem::path user_runtime(const boost::filesystem::path& file)
183
179
*
184
180
* This is useful if you want to read a file.
185
181
*/
186
- inline boost ::filesystem::path find_config (const boost ::filesystem::path& file) {
182
+ inline std ::filesystem::path find_config (const std ::filesystem::path& file) {
187
183
return xdg_find (file, all_config_dirs ());
188
184
}
189
- inline boost ::filesystem::path find_data (const boost ::filesystem::path& file) {
185
+ inline std ::filesystem::path find_data (const std ::filesystem::path& file) {
190
186
return xdg_find (file, all_data_dirs ());
191
187
}
192
- inline boost ::filesystem::path find_cache (const boost ::filesystem::path& file) {
193
- return xdg_find (file, std::vector<boost ::filesystem::path>{cache_home ()});
188
+ inline std ::filesystem::path find_cache (const std ::filesystem::path& file) {
189
+ return xdg_find (file, std::vector<std ::filesystem::path>{cache_home ()});
194
190
}
195
- inline boost ::filesystem::path find_runtime (const boost ::filesystem::path& file) {
196
- return xdg_find (file, std::vector<boost ::filesystem::path>{runtime_dir ()});
191
+ inline std ::filesystem::path find_runtime (const std ::filesystem::path& file) {
192
+ return xdg_find (file, std::vector<std ::filesystem::path>{runtime_dir ()});
197
193
}
198
194
199
195
/*
@@ -202,10 +198,10 @@ inline boost::filesystem::path find_runtime(const boost::filesystem::path& file)
202
198
*
203
199
* This is useful if you can read multiple instances of the config or data.
204
200
*/
205
- inline std::vector<boost ::filesystem::path> find_all_config (const boost ::filesystem::path& file) {
201
+ inline std::vector<std ::filesystem::path> find_all_config (const std ::filesystem::path& file) {
206
202
return xdg_findall (file, all_config_dirs ());
207
203
}
208
- inline std::vector<boost ::filesystem::path> find_all_data (const boost ::filesystem::path& file) {
204
+ inline std::vector<std ::filesystem::path> find_all_data (const std ::filesystem::path& file) {
209
205
return xdg_findall (file, all_data_dirs ());
210
206
}
211
207
@@ -217,19 +213,16 @@ inline std::vector<boost::filesystem::path> find_all_data(const boost::filesyste
217
213
* Because in merging, the most important file should be loaded last, there
218
214
* is a reverse option. If the function returns false, the merging is aborted.
219
215
*/
220
- inline void merge_config (const boost::filesystem::path& file,
221
- std::function<bool (const boost::filesystem::path&)>
222
- mergefn,
216
+ inline void merge_config (const std::filesystem::path& file,
217
+ const std::function<bool (const std::filesystem::path&)>& mergefn,
223
218
bool reverse = false) {
224
219
xdg_merge (file, all_config_dirs (), reverse, mergefn);
225
220
}
226
221
227
- inline void merge_data (const boost::filesystem::path& file,
228
- std::function<bool (const boost::filesystem::path&)>
229
- mergefn,
222
+ inline void merge_data (const std::filesystem::path& file,
223
+ const std::function<bool (const std::filesystem::path&)>& mergefn,
230
224
bool reverse = false) {
231
225
xdg_merge (file, all_data_dirs (), reverse, mergefn);
232
226
}
233
227
234
- } // namespace utility
235
- } // namespace cloe
228
+ } // namespace cloe::utility
0 commit comments