platformdirs 0.1.0
📂 Python's platformdirs module for C++
Loading...
Searching...
No Matches
platformdirs.h
Go to the documentation of this file.
1#pragma once
2
7#undef unix
8#include "platformdirs/api.h"
10#include <filesystem>
11#include <string>
12#include <string_view>
13#include <variant>
14#if __COSMOPOLITAN__
15#include "platformdirs/macos.h"
16#include "platformdirs/unix.h"
18#include <cosmo.h>
19#elif __APPLE__
20#include "platformdirs/macos.h"
21#elif _WIN32
23#else
24#include "platformdirs/unix.h"
25#endif
26
27namespace platformdirs {
28
31
33
34#if __COSMOPOLITAN__
41class platform_dirs {
42public:
45 value;
46
47public:
48 platform_dirs(const std::optional<std::string> &appname = std::nullopt,
49 const std::variant<std::string, std::nullopt_t, bool>
50 &appauthor = std::nullopt,
51 const std::optional<std::string> &version = std::nullopt,
52 bool roaming = false, bool multipath = false,
53 bool opinion = true, bool ensure_exists = false) {
54 if (IsWindows()) {
55 this->value =
56 platformdirs::windows::windows(appname, appauthor, version, roaming,
57 multipath, opinion, ensure_exists);
58 } else if (IsXnu()) {
59 this->value =
60 platformdirs::macos::macos(appname, appauthor, version, roaming,
61 multipath, opinion, ensure_exists);
62 } else {
63 this->value =
64 platformdirs::unix::unix(appname, appauthor, version, roaming,
65 multipath, opinion, ensure_exists);
66 }
67 }
68
69 std::string user_data_dir() const {
70 return std::visit([](auto &&arg) { return arg.user_data_dir(); },
71 this->value);
72 }
73
74 std::string site_data_dir() const {
75 return std::visit([](auto &&arg) { return arg.site_data_dir(); },
76 this->value);
77 }
78
79 std::string user_config_dir() const {
80 return std::visit([](auto &&arg) { return arg.user_config_dir(); },
81 this->value);
82 }
83
84 std::string site_config_dir() const {
85 return std::visit([](auto &&arg) { return arg.site_config_dir(); },
86 this->value);
87 }
88
89 std::string user_cache_dir() const {
90 return std::visit([](auto &&arg) { return arg.user_cache_dir(); },
91 this->value);
92 }
93
94 std::string site_cache_dir() const {
95 return std::visit([](auto &&arg) { return arg.site_cache_dir(); },
96 this->value);
97 }
98
99 std::string user_state_dir() const {
100 return std::visit([](auto &&arg) { return arg.user_state_dir(); },
101 this->value);
102 }
103
104 std::string user_log_dir() const {
105 return std::visit([](auto &&arg) { return arg.user_log_dir(); },
106 this->value);
107 }
108
109 std::string user_documents_dir() const {
110 return std::visit([](auto &&arg) { return arg.user_documents_dir(); },
111 this->value);
112 }
113
114 std::string user_downloads_dir() const {
115 return std::visit([](auto &&arg) { return arg.user_downloads_dir(); },
116 this->value);
117 }
118
119 std::string user_pictures_dir() const {
120 return std::visit([](auto &&arg) { return arg.user_pictures_dir(); },
121 this->value);
122 }
123
124 std::string user_videos_dir() const {
125 return std::visit([](auto &&arg) { return arg.user_videos_dir(); },
126 this->value);
127 }
128
129 std::string user_music_dir() const {
130 return std::visit([](auto &&arg) { return arg.user_music_dir(); },
131 this->value);
132 }
133
134 std::string user_desktop_dir() const {
135 return std::visit([](auto &&arg) { return arg.user_desktop_dir(); },
136 this->value);
137 }
138
139 std::string user_runtime_dir() const {
140 return std::visit([](auto &&arg) { return arg.user_runtime_dir(); },
141 this->value);
142 }
143
144 std::string site_runtime_dir() const {
145 return std::visit([](auto &&arg) { return arg.site_runtime_dir(); },
146 this->value);
147 }
148
149 std::filesystem::path user_data_path() const {
150 return std::visit([](auto &&arg) { return arg.user_data_path(); },
151 this->value);
152 }
153
154 std::filesystem::path site_data_path() const {
155 return std::visit([](auto &&arg) { return arg.site_data_path(); },
156 this->value);
157 }
158
159 std::filesystem::path user_config_path() const {
160 return std::visit([](auto &&arg) { return arg.user_config_path(); },
161 this->value);
162 }
163
164 std::filesystem::path site_config_path() const {
165 return std::visit([](auto &&arg) { return arg.site_config_path(); },
166 this->value);
167 }
168
169 std::filesystem::path user_cache_path() const {
170 return std::visit([](auto &&arg) { return arg.user_cache_path(); },
171 this->value);
172 }
173
174 std::filesystem::path site_cache_path() const {
175 return std::visit([](auto &&arg) { return arg.site_cache_path(); },
176 this->value);
177 }
178
179 std::filesystem::path user_state_path() const {
180 return std::visit([](auto &&arg) { return arg.user_state_path(); },
181 this->value);
182 }
183
184 std::filesystem::path user_log_path() const {
185 return std::visit([](auto &&arg) { return arg.user_log_path(); },
186 this->value);
187 }
188
189 std::filesystem::path user_documents_path() const {
190 return std::visit([](auto &&arg) { return arg.user_documents_path(); },
191 this->value);
192 }
193
194 std::filesystem::path user_downloads_path() const {
195 return std::visit([](auto &&arg) { return arg.user_downloads_path(); },
196 this->value);
197 }
198
199 std::filesystem::path user_pictures_path() const {
200 return std::visit([](auto &&arg) { return arg.user_pictures_path(); },
201 this->value);
202 }
203
204 std::filesystem::path user_videos_path() const {
205 return std::visit([](auto &&arg) { return arg.user_videos_path(); },
206 this->value);
207 }
208
209 std::filesystem::path user_music_path() const {
210 return std::visit([](auto &&arg) { return arg.user_music_path(); },
211 this->value);
212 }
213
214 std::filesystem::path user_desktop_path() const {
215 return std::visit([](auto &&arg) { return arg.user_desktop_path(); },
216 this->value);
217 }
218
219 std::filesystem::path user_runtime_path() const {
220 return std::visit([](auto &&arg) { return arg.user_runtime_path(); },
221 this->value);
222 }
223
224 std::filesystem::path site_runtime_path() const {
225 return std::visit([](auto &&arg) { return arg.site_runtime_path(); },
226 this->value);
227 }
228};
229#else
232#if __APPLE__
234#elif _WIN32
236#else
238#endif
239#endif
240
242
244
253std::string
254user_data_dir(const std::optional<std::string> &appname = std::nullopt,
255 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
256 std::nullopt,
257 const std::optional<std::string> &version = std::nullopt,
258 bool roaming = false, bool ensure_exists = false);
259
268std::string
269site_data_dir(const std::optional<std::string> &appname = std::nullopt,
270 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
271 std::nullopt,
272 const std::optional<std::string> &version = std::nullopt,
273 bool multipath = false, bool ensure_exists = false);
274
283std::string user_config_dir(
284 const std::optional<std::string> &appname = std::nullopt,
285 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
286 std::nullopt,
287 const std::optional<std::string> &version = std::nullopt,
288 bool roaming = false, bool ensure_exists = false);
289
298std::string site_config_dir(
299 const std::optional<std::string> &appname = std::nullopt,
300 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
301 std::nullopt,
302 const std::optional<std::string> &version = std::nullopt,
303 bool multipath = false, bool ensure_exists = false);
304
313std::string user_cache_dir(
314 const std::optional<std::string> &appname = std::nullopt,
315 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
316 std::nullopt,
317 const std::optional<std::string> &version = std::nullopt,
318 bool roaming = false, bool ensure_exists = false);
319
328std::string site_cache_dir(
329 const std::optional<std::string> &appname = std::nullopt,
330 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
331 std::nullopt,
332 const std::optional<std::string> &version = std::nullopt,
333 bool multipath = false, bool ensure_exists = false);
334
343std::string user_state_dir(
344 const std::optional<std::string> &appname = std::nullopt,
345 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
346 std::nullopt,
347 const std::optional<std::string> &version = std::nullopt,
348 bool roaming = false, bool ensure_exists = false);
349
358std::string
359user_log_dir(const std::optional<std::string> &appname = std::nullopt,
360 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
361 std::nullopt,
362 const std::optional<std::string> &version = std::nullopt,
363 bool roaming = false, bool ensure_exists = false);
364
366std::string user_documents_dir();
367
369std::string user_downloads_dir();
370
372std::string user_pictures_dir();
373
375std::string user_videos_dir();
376
378std::string user_music_dir();
379
381std::string user_desktop_dir();
382
391std::string user_runtime_dir(
392 const std::optional<std::string> &appname = std::nullopt,
393 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
394 std::nullopt,
395 const std::optional<std::string> &version = std::nullopt,
396 bool roaming = false, bool ensure_exists = false);
397
406std::string site_runtime_dir(
407 const std::optional<std::string> &appname = std::nullopt,
408 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
409 std::nullopt,
410 const std::optional<std::string> &version = std::nullopt,
411 bool multipath = false, bool ensure_exists = false);
412
421std::filesystem::path user_data_path(
422 const std::optional<std::string> &appname = std::nullopt,
423 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
424 std::nullopt,
425 const std::optional<std::string> &version = std::nullopt,
426 bool roaming = false, bool ensure_exists = false);
427
436std::filesystem::path site_data_path(
437 const std::optional<std::string> &appname = std::nullopt,
438 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
439 std::nullopt,
440 const std::optional<std::string> &version = std::nullopt,
441 bool multipath = false, bool ensure_exists = false);
442
451std::filesystem::path user_config_path(
452 const std::optional<std::string> &appname = std::nullopt,
453 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
454 std::nullopt,
455 const std::optional<std::string> &version = std::nullopt,
456 bool roaming = false, bool ensure_exists = false);
457
466std::filesystem::path site_config_path(
467 const std::optional<std::string> &appname = std::nullopt,
468 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
469 std::nullopt,
470 const std::optional<std::string> &version = std::nullopt,
471 bool multipath = false, bool ensure_exists = false);
472
481std::filesystem::path user_cache_path(
482 const std::optional<std::string> &appname = std::nullopt,
483 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
484 std::nullopt,
485 const std::optional<std::string> &version = std::nullopt,
486 bool roaming = false, bool ensure_exists = false);
487
496std::filesystem::path site_cache_path(
497 const std::optional<std::string> &appname = std::nullopt,
498 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
499 std::nullopt,
500 const std::optional<std::string> &version = std::nullopt,
501 bool multipath = false, bool ensure_exists = false);
502
511std::filesystem::path user_state_path(
512 const std::optional<std::string> &appname = std::nullopt,
513 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
514 std::nullopt,
515 const std::optional<std::string> &version = std::nullopt,
516 bool roaming = false, bool ensure_exists = false);
517
526std::filesystem::path
527user_log_path(const std::optional<std::string> &appname = std::nullopt,
528 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
529 std::nullopt,
530 const std::optional<std::string> &version = std::nullopt,
531 bool roaming = false, bool ensure_exists = false);
532
534std::filesystem::path user_documents_path();
535
537std::filesystem::path user_downloads_path();
538
540std::filesystem::path user_pictures_path();
541
543std::filesystem::path user_videos_path();
544
546std::filesystem::path user_music_path();
547
549std::filesystem::path user_desktop_path();
550
559std::filesystem::path user_runtime_path(
560 const std::optional<std::string> &appname = std::nullopt,
561 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
562 std::nullopt,
563 const std::optional<std::string> &version = std::nullopt,
564 bool roaming = false, bool ensure_exists = false);
565
574std::filesystem::path site_runtime_path(
575 const std::optional<std::string> &appname = std::nullopt,
576 const std::variant<std::string, std::nullopt_t, bool> &appauthor =
577 std::nullopt,
578 const std::optional<std::string> &version = std::nullopt,
579 bool multipath = false, bool ensure_exists = false);
580
581} // namespace platformdirs
Definition macos.h:11
Definition unix.h:21
Definition windows.h:11
std::tuple< uint8_t, uint8_t, uint8_t > version_tuple()
Definition version.cpp:10
std::string version()
Definition version.cpp:6
Definition platformdirs.h:27
std::filesystem::path site_cache_path(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool multipath=false, bool ensure_exists=false)
Definition platformdirs.cpp:182
std::string user_runtime_dir(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool roaming=false, bool ensure_exists=false)
Definition platformdirs.cpp:112
std::filesystem::path user_data_path(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool roaming=false, bool ensure_exists=false)
Definition platformdirs.cpp:132
std::string user_log_dir(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool roaming=false, bool ensure_exists=false)
Definition platformdirs.cpp:78
std::string site_cache_dir(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool multipath=false, bool ensure_exists=false)
Definition platformdirs.cpp:58
std::string user_data_dir(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool roaming=false, bool ensure_exists=false)
Definition platformdirs.cpp:8
std::string user_desktop_dir()
Definition platformdirs.cpp:108
std::filesystem::path user_runtime_path(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool roaming=false, bool ensure_exists=false)
Definition platformdirs.cpp:236
std::string site_config_dir(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool multipath=false, bool ensure_exists=false)
Definition platformdirs.cpp:38
std::filesystem::path user_config_path(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool roaming=false, bool ensure_exists=false)
Definition platformdirs.cpp:152
std::filesystem::path user_pictures_path()
Definition platformdirs.cpp:220
std::filesystem::path user_videos_path()
Definition platformdirs.cpp:224
std::string user_videos_dir()
Definition platformdirs.cpp:100
std::string user_music_dir()
Definition platformdirs.cpp:104
constexpr auto & version_info
Definition platformdirs.h:32
std::filesystem::path user_music_path()
Definition platformdirs.cpp:228
std::filesystem::path site_runtime_path(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool multipath=false, bool ensure_exists=false)
Definition platformdirs.cpp:246
std::filesystem::path user_desktop_path()
Definition platformdirs.cpp:232
std::string user_cache_dir(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool roaming=false, bool ensure_exists=false)
Definition platformdirs.cpp:48
constexpr auto & version_
Definition platformdirs.h:30
platformdirs::unix::unix platform_dirs
Definition platformdirs.h:231
std::filesystem::path user_downloads_path()
Definition platformdirs.cpp:216
std::string site_data_dir(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool multipath=false, bool ensure_exists=false)
Definition platformdirs.cpp:18
std::filesystem::path user_cache_path(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool roaming=false, bool ensure_exists=false)
Definition platformdirs.cpp:172
std::string user_downloads_dir()
Definition platformdirs.cpp:92
std::string user_state_dir(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool roaming=false, bool ensure_exists=false)
Definition platformdirs.cpp:68
std::filesystem::path user_state_path(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool roaming=false, bool ensure_exists=false)
Definition platformdirs.cpp:192
std::string user_config_dir(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool roaming=false, bool ensure_exists=false)
Definition platformdirs.cpp:28
std::filesystem::path site_data_path(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool multipath=false, bool ensure_exists=false)
Definition platformdirs.cpp:142
std::filesystem::path site_config_path(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool multipath=false, bool ensure_exists=false)
Definition platformdirs.cpp:162
std::filesystem::path user_log_path(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool roaming=false, bool ensure_exists=false)
Definition platformdirs.cpp:202
std::string user_pictures_dir()
Definition platformdirs.cpp:96
std::filesystem::path user_documents_path()
Definition platformdirs.cpp:212
std::string site_runtime_dir(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool multipath=false, bool ensure_exists=false)
Definition platformdirs.cpp:122
std::string user_documents_dir()
Definition platformdirs.cpp:88