Bitcoin ABC  0.29.1
P2P Digital Currency
Go to the documentation of this file.
1 // Copyright (c) 2019 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or
8 #include <fs.h>
10 #include <map>
11 #include <string>
12 #include <vector>
14 class UniValue;
16 namespace util {
31 struct Settings {
33  std::map<std::string, SettingsValue> forced_settings;
35  std::map<std::string, std::vector<SettingsValue>> command_line_options;
37  std::map<std::string, SettingsValue> rw_settings;
40  std::map<std::string, std::map<std::string, std::vector<SettingsValue>>>
42 };
45 bool ReadSettings(const fs::path &path,
46  std::map<std::string, SettingsValue> &values,
47  std::vector<std::string> &errors);
50 bool WriteSettings(const fs::path &path,
51  const std::map<std::string, SettingsValue> &values,
52  std::vector<std::string> &errors);
67 SettingsValue GetSetting(const Settings &settings, const std::string &section,
68  const std::string &name,
69  bool ignore_default_section_config,
70  bool ignore_nonpersistent, bool get_chain_name);
74 std::vector<SettingsValue> GetSettingsList(const Settings &settings,
75  const std::string &section,
76  const std::string &name,
77  bool ignore_default_section_config);
84 bool OnlyHasDefaultSectionSetting(const Settings &settings,
85  const std::string &section,
86  const std::string &name);
91 struct SettingsSpan {
92  explicit SettingsSpan() = default;
93  explicit SettingsSpan(const SettingsValue &value) noexcept
94  : SettingsSpan(&value, 1) {}
95  explicit SettingsSpan(const SettingsValue *dataIn, size_t sizeIn) noexcept
96  : data(dataIn), size(sizeIn) {}
97  explicit SettingsSpan(const std::vector<SettingsValue> &vec) noexcept;
99  const SettingsValue *begin() const;
101  const SettingsValue *end() const;
103  bool empty() const;
105  bool last_negated() const;
107  size_t negated() const;
109  const SettingsValue *data = nullptr;
110  size_t size = 0;
111 };
114 template <typename Map, typename Key>
115 auto FindKey(Map &&map, Key &&key) -> decltype(& {
116  auto it = map.find(key);
117  return it == map.end() ? nullptr : &it->second;
118 }
120 } // namespace util
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:30
Definition: result.h:13
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:209
SettingsValue GetSetting(const Settings &settings, const std::string &section, const std::string &name, bool ignore_default_section_config, bool ignore_nonpersistent, bool get_chain_name)
Get settings value from combined sources: forced settings, command line arguments,...
Definition: settings.cpp:142
bool ReadSettings(const fs::path &path, std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Read settings file.
Definition: settings.cpp:67
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:261
bool WriteSettings(const fs::path &path, const std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Write settings file.
Definition: settings.cpp:122
auto FindKey(Map &&map, Key &&key) -> decltype(&
Map lookup helper.
Definition: settings.h:115
const char * name
Definition: rest.cpp:48
Stored settings.
Definition: settings.h:31
std::map< std::string, SettingsValue > rw_settings
Map of setting name to read-write file setting value.
Definition: settings.h:37
std::map< std::string, SettingsValue > forced_settings
Map of setting name to forced setting value.
Definition: settings.h:33
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:41
std::map< std::string, std::vector< SettingsValue > > command_line_options
Map of setting name to list of command line values.
Definition: settings.h:35
Accessor for list of settings that skips negated values when iterated over.
Definition: settings.h:91
size_t negated() const
Number of negated values.
Definition: settings.cpp:296
SettingsSpan(const SettingsValue &value) noexcept
Definition: settings.h:93
const SettingsValue * end() const
Pointer to end of values.
Definition: settings.cpp:287
bool empty() const
True if there are any non-negated values.
Definition: settings.cpp:290
SettingsSpan(const SettingsValue *dataIn, size_t sizeIn) noexcept
Definition: settings.h:95
const SettingsValue * data
Definition: settings.h:109
bool last_negated() const
True if the last value is negated.
Definition: settings.cpp:293
const SettingsValue * begin() const
Pointer to first non-negated value.
Definition: settings.cpp:284