Bitcoin Core  0.20.99
P2P Digital Currency
settings.h
Go to the documentation of this file.
1 // Copyright (c) 2019-2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_UTIL_SETTINGS_H
6 #define BITCOIN_UTIL_SETTINGS_H
7 
8 #include <map>
9 #include <string>
10 #include <vector>
11 
12 class UniValue;
13 
14 namespace util {
15 
26 
29 struct Settings {
31  std::map<std::string, SettingsValue> forced_settings;
33  std::map<std::string, std::vector<SettingsValue>> command_line_options;
35  std::map<std::string, std::map<std::string, std::vector<SettingsValue>>> ro_config;
36 };
37 
46 SettingsValue GetSetting(const Settings& settings,
47  const std::string& section,
48  const std::string& name,
49  bool ignore_default_section_config,
50  bool get_chain_name);
51 
54 std::vector<SettingsValue> GetSettingsList(const Settings& settings,
55  const std::string& section,
56  const std::string& name,
57  bool ignore_default_section_config);
58 
64 bool OnlyHasDefaultSectionSetting(const Settings& settings, const std::string& section, const std::string& name);
65 
69 struct SettingsSpan {
70  explicit SettingsSpan() = default;
71  explicit SettingsSpan(const SettingsValue& value) noexcept : SettingsSpan(&value, 1) {}
72  explicit SettingsSpan(const SettingsValue* data, size_t size) noexcept : data(data), size(size) {}
73  explicit SettingsSpan(const std::vector<SettingsValue>& vec) noexcept;
74  const SettingsValue* begin() const;
75  const SettingsValue* end() const;
76  bool empty() const;
77  bool last_negated() const;
78  size_t negated() const;
79 
80  const SettingsValue* data = nullptr;
81  size_t size = 0;
82 };
83 
85 template <typename Map, typename Key>
86 auto FindKey(Map&& map, Key&& key) -> decltype(&map.at(key))
87 {
88  auto it = map.find(key);
89  return it == map.end() ? nullptr : &it->second;
90 }
91 
92 } // namespace util
93 
94 #endif // BITCOIN_UTIL_SETTINGS_H
Stored bitcoin settings.
Definition: settings.h:29
bool OnlyHasDefaultSectionSetting(const Settings &settings, const std::string &section, const std::string &name)
Return true if a setting is set in the default config file section, and not overridden by a higher pr...
Definition: settings.cpp:150
Definition: httprpc.h:8
SettingsValue GetSetting(const Settings &settings, const std::string &section, const std::string &name, bool ignore_default_section_config, bool get_chain_name)
Get settings value from combined sources: forced settings, command line arguments and the read-only c...
Definition: settings.cpp:52
auto FindKey(Map &&map, Key &&key) -> decltype(&map.at(key))
Map lookup helper.
Definition: settings.h:86
std::vector< SettingsValue > GetSettingsList(const Settings &settings, const std::string &section, const std::string &name, bool ignore_default_section_config)
Get combined setting value similar to GetSetting(), except if setting was specified multiple times...
Definition: settings.cpp:105
const char * name
Definition: rest.cpp:41
std::map< std::string, std::vector< SettingsValue > > command_line_options
Map of setting name to list of command line values.
Definition: settings.h:33
Accessor for list of settings that skips negated values when iterated over.
Definition: settings.h:69
std::map< std::string, std::map< std::string, std::vector< SettingsValue > > > ro_config
Map of config section name and setting name to list of config file values.
Definition: settings.h:35
SettingsSpan(const SettingsValue &value) noexcept
Definition: settings.h:71
std::map< std::string, SettingsValue > forced_settings
Map of setting name to forced setting value.
Definition: settings.h:31
auto it
Definition: validation.cpp:384
SettingsSpan(const SettingsValue *data, size_t size) noexcept
Definition: settings.h:72