2020-07-22 12:02:47 +00:00
|
|
|
#include <Common/SettingsChanges.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
2022-07-14 16:11:35 +00:00
|
|
|
SettingChange * find(SettingsChanges & changes, std::string_view name)
|
2020-07-22 12:02:47 +00:00
|
|
|
{
|
|
|
|
auto it = std::find_if(changes.begin(), changes.end(), [&name](const SettingChange & change) { return change.name == name; });
|
|
|
|
if (it == changes.end())
|
|
|
|
return nullptr;
|
|
|
|
return &*it;
|
|
|
|
}
|
|
|
|
|
2022-07-14 16:11:35 +00:00
|
|
|
const SettingChange * find(const SettingsChanges & changes, std::string_view name)
|
2020-07-22 12:02:47 +00:00
|
|
|
{
|
|
|
|
auto it = std::find_if(changes.begin(), changes.end(), [&name](const SettingChange & change) { return change.name == name; });
|
|
|
|
if (it == changes.end())
|
|
|
|
return nullptr;
|
|
|
|
return &*it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-14 16:11:35 +00:00
|
|
|
bool SettingsChanges::tryGet(std::string_view name, Field & out_value) const
|
2020-07-22 12:02:47 +00:00
|
|
|
{
|
|
|
|
const auto * change = find(*this, name);
|
|
|
|
if (!change)
|
|
|
|
return false;
|
|
|
|
out_value = change->value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-07-14 16:11:35 +00:00
|
|
|
const Field * SettingsChanges::tryGet(std::string_view name) const
|
2020-07-22 12:02:47 +00:00
|
|
|
{
|
|
|
|
const auto * change = find(*this, name);
|
|
|
|
if (!change)
|
|
|
|
return nullptr;
|
|
|
|
return &change->value;
|
|
|
|
}
|
|
|
|
|
2022-07-14 16:11:35 +00:00
|
|
|
Field * SettingsChanges::tryGet(std::string_view name)
|
2020-07-22 12:02:47 +00:00
|
|
|
{
|
|
|
|
auto * change = find(*this, name);
|
|
|
|
if (!change)
|
|
|
|
return nullptr;
|
|
|
|
return &change->value;
|
|
|
|
}
|
|
|
|
|
2023-02-21 22:36:02 +00:00
|
|
|
bool SettingsChanges::insertSetting(std::string_view name, const Field & value)
|
|
|
|
{
|
2023-02-22 17:22:13 +00:00
|
|
|
auto it = std::find_if(begin(), end(), [&name](const SettingChange & change) { return change.name == name; });
|
|
|
|
if (it != end())
|
2023-02-21 22:36:02 +00:00
|
|
|
return false;
|
|
|
|
emplace_back(name, value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsChanges::setSetting(std::string_view name, const Field & value)
|
|
|
|
{
|
2023-02-22 17:22:13 +00:00
|
|
|
if (auto * setting_value = tryGet(name))
|
|
|
|
*setting_value = value;
|
2023-02-21 22:36:02 +00:00
|
|
|
else
|
|
|
|
insertSetting(name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SettingsChanges::removeSetting(std::string_view name)
|
|
|
|
{
|
|
|
|
auto it = std::find_if(begin(), end(), [&name](const SettingChange & change) { return change.name == name; });
|
|
|
|
if (it == end())
|
|
|
|
return false;
|
|
|
|
erase(it);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-22 12:02:47 +00:00
|
|
|
}
|