MPD  0.20.6
ConfigGlobal.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2003-2017 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef MPD_CONFIG_GLOBAL_HXX
21 #define MPD_CONFIG_GLOBAL_HXX
22 
23 #include "ConfigOption.hxx"
24 #include "Compiler.h"
25 
26 #include <chrono>
27 
28 class Path;
29 class AllocatedPath;
30 struct ConfigParam;
31 struct ConfigBlock;
32 
33 void
35 
36 void
38 
43 void
45 
46 void
47 ReadConfigFile(Path path);
48 
50 const ConfigParam *
51 config_get_param(enum ConfigOption option);
52 
54 const ConfigBlock *
56 
65 const ConfigBlock *
66 config_find_block(ConfigBlockOption option, const char *key, const char *value);
67 
68 /* Note on gcc_pure: Some of the functions declared pure are not
69  really pure in strict sense. They have side effect such that they
70  validate parameter's value and signal an error if it's invalid.
71  However, if the argument was already validated or we don't care
72  about the argument at all, this may be ignored so in the end, we
73  should be fine with calling those functions pure. */
74 
76 const char *
77 config_get_string(enum ConfigOption option, const char *default_value=nullptr);
78 
87 config_get_path(enum ConfigOption option);
88 
90 unsigned
91 config_get_unsigned(enum ConfigOption option, unsigned default_value);
92 
94 static inline std::chrono::steady_clock::duration
96  std::chrono::steady_clock::duration default_value)
97 {
98  // TODO: allow unit suffixes
99  auto u = config_get_unsigned(option, default_value.count());
100  return std::chrono::steady_clock::duration(u);
101 }
102 
103 gcc_pure
104 unsigned
105 config_get_positive(enum ConfigOption option, unsigned default_value);
106 
107 gcc_pure
108 static inline std::chrono::steady_clock::duration
110  std::chrono::steady_clock::duration default_value)
111 {
112  // TODO: allow unit suffixes
113  auto u = config_get_positive(option, default_value.count());
114  return std::chrono::steady_clock::duration(u);
115 }
116 
117 gcc_pure
118 bool config_get_bool(enum ConfigOption option, bool default_value);
119 
120 #endif
gcc_pure const ConfigParam * config_get_param(enum ConfigOption option)
void ReadConfigFile(Path path)
void config_global_check()
Call this function after all configuration has been evaluated.
A path name in the native file system character set.
ConfigBlockOption
gcc_pure const ConfigBlock * config_get_block(enum ConfigBlockOption option)
void config_global_finish()
gcc_pure const ConfigBlock * config_find_block(ConfigBlockOption option, const char *key, const char *value)
Find a block with a matching attribute.
A path name in the native file system character set.
Definition: Path.hxx:39
void config_global_init()
gcc_pure unsigned config_get_positive(enum ConfigOption option, unsigned default_value)
AllocatedPath config_get_path(enum ConfigOption option)
Returns an optional configuration variable which contains an absolute path.
ConfigOption
gcc_pure const char * config_get_string(enum ConfigOption option, const char *default_value=nullptr)
gcc_pure unsigned config_get_unsigned(enum ConfigOption option, unsigned default_value)
#define gcc_pure
Definition: Compiler.h:116
gcc_pure bool config_get_bool(enum ConfigOption option, bool default_value)