aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorTheCharlatan <seb.kung@gmail.com>2023-05-24 16:18:59 +0200
committerTheCharlatan <seb.kung@gmail.com>2023-05-30 17:26:51 +0200
commitdb77f87c6365cb5f414036d6bfb1a12705772028 (patch)
tree30e4524849540d22fb8228c5bc87e75ebed1d647 /src/common
parentc27e4bdc35bc7cedd1ee07e98a52c230241120d1 (diff)
scripted-diff: move settings to common namespace
-BEGIN VERIFY SCRIPT- sed -i 's/namespace\ util/namespace\ common/g' src/common/settings.cpp src/common/settings.h sed -i 's/util\:\:GetSetting/common\:\:GetSetting/g' $( git grep -l 'util\:\:GetSetting') sed -i 's/util\:\:Setting/common\:\:Setting/g' $( git grep -l 'util\:\:Setting') sed -i 's/util\:\:FindKey/common\:\:FindKey/g' $( git grep -l 'util\:\:FindKey') sed -i 's/util\:\:ReadSettings/common\:\:ReadSettings/g' $( git grep -l 'util\:\:ReadSettings') sed -i 's/util\:\:WriteSettings/common\:\:WriteSettings/g' $( git grep -l 'util\:\:WriteSettings') -END VERIFY SCRIPT-
Diffstat (limited to 'src/common')
-rw-r--r--src/common/args.cpp48
-rw-r--r--src/common/args.h24
-rw-r--r--src/common/config.cpp12
-rw-r--r--src/common/settings.cpp4
-rw-r--r--src/common/settings.h4
5 files changed, 46 insertions, 46 deletions
diff --git a/src/common/args.cpp b/src/common/args.cpp
index 289410ecbe..643838399f 100644
--- a/src/common/args.cpp
+++ b/src/common/args.cpp
@@ -104,7 +104,7 @@ KeyInfo InterpretKey(std::string key)
* @return parsed settings value if it is valid, otherwise nullopt accompanied
* by a descriptive error string
*/
-std::optional<util::SettingsValue> InterpretValue(const KeyInfo& key, const std::string* value,
+std::optional<common::SettingsValue> InterpretValue(const KeyInfo& key, const std::string* value,
unsigned int flags, std::string& error)
{
// Return negated settings as false values.
@@ -238,15 +238,15 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
return false;
}
- std::optional<util::SettingsValue> value = InterpretValue(keyinfo, val ? &*val : nullptr, *flags, error);
+ std::optional<common::SettingsValue> value = InterpretValue(keyinfo, val ? &*val : nullptr, *flags, error);
if (!value) return false;
m_settings.command_line_options[keyinfo.name].push_back(*value);
}
// we do not allow -includeconf from command line, only -noincludeconf
- if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) {
- const util::SettingsSpan values{*includes};
+ if (auto* includes = common::FindKey(m_settings.command_line_options, "includeconf")) {
+ const common::SettingsSpan values{*includes};
// Range may be empty if -noincludeconf was passed
if (!values.empty()) {
error = "-includeconf cannot be used from commandline; -includeconf=" + values.begin()->write();
@@ -361,7 +361,7 @@ std::optional<const ArgsManager::Command> ArgsManager::GetCommand() const
std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const
{
std::vector<std::string> result;
- for (const util::SettingsValue& value : GetSettingsList(strArg)) {
+ for (const common::SettingsValue& value : GetSettingsList(strArg)) {
result.push_back(value.isFalse() ? "0" : value.isTrue() ? "1" : value.get_str());
}
return result;
@@ -408,7 +408,7 @@ bool ArgsManager::ReadSettingsFile(std::vector<std::string>* errors)
LOCK(cs_args);
m_settings.rw_settings.clear();
std::vector<std::string> read_errors;
- if (!util::ReadSettings(path, m_settings.rw_settings, read_errors)) {
+ if (!common::ReadSettings(path, m_settings.rw_settings, read_errors)) {
SaveErrors(read_errors, errors);
return false;
}
@@ -430,7 +430,7 @@ bool ArgsManager::WriteSettingsFile(std::vector<std::string>* errors, bool backu
LOCK(cs_args);
std::vector<std::string> write_errors;
- if (!util::WriteSettings(path_tmp, m_settings.rw_settings, write_errors)) {
+ if (!common::WriteSettings(path_tmp, m_settings.rw_settings, write_errors)) {
SaveErrors(write_errors, errors);
return false;
}
@@ -441,10 +441,10 @@ bool ArgsManager::WriteSettingsFile(std::vector<std::string>* errors, bool backu
return true;
}
-util::SettingsValue ArgsManager::GetPersistentSetting(const std::string& name) const
+common::SettingsValue ArgsManager::GetPersistentSetting(const std::string& name) const
{
LOCK(cs_args);
- return util::GetSetting(m_settings, m_network, name, !UseDefaultSection("-" + name),
+ return common::GetSetting(m_settings, m_network, name, !UseDefaultSection("-" + name),
/*ignore_nonpersistent=*/true, /*get_chain_type=*/false);
}
@@ -460,11 +460,11 @@ std::string ArgsManager::GetArg(const std::string& strArg, const std::string& st
std::optional<std::string> ArgsManager::GetArg(const std::string& strArg) const
{
- const util::SettingsValue value = GetSetting(strArg);
+ const common::SettingsValue value = GetSetting(strArg);
return SettingToString(value);
}
-std::optional<std::string> SettingToString(const util::SettingsValue& value)
+std::optional<std::string> SettingToString(const common::SettingsValue& value)
{
if (value.isNull()) return std::nullopt;
if (value.isFalse()) return "0";
@@ -473,7 +473,7 @@ std::optional<std::string> SettingToString(const util::SettingsValue& value)
return value.get_str();
}
-std::string SettingToString(const util::SettingsValue& value, const std::string& strDefault)
+std::string SettingToString(const common::SettingsValue& value, const std::string& strDefault)
{
return SettingToString(value).value_or(strDefault);
}
@@ -485,11 +485,11 @@ int64_t ArgsManager::GetIntArg(const std::string& strArg, int64_t nDefault) cons
std::optional<int64_t> ArgsManager::GetIntArg(const std::string& strArg) const
{
- const util::SettingsValue value = GetSetting(strArg);
+ const common::SettingsValue value = GetSetting(strArg);
return SettingToInt(value);
}
-std::optional<int64_t> SettingToInt(const util::SettingsValue& value)
+std::optional<int64_t> SettingToInt(const common::SettingsValue& value)
{
if (value.isNull()) return std::nullopt;
if (value.isFalse()) return 0;
@@ -498,7 +498,7 @@ std::optional<int64_t> SettingToInt(const util::SettingsValue& value)
return LocaleIndependentAtoi<int64_t>(value.get_str());
}
-int64_t SettingToInt(const util::SettingsValue& value, int64_t nDefault)
+int64_t SettingToInt(const common::SettingsValue& value, int64_t nDefault)
{
return SettingToInt(value).value_or(nDefault);
}
@@ -510,18 +510,18 @@ bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault) const
std::optional<bool> ArgsManager::GetBoolArg(const std::string& strArg) const
{
- const util::SettingsValue value = GetSetting(strArg);
+ const common::SettingsValue value = GetSetting(strArg);
return SettingToBool(value);
}
-std::optional<bool> SettingToBool(const util::SettingsValue& value)
+std::optional<bool> SettingToBool(const common::SettingsValue& value)
{
if (value.isNull()) return std::nullopt;
if (value.isBool()) return value.get_bool();
return InterpretBool(value.get_str());
}
-bool SettingToBool(const util::SettingsValue& value, bool fDefault)
+bool SettingToBool(const common::SettingsValue& value, bool fDefault)
{
return SettingToBool(value).value_or(fDefault);
}
@@ -738,7 +738,7 @@ std::variant<ChainType, std::string> ArgsManager::GetChainArg() const
{
auto get_net = [&](const std::string& arg) {
LOCK(cs_args);
- util::SettingsValue value = util::GetSetting(m_settings, /* section= */ "", SettingName(arg),
+ common::SettingsValue value = common::GetSetting(m_settings, /* section= */ "", SettingName(arg),
/* ignore_default_section_config= */ false,
/*ignore_nonpersistent=*/false,
/* get_chain_type= */ true);
@@ -769,24 +769,24 @@ bool ArgsManager::UseDefaultSection(const std::string& arg) const
return m_network == ChainTypeToString(ChainType::MAIN) || m_network_only_args.count(arg) == 0;
}
-util::SettingsValue ArgsManager::GetSetting(const std::string& arg) const
+common::SettingsValue ArgsManager::GetSetting(const std::string& arg) const
{
LOCK(cs_args);
- return util::GetSetting(
+ return common::GetSetting(
m_settings, m_network, SettingName(arg), !UseDefaultSection(arg),
/*ignore_nonpersistent=*/false, /*get_chain_type=*/false);
}
-std::vector<util::SettingsValue> ArgsManager::GetSettingsList(const std::string& arg) const
+std::vector<common::SettingsValue> ArgsManager::GetSettingsList(const std::string& arg) const
{
LOCK(cs_args);
- return util::GetSettingsList(m_settings, m_network, SettingName(arg), !UseDefaultSection(arg));
+ return common::GetSettingsList(m_settings, m_network, SettingName(arg), !UseDefaultSection(arg));
}
void ArgsManager::logArgsPrefix(
const std::string& prefix,
const std::string& section,
- const std::map<std::string, std::vector<util::SettingsValue>>& args) const
+ const std::map<std::string, std::vector<common::SettingsValue>>& args) const
{
std::string section_str = section.empty() ? "" : "[" + section + "] ";
for (const auto& arg : args) {
diff --git a/src/common/args.h b/src/common/args.h
index c4debb9c82..ae3ed02bc7 100644
--- a/src/common/args.h
+++ b/src/common/args.h
@@ -75,7 +75,7 @@ struct KeyInfo {
KeyInfo InterpretKey(std::string key);
-std::optional<util::SettingsValue> InterpretValue(const KeyInfo& key, const std::string* value,
+std::optional<common::SettingsValue> InterpretValue(const KeyInfo& key, const std::string* value,
unsigned int flags, std::string& error);
struct SectionInfo {
@@ -84,14 +84,14 @@ struct SectionInfo {
int m_line;
};
-std::string SettingToString(const util::SettingsValue&, const std::string&);
-std::optional<std::string> SettingToString(const util::SettingsValue&);
+std::string SettingToString(const common::SettingsValue&, const std::string&);
+std::optional<std::string> SettingToString(const common::SettingsValue&);
-int64_t SettingToInt(const util::SettingsValue&, int64_t);
-std::optional<int64_t> SettingToInt(const util::SettingsValue&);
+int64_t SettingToInt(const common::SettingsValue&, int64_t);
+std::optional<int64_t> SettingToInt(const common::SettingsValue&);
-bool SettingToBool(const util::SettingsValue&, bool);
-std::optional<bool> SettingToBool(const util::SettingsValue&);
+bool SettingToBool(const common::SettingsValue&, bool);
+std::optional<bool> SettingToBool(const common::SettingsValue&);
class ArgsManager
{
@@ -130,7 +130,7 @@ protected:
};
mutable RecursiveMutex cs_args;
- util::Settings m_settings GUARDED_BY(cs_args);
+ common::Settings m_settings GUARDED_BY(cs_args);
std::vector<std::string> m_command GUARDED_BY(cs_args);
std::string m_network GUARDED_BY(cs_args);
std::set<std::string> m_network_only_args GUARDED_BY(cs_args);
@@ -159,12 +159,12 @@ protected:
* false if "-nosetting" argument was passed, and a string if a "-setting=value"
* argument was passed.
*/
- util::SettingsValue GetSetting(const std::string& arg) const;
+ common::SettingsValue GetSetting(const std::string& arg) const;
/**
* Get list of setting values.
*/
- std::vector<util::SettingsValue> GetSettingsList(const std::string& arg) const;
+ std::vector<common::SettingsValue> GetSettingsList(const std::string& arg) const;
ArgsManager();
~ArgsManager();
@@ -394,7 +394,7 @@ protected:
* Get current setting from config file or read/write settings file,
* ignoring nonpersistent command line or forced settings values.
*/
- util::SettingsValue GetPersistentSetting(const std::string& name) const;
+ common::SettingsValue GetPersistentSetting(const std::string& name) const;
/**
* Access settings with lock held.
@@ -433,7 +433,7 @@ private:
void logArgsPrefix(
const std::string& prefix,
const std::string& section,
- const std::map<std::string, std::vector<util::SettingsValue>>& args) const;
+ const std::map<std::string, std::vector<common::SettingsValue>>& args) const;
};
extern ArgsManager gArgs;
diff --git a/src/common/config.cpp b/src/common/config.cpp
index d156f8e514..1c85273f69 100644
--- a/src/common/config.cpp
+++ b/src/common/config.cpp
@@ -98,7 +98,7 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file
std::optional<unsigned int> flags = GetArgFlags('-' + key.name);
if (!IsConfSupported(key, error)) return false;
if (flags) {
- std::optional<util::SettingsValue> value = InterpretValue(key, &option.second, *flags, error);
+ std::optional<common::SettingsValue> value = InterpretValue(key, &option.second, *flags, error);
if (!value) {
return false;
}
@@ -142,9 +142,9 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
bool use_conf_file{true};
{
LOCK(cs_args);
- if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) {
+ if (auto* includes = common::FindKey(m_settings.command_line_options, "includeconf")) {
// ParseParameters() fails if a non-negated -includeconf is passed on the command-line
- assert(util::SettingsSpan(*includes).last_negated());
+ assert(common::SettingsSpan(*includes).last_negated());
use_conf_file = false;
}
}
@@ -155,9 +155,9 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
auto add_includes = [&](const std::string& network, size_t skip = 0) {
size_t num_values = 0;
LOCK(cs_args);
- if (auto* section = util::FindKey(m_settings.ro_config, network)) {
- if (auto* values = util::FindKey(*section, "includeconf")) {
- for (size_t i = std::max(skip, util::SettingsSpan(*values).negated()); i < values->size(); ++i) {
+ if (auto* section = common::FindKey(m_settings.ro_config, network)) {
+ if (auto* values = common::FindKey(*section, "includeconf")) {
+ for (size_t i = std::max(skip, common::SettingsSpan(*values).negated()); i < values->size(); ++i) {
conf_file_names.push_back((*values)[i].get_str());
}
num_values = values->size();
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 7d08355b33..9187f242eb 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -16,7 +16,7 @@
#include <utility>
#include <vector>
-namespace util {
+namespace common {
namespace {
enum class Source {
@@ -258,4 +258,4 @@ size_t SettingsSpan::negated() const
return 0;
}
-} // namespace util
+} // namespace common
diff --git a/src/common/settings.h b/src/common/settings.h
index 4cec85ea1e..0e9d376e23 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -14,7 +14,7 @@
class UniValue;
-namespace util {
+namespace common {
//! Settings value type (string/integer/boolean/null variant).
//!
@@ -110,6 +110,6 @@ auto FindKey(Map&& map, Key&& key) -> decltype(&map.at(key))
return it == map.end() ? nullptr : &it->second;
}
-} // namespace util
+} // namespace common
#endif // BITCOIN_COMMON_SETTINGS_H