comparison common/xdg.h @ 0:1158cffe5a5e

Initial import
author David Demelier <markand@malikania.fr>
date Mon, 08 Feb 2016 16:43:14 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1158cffe5a5e
1 /*
2 * Xdg.h -- XDG directory specifications
3 *
4 * Copyright (c) 2013, 2014, 2015 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 _IRCCD_XDG_H_
20 #define _IRCCD_XDG_H_
21
22 /**
23 * @file Xdg.h
24 * @brief Read XDG standard specifications
25 */
26
27 #include <vector>
28 #include <string>
29
30 namespace irccd {
31
32 /**
33 * @class Xdg
34 * @brief XDG specifications
35 *
36 * Read and get XDG directories. This file contains exports thingies so it can
37 * compiles successfully on Windows but its usage is discouraged.
38 */
39 class Xdg {
40 public:
41 /**
42 * list of directories.
43 */
44 using List = std::vector<std::string>;
45
46 private:
47 std::string m_configHome;
48 std::string m_dataHome;
49 std::string m_cacheHome;
50 std::string m_runtimeDir;
51 List m_configDirs;
52 List m_dataDirs;
53
54 public:
55 /**
56 * Open an xdg instance and load directories.
57 *
58 * @throw std::runtime_error on failures
59 */
60 Xdg();
61
62 /**
63 * Get the config directory. ${XDG_CONFIG_HOME} or ${HOME}/.config
64 *
65 * @return the config directory
66 */
67 const std::string &configHome() const noexcept;
68
69 /**
70 * Get the data directory. ${XDG_DATA_HOME} or ${HOME}/.local/share
71 *
72 * @return the data directory
73 */
74 const std::string &dataHome() const noexcept;
75
76 /**
77 * Get the cache directory. ${XDG_CACHE_HOME} or ${HOME}/.cache
78 *
79 * @return the cache directory
80 */
81 const std::string &cacheHome() const noexcept;
82
83 /**
84 * Get the runtime directory. ${XDG_RUNTIME_DIR} must be set,
85 * if not, it throws an exception.
86 *
87 * The XDG standard says that application should handle XDG_RUNTIME_DIR by
88 * themselves.
89 *
90 * @return the runtime directory
91 * @throw std::runtime_error on error
92 */
93 const std::string &runtimeDir() const;
94
95 /**
96 * Get the standard config directories. ${XDG_CONFIG_DIRS} or { "/etc/xdg" }
97 *
98 * @return the list of config directories
99 */
100 const List &configDirs() const noexcept;
101
102 /**
103 * Get the data directories. ${XDG_DATA_DIRS} or { "/usr/local/share", "/usr/share" }
104 *
105 * @return the list of data directories
106 */
107 const List &dataDirs() const noexcept;
108 };
109
110 } // !irccd
111
112 #endif // !_IRCCD_XDG_H_