Mercurial > code
comparison C++/Xdg.h @ 239:9b69f810d3b9
Add Xdg, a replacement for XDG standard directories
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 12 Aug 2014 16:45:33 +0200 |
parents | |
children | f6d9fdb5eeeb |
comparison
equal
deleted
inserted
replaced
237:887d43215b90 | 239:9b69f810d3b9 |
---|---|
1 /* | |
2 * Xdg.h -- XDG directory specifications | |
3 * | |
4 * Copyright (c) 2013, 2014 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #ifndef _XDG_H_ | |
20 #define _XDG_H_ | |
21 | |
22 #include <vector> | |
23 #include <string> | |
24 | |
25 #if defined(_WIN32) | |
26 # if defined(BUILDING_DLL) | |
27 # define EXPORT __declspec(dllexport) | |
28 # else | |
29 # define EXPORT __declspec(dllimport) | |
30 # endif | |
31 #else | |
32 # define EXPORT | |
33 #endif | |
34 | |
35 /** | |
36 * @class Xdg | |
37 * @brief XDG specifications | |
38 * | |
39 * Read and get XDG directories. | |
40 */ | |
41 class EXPORT Xdg { | |
42 public: | |
43 using List = std::vector<std::string>; | |
44 | |
45 private: | |
46 std::string m_configHome; | |
47 std::string m_dataHome; | |
48 std::string m_cacheHome; | |
49 std::string m_runtimeDir; | |
50 List m_configDirs; | |
51 List m_dataDirs; | |
52 | |
53 public: | |
54 /** | |
55 * Open an xdg instance and load directories. | |
56 * | |
57 * @throw std::runtime_error on failures | |
58 */ | |
59 Xdg(); | |
60 | |
61 /** | |
62 * Get the config directory. ${XDG_CONFIG_HOME} or ${HOME}/.config | |
63 * | |
64 * @return the config directory | |
65 */ | |
66 const std::string &configHome() const noexcept; | |
67 | |
68 /** | |
69 * Get the data directory. ${XDG_DATA_HOME} or ${HOME}/.local/share | |
70 * | |
71 * @return the data directory | |
72 */ | |
73 const std::string &dataHome() const noexcept; | |
74 | |
75 /** | |
76 * Get the cache directory. ${XDG_CACHE_HOME} or ${HOME}/.cache | |
77 * | |
78 * @return the cache directory | |
79 */ | |
80 const std::string &cacheHome() const noexcept; | |
81 | |
82 /** | |
83 * Get the runtime directory. ${XDG_RUNTIME_DIR} must be set, | |
84 * if not, it throws an exception. | |
85 * | |
86 * The XDG standard says that application should handle XDG_RUNTIME_DIR by | |
87 * themselves. | |
88 * | |
89 * @return the runtime directory | |
90 * @throw std::runtime_error on error | |
91 */ | |
92 const std::string &runtimeDir() const; | |
93 | |
94 /** | |
95 * Get the standard config directories. ${XDG_CONFIG_DIRS} or { "/etc/xdg" } | |
96 * | |
97 * @return the list of config directories | |
98 */ | |
99 const List &configDirs() const noexcept; | |
100 | |
101 /** | |
102 * Get the data directories. ${XDG_DATA_DIRS} or { "/usr/local/share", "/usr/share" } | |
103 * | |
104 * @return the list of data directories | |
105 */ | |
106 const List &dataDirs() const noexcept; | |
107 }; | |
108 | |
109 #endif // !_XDG_H_ |