Mercurial > irccd
comparison common/path.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 * path.h -- special paths inside irccd | |
3 * | |
4 * Copyright (c) 2013-2016 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_PATH_H_ | |
20 #define _IRCCD_PATH_H_ | |
21 | |
22 #include <string> | |
23 #include <vector> | |
24 | |
25 namespace irccd { | |
26 | |
27 namespace path { | |
28 | |
29 /** | |
30 * PATH separator, either : or ;. | |
31 */ | |
32 extern const char Separator; | |
33 | |
34 /** | |
35 * @enum Path | |
36 * @brief Which special path to get | |
37 */ | |
38 enum Path { | |
39 PathConfig, //!< Configuration files | |
40 PathData, //!< Data directory | |
41 PathCache, //!< Cache files | |
42 PathPlugins //!< Path to the plugins | |
43 }; | |
44 | |
45 /** | |
46 * @enum Owner | |
47 * @brief For paths, get the installation path or the user ones | |
48 */ | |
49 enum Owner { | |
50 OwnerSystem, //!< System wide | |
51 OwnerUser //!< User | |
52 }; | |
53 | |
54 /** | |
55 * This function must be called before at the beginning of the main. | |
56 * | |
57 * It use system dependant program path lookup if available and fallbacks to the path given as argument if any failure | |
58 * was encoutered. | |
59 * | |
60 * @param argv0 the path to the executable (argv[0]) | |
61 */ | |
62 void setApplicationPath(const std::string &argv0); | |
63 | |
64 /** | |
65 * Clean a path by removing any extra / or \ and add a trailing one. | |
66 * | |
67 * @param path the path | |
68 * @return the updated path | |
69 */ | |
70 std::string clean(std::string path); | |
71 | |
72 /** | |
73 * Generic function for path retrievement. | |
74 * | |
75 * The path is always terminated by a trailing / or \\. | |
76 * | |
77 * @pre setApplicationPath must have been called | |
78 * @param path the type of path | |
79 * @param owner system or user wide | |
80 * @return the path | |
81 */ | |
82 std::string get(Path path, Owner owner); | |
83 | |
84 /** | |
85 * Generic function for multiple paths. | |
86 * | |
87 * This function will add more directories than pathSystem*() and pathUser*() functions, for example | |
88 * it will add some path if irccd is relocatable. | |
89 * | |
90 * @pre setApplicationPath must have been called | |
91 * @param path the type of path | |
92 * @return the list of preferred directories in order | |
93 */ | |
94 std::vector<std::string> list(Path path); | |
95 | |
96 } // !path | |
97 | |
98 } // !irccd | |
99 | |
100 #endif // !_IRCCD_PATH_H_ |