mirror of
https://github.com/NixOS/nix
synced 2025-07-05 16:31:47 +02:00
Simplify ConfigRegistrations
This commit is contained in:
parent
f59ccb468e
commit
47989a2124
2 changed files with 12 additions and 11 deletions
|
@ -6,7 +6,7 @@ namespace nix {
|
||||||
|
|
||||||
bool GlobalConfig::set(const std::string & name, const std::string & value)
|
bool GlobalConfig::set(const std::string & name, const std::string & value)
|
||||||
{
|
{
|
||||||
for (auto & config : *configRegistrations)
|
for (auto & config : configRegistrations())
|
||||||
if (config->set(name, value))
|
if (config->set(name, value))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -17,20 +17,20 @@ bool GlobalConfig::set(const std::string & name, const std::string & value)
|
||||||
|
|
||||||
void GlobalConfig::getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly)
|
void GlobalConfig::getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly)
|
||||||
{
|
{
|
||||||
for (auto & config : *configRegistrations)
|
for (auto & config : configRegistrations())
|
||||||
config->getSettings(res, overriddenOnly);
|
config->getSettings(res, overriddenOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalConfig::resetOverridden()
|
void GlobalConfig::resetOverridden()
|
||||||
{
|
{
|
||||||
for (auto & config : *configRegistrations)
|
for (auto & config : configRegistrations())
|
||||||
config->resetOverridden();
|
config->resetOverridden();
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json GlobalConfig::toJSON()
|
nlohmann::json GlobalConfig::toJSON()
|
||||||
{
|
{
|
||||||
auto res = nlohmann::json::object();
|
auto res = nlohmann::json::object();
|
||||||
for (const auto & config : *configRegistrations)
|
for (const auto & config : configRegistrations())
|
||||||
res.update(config->toJSON());
|
res.update(config->toJSON());
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -47,19 +47,15 @@ std::string GlobalConfig::toKeyValue()
|
||||||
|
|
||||||
void GlobalConfig::convertToArgs(Args & args, const std::string & category)
|
void GlobalConfig::convertToArgs(Args & args, const std::string & category)
|
||||||
{
|
{
|
||||||
for (auto & config : *configRegistrations)
|
for (auto & config : configRegistrations())
|
||||||
config->convertToArgs(args, category);
|
config->convertToArgs(args, category);
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalConfig globalConfig;
|
GlobalConfig globalConfig;
|
||||||
|
|
||||||
GlobalConfig::ConfigRegistrations * GlobalConfig::configRegistrations;
|
|
||||||
|
|
||||||
GlobalConfig::Register::Register(Config * config)
|
GlobalConfig::Register::Register(Config * config)
|
||||||
{
|
{
|
||||||
if (!configRegistrations)
|
configRegistrations().emplace_back(config);
|
||||||
configRegistrations = new ConfigRegistrations;
|
|
||||||
configRegistrations->emplace_back(config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ExperimentalFeatureSettings experimentalFeatureSettings;
|
ExperimentalFeatureSettings experimentalFeatureSettings;
|
||||||
|
|
|
@ -8,7 +8,12 @@ namespace nix {
|
||||||
struct GlobalConfig : public AbstractConfig
|
struct GlobalConfig : public AbstractConfig
|
||||||
{
|
{
|
||||||
typedef std::vector<Config *> ConfigRegistrations;
|
typedef std::vector<Config *> ConfigRegistrations;
|
||||||
static ConfigRegistrations * configRegistrations;
|
|
||||||
|
static ConfigRegistrations & configRegistrations()
|
||||||
|
{
|
||||||
|
static ConfigRegistrations configRegistrations;
|
||||||
|
return configRegistrations;
|
||||||
|
}
|
||||||
|
|
||||||
bool set(const std::string & name, const std::string & value) override;
|
bool set(const std::string & name, const std::string & value) override;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue