mirror of
https://github.com/NixOS/nix.git
synced 2024-11-22 14:52:55 +00:00
libutil: Move some non-template implememntations from config.hh to
config.cc
This commit is contained in:
parent
9bc7b4f463
commit
87c4f4a972
@ -9,6 +9,10 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
Config::Config(StringMap initials)
|
||||
: AbstractConfig(std::move(initials))
|
||||
{ }
|
||||
|
||||
bool Config::set(const std::string & name, const std::string & value)
|
||||
{
|
||||
bool append = false;
|
||||
@ -59,6 +63,10 @@ void Config::addSetting(AbstractSetting * setting)
|
||||
}
|
||||
}
|
||||
|
||||
AbstractConfig::AbstractConfig(StringMap initials)
|
||||
: unknownSettings(std::move(initials))
|
||||
{ }
|
||||
|
||||
void AbstractConfig::warnUnknownSettings()
|
||||
{
|
||||
for (auto & s : unknownSettings)
|
||||
@ -199,6 +207,13 @@ AbstractSetting::AbstractSetting(
|
||||
{
|
||||
}
|
||||
|
||||
AbstractSetting::~AbstractSetting()
|
||||
{
|
||||
// Check against a gcc miscompilation causing our constructor
|
||||
// not to run (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80431).
|
||||
assert(created == 123);
|
||||
}
|
||||
|
||||
nlohmann::json AbstractSetting::toJSON()
|
||||
{
|
||||
return nlohmann::json(toJSONObject());
|
||||
@ -220,6 +235,9 @@ void AbstractSetting::convertToArg(Args & args, const std::string & category)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool AbstractSetting::isOverridden() const { return overridden; }
|
||||
|
||||
template<> std::string BaseSetting<std::string>::parse(const std::string & str) const
|
||||
{
|
||||
return str;
|
||||
@ -385,11 +403,33 @@ static Path parsePath(const AbstractSetting & s, const std::string & str)
|
||||
return canonPath(str);
|
||||
}
|
||||
|
||||
PathSetting::PathSetting(Config * options,
|
||||
const Path & def,
|
||||
const std::string & name,
|
||||
const std::string & description,
|
||||
const std::set<std::string> & aliases)
|
||||
: BaseSetting<Path>(def, true, name, description, aliases)
|
||||
{
|
||||
options->addSetting(this);
|
||||
}
|
||||
|
||||
Path PathSetting::parse(const std::string & str) const
|
||||
{
|
||||
return parsePath(*this, str);
|
||||
}
|
||||
|
||||
|
||||
OptionalPathSetting::OptionalPathSetting(Config * options,
|
||||
const std::optional<Path> & def,
|
||||
const std::string & name,
|
||||
const std::string & description,
|
||||
const std::set<std::string> & aliases)
|
||||
: BaseSetting<std::optional<Path>>(def, true, name, description, aliases)
|
||||
{
|
||||
options->addSetting(this);
|
||||
}
|
||||
|
||||
|
||||
std::optional<Path> OptionalPathSetting::parse(const std::string & str) const
|
||||
{
|
||||
if (str == "")
|
||||
@ -398,6 +438,11 @@ std::optional<Path> OptionalPathSetting::parse(const std::string & str) const
|
||||
return parsePath(*this, str);
|
||||
}
|
||||
|
||||
void OptionalPathSetting::operator =(const std::optional<Path> & v)
|
||||
{
|
||||
this->assign(v);
|
||||
}
|
||||
|
||||
bool GlobalConfig::set(const std::string & name, const std::string & value)
|
||||
{
|
||||
for (auto & config : *configRegistrations)
|
||||
|
@ -52,9 +52,7 @@ class AbstractConfig
|
||||
protected:
|
||||
StringMap unknownSettings;
|
||||
|
||||
AbstractConfig(const StringMap & initials = {})
|
||||
: unknownSettings(initials)
|
||||
{ }
|
||||
AbstractConfig(StringMap initials = {});
|
||||
|
||||
public:
|
||||
|
||||
@ -163,9 +161,7 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
Config(const StringMap & initials = {})
|
||||
: AbstractConfig(initials)
|
||||
{ }
|
||||
Config(StringMap initials = {});
|
||||
|
||||
bool set(const std::string & name, const std::string & value) override;
|
||||
|
||||
@ -206,12 +202,7 @@ protected:
|
||||
const std::set<std::string> & aliases,
|
||||
std::optional<ExperimentalFeature> experimentalFeature = std::nullopt);
|
||||
|
||||
virtual ~AbstractSetting()
|
||||
{
|
||||
// Check against a gcc miscompilation causing our constructor
|
||||
// not to run (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80431).
|
||||
assert(created == 123);
|
||||
}
|
||||
virtual ~AbstractSetting();
|
||||
|
||||
virtual void set(const std::string & value, bool append = false) = 0;
|
||||
|
||||
@ -229,7 +220,7 @@ protected:
|
||||
|
||||
virtual void convertToArg(Args & args, const std::string & category);
|
||||
|
||||
bool isOverridden() const { return overridden; }
|
||||
bool isOverridden() const;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -365,11 +356,7 @@ public:
|
||||
const Path & def,
|
||||
const std::string & name,
|
||||
const std::string & description,
|
||||
const std::set<std::string> & aliases = {})
|
||||
: BaseSetting<Path>(def, true, name, description, aliases)
|
||||
{
|
||||
options->addSetting(this);
|
||||
}
|
||||
const std::set<std::string> & aliases = {});
|
||||
|
||||
Path parse(const std::string & str) const override;
|
||||
|
||||
@ -391,15 +378,11 @@ public:
|
||||
const std::optional<Path> & def,
|
||||
const std::string & name,
|
||||
const std::string & description,
|
||||
const std::set<std::string> & aliases = {})
|
||||
: BaseSetting<std::optional<Path>>(def, true, name, description, aliases)
|
||||
{
|
||||
options->addSetting(this);
|
||||
}
|
||||
const std::set<std::string> & aliases = {});
|
||||
|
||||
std::optional<Path> parse(const std::string & str) const override;
|
||||
|
||||
void operator =(const std::optional<Path> & v) { this->assign(v); }
|
||||
void operator =(const std::optional<Path> & v);
|
||||
};
|
||||
|
||||
struct GlobalConfig : public AbstractConfig
|
||||
|
Loading…
Reference in New Issue
Block a user