style(3p/nix): Reformat project in Google C++ style
Reformatted with:
fd . -e hh -e cc | xargs clang-format -i
This commit is contained in:
parent
65a1aae98c
commit
0f2cf531f7
175 changed files with 32126 additions and 34689 deletions
291
third_party/nix/src/libutil/config.hh
vendored
291
third_party/nix/src/libutil/config.hh
vendored
|
|
@ -1,6 +1,5 @@
|
|||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include "types.hh"
|
||||
|
||||
#pragma once
|
||||
|
|
@ -12,38 +11,34 @@ class AbstractSetting;
|
|||
class JSONPlaceholder;
|
||||
class JSONObject;
|
||||
|
||||
class AbstractConfig
|
||||
{
|
||||
protected:
|
||||
StringMap unknownSettings;
|
||||
class AbstractConfig {
|
||||
protected:
|
||||
StringMap unknownSettings;
|
||||
|
||||
AbstractConfig(const StringMap & initials = {})
|
||||
: unknownSettings(initials)
|
||||
{ }
|
||||
AbstractConfig(const StringMap& initials = {}) : unknownSettings(initials) {}
|
||||
|
||||
public:
|
||||
public:
|
||||
virtual bool set(const std::string& name, const std::string& value) = 0;
|
||||
|
||||
virtual bool set(const std::string & name, const std::string & value) = 0;
|
||||
struct SettingInfo {
|
||||
std::string value;
|
||||
std::string description;
|
||||
};
|
||||
|
||||
struct SettingInfo
|
||||
{
|
||||
std::string value;
|
||||
std::string description;
|
||||
};
|
||||
virtual void getSettings(std::map<std::string, SettingInfo>& res,
|
||||
bool overridenOnly = false) = 0;
|
||||
|
||||
virtual void getSettings(std::map<std::string, SettingInfo> & res, bool overridenOnly = false) = 0;
|
||||
void applyConfigFile(const Path& path);
|
||||
|
||||
void applyConfigFile(const Path & path);
|
||||
virtual void resetOverriden() = 0;
|
||||
|
||||
virtual void resetOverriden() = 0;
|
||||
virtual void toJSON(JSONObject& out) = 0;
|
||||
|
||||
virtual void toJSON(JSONObject & out) = 0;
|
||||
virtual void convertToArgs(Args& args, const std::string& category) = 0;
|
||||
|
||||
virtual void convertToArgs(Args & args, const std::string & category) = 0;
|
||||
void warnUnknownSettings();
|
||||
|
||||
void warnUnknownSettings();
|
||||
|
||||
void reapplyUnknownSettings();
|
||||
void reapplyUnknownSettings();
|
||||
};
|
||||
|
||||
/* A class to simplify providing configuration settings. The typical
|
||||
|
|
@ -61,201 +56,171 @@ public:
|
|||
};
|
||||
*/
|
||||
|
||||
class Config : public AbstractConfig
|
||||
{
|
||||
friend class AbstractSetting;
|
||||
class Config : public AbstractConfig {
|
||||
friend class AbstractSetting;
|
||||
|
||||
public:
|
||||
public:
|
||||
struct SettingData {
|
||||
bool isAlias;
|
||||
AbstractSetting* setting;
|
||||
SettingData(bool isAlias, AbstractSetting* setting)
|
||||
: isAlias(isAlias), setting(setting) {}
|
||||
};
|
||||
|
||||
struct SettingData
|
||||
{
|
||||
bool isAlias;
|
||||
AbstractSetting * setting;
|
||||
SettingData(bool isAlias, AbstractSetting * setting)
|
||||
: isAlias(isAlias), setting(setting)
|
||||
{ }
|
||||
};
|
||||
typedef std::map<std::string, SettingData> Settings;
|
||||
|
||||
typedef std::map<std::string, SettingData> Settings;
|
||||
private:
|
||||
Settings _settings;
|
||||
|
||||
private:
|
||||
public:
|
||||
Config(const StringMap& initials = {}) : AbstractConfig(initials) {}
|
||||
|
||||
Settings _settings;
|
||||
bool set(const std::string& name, const std::string& value) override;
|
||||
|
||||
public:
|
||||
void addSetting(AbstractSetting* setting);
|
||||
|
||||
Config(const StringMap & initials = {})
|
||||
: AbstractConfig(initials)
|
||||
{ }
|
||||
void getSettings(std::map<std::string, SettingInfo>& res,
|
||||
bool overridenOnly = false) override;
|
||||
|
||||
bool set(const std::string & name, const std::string & value) override;
|
||||
void resetOverriden() override;
|
||||
|
||||
void addSetting(AbstractSetting * setting);
|
||||
void toJSON(JSONObject& out) override;
|
||||
|
||||
void getSettings(std::map<std::string, SettingInfo> & res, bool overridenOnly = false) override;
|
||||
|
||||
void resetOverriden() override;
|
||||
|
||||
void toJSON(JSONObject & out) override;
|
||||
|
||||
void convertToArgs(Args & args, const std::string & category) override;
|
||||
void convertToArgs(Args& args, const std::string& category) override;
|
||||
};
|
||||
|
||||
class AbstractSetting
|
||||
{
|
||||
friend class Config;
|
||||
class AbstractSetting {
|
||||
friend class Config;
|
||||
|
||||
public:
|
||||
public:
|
||||
const std::string name;
|
||||
const std::string description;
|
||||
const std::set<std::string> aliases;
|
||||
|
||||
const std::string name;
|
||||
const std::string description;
|
||||
const std::set<std::string> aliases;
|
||||
int created = 123;
|
||||
|
||||
int created = 123;
|
||||
bool overriden = false;
|
||||
|
||||
bool overriden = false;
|
||||
protected:
|
||||
AbstractSetting(const std::string& name, const std::string& description,
|
||||
const std::set<std::string>& aliases);
|
||||
|
||||
protected:
|
||||
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);
|
||||
}
|
||||
|
||||
AbstractSetting(
|
||||
const std::string & name,
|
||||
const std::string & description,
|
||||
const std::set<std::string> & aliases);
|
||||
virtual void set(const std::string& value) = 0;
|
||||
|
||||
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 std::string to_string() = 0;
|
||||
|
||||
virtual void set(const std::string & value) = 0;
|
||||
virtual void toJSON(JSONPlaceholder& out);
|
||||
|
||||
virtual std::string to_string() = 0;
|
||||
virtual void convertToArg(Args& args, const std::string& category);
|
||||
|
||||
virtual void toJSON(JSONPlaceholder & out);
|
||||
|
||||
virtual void convertToArg(Args & args, const std::string & category);
|
||||
|
||||
bool isOverriden() { return overriden; }
|
||||
bool isOverriden() { return overriden; }
|
||||
};
|
||||
|
||||
/* A setting of type T. */
|
||||
template<typename T>
|
||||
class BaseSetting : public AbstractSetting
|
||||
{
|
||||
protected:
|
||||
template <typename T>
|
||||
class BaseSetting : public AbstractSetting {
|
||||
protected:
|
||||
T value;
|
||||
|
||||
T value;
|
||||
public:
|
||||
BaseSetting(const T& def, const std::string& name,
|
||||
const std::string& description,
|
||||
const std::set<std::string>& aliases = {})
|
||||
: AbstractSetting(name, description, aliases), value(def) {}
|
||||
|
||||
public:
|
||||
operator const T&() const { return value; }
|
||||
operator T&() { return value; }
|
||||
const T& get() const { return value; }
|
||||
bool operator==(const T& v2) const { return value == v2; }
|
||||
bool operator!=(const T& v2) const { return value != v2; }
|
||||
void operator=(const T& v) { assign(v); }
|
||||
virtual void assign(const T& v) { value = v; }
|
||||
|
||||
BaseSetting(const T & def,
|
||||
const std::string & name,
|
||||
const std::string & description,
|
||||
const std::set<std::string> & aliases = {})
|
||||
: AbstractSetting(name, description, aliases)
|
||||
, value(def)
|
||||
{ }
|
||||
void set(const std::string& str) override;
|
||||
|
||||
operator const T &() const { return value; }
|
||||
operator T &() { return value; }
|
||||
const T & get() const { return value; }
|
||||
bool operator ==(const T & v2) const { return value == v2; }
|
||||
bool operator !=(const T & v2) const { return value != v2; }
|
||||
void operator =(const T & v) { assign(v); }
|
||||
virtual void assign(const T & v) { value = v; }
|
||||
virtual void override(const T& v) {
|
||||
overriden = true;
|
||||
value = v;
|
||||
}
|
||||
|
||||
void set(const std::string & str) override;
|
||||
std::string to_string() override;
|
||||
|
||||
virtual void override(const T & v)
|
||||
{
|
||||
overriden = true;
|
||||
value = v;
|
||||
}
|
||||
void convertToArg(Args& args, const std::string& category) override;
|
||||
|
||||
std::string to_string() override;
|
||||
|
||||
void convertToArg(Args & args, const std::string & category) override;
|
||||
|
||||
void toJSON(JSONPlaceholder & out) override;
|
||||
void toJSON(JSONPlaceholder& out) override;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
std::ostream & operator <<(std::ostream & str, const BaseSetting<T> & opt)
|
||||
{
|
||||
str << (const T &) opt;
|
||||
return str;
|
||||
template <typename T>
|
||||
std::ostream& operator<<(std::ostream& str, const BaseSetting<T>& opt) {
|
||||
str << (const T&)opt;
|
||||
return str;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool operator ==(const T & v1, const BaseSetting<T> & v2) { return v1 == (const T &) v2; }
|
||||
template <typename T>
|
||||
bool operator==(const T& v1, const BaseSetting<T>& v2) {
|
||||
return v1 == (const T&)v2;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class Setting : public BaseSetting<T>
|
||||
{
|
||||
public:
|
||||
Setting(Config * options,
|
||||
const T & def,
|
||||
const std::string & name,
|
||||
const std::string & description,
|
||||
const std::set<std::string> & aliases = {})
|
||||
: BaseSetting<T>(def, name, description, aliases)
|
||||
{
|
||||
options->addSetting(this);
|
||||
}
|
||||
template <typename T>
|
||||
class Setting : public BaseSetting<T> {
|
||||
public:
|
||||
Setting(Config* options, const T& def, const std::string& name,
|
||||
const std::string& description,
|
||||
const std::set<std::string>& aliases = {})
|
||||
: BaseSetting<T>(def, name, description, aliases) {
|
||||
options->addSetting(this);
|
||||
}
|
||||
|
||||
void operator =(const T & v) { this->assign(v); }
|
||||
void operator=(const T& v) { this->assign(v); }
|
||||
};
|
||||
|
||||
/* A special setting for Paths. These are automatically canonicalised
|
||||
(e.g. "/foo//bar/" becomes "/foo/bar"). */
|
||||
class PathSetting : public BaseSetting<Path>
|
||||
{
|
||||
bool allowEmpty;
|
||||
class PathSetting : public BaseSetting<Path> {
|
||||
bool allowEmpty;
|
||||
|
||||
public:
|
||||
public:
|
||||
PathSetting(Config* options, bool allowEmpty, const Path& def,
|
||||
const std::string& name, const std::string& description,
|
||||
const std::set<std::string>& aliases = {})
|
||||
: BaseSetting<Path>(def, name, description, aliases),
|
||||
allowEmpty(allowEmpty) {
|
||||
options->addSetting(this);
|
||||
}
|
||||
|
||||
PathSetting(Config * options,
|
||||
bool allowEmpty,
|
||||
const Path & def,
|
||||
const std::string & name,
|
||||
const std::string & description,
|
||||
const std::set<std::string> & aliases = {})
|
||||
: BaseSetting<Path>(def, name, description, aliases)
|
||||
, allowEmpty(allowEmpty)
|
||||
{
|
||||
options->addSetting(this);
|
||||
}
|
||||
void set(const std::string& str) override;
|
||||
|
||||
void set(const std::string & str) override;
|
||||
Path operator+(const char* p) const { return value + p; }
|
||||
|
||||
Path operator +(const char * p) const { return value + p; }
|
||||
|
||||
void operator =(const Path & v) { this->assign(v); }
|
||||
void operator=(const Path& v) { this->assign(v); }
|
||||
};
|
||||
|
||||
struct GlobalConfig : public AbstractConfig
|
||||
{
|
||||
typedef std::vector<Config*> ConfigRegistrations;
|
||||
static ConfigRegistrations * configRegistrations;
|
||||
struct GlobalConfig : public AbstractConfig {
|
||||
typedef std::vector<Config*> ConfigRegistrations;
|
||||
static ConfigRegistrations* configRegistrations;
|
||||
|
||||
bool set(const std::string & name, const std::string & value) override;
|
||||
bool set(const std::string& name, const std::string& value) override;
|
||||
|
||||
void getSettings(std::map<std::string, SettingInfo> & res, bool overridenOnly = false) override;
|
||||
void getSettings(std::map<std::string, SettingInfo>& res,
|
||||
bool overridenOnly = false) override;
|
||||
|
||||
void resetOverriden() override;
|
||||
void resetOverriden() override;
|
||||
|
||||
void toJSON(JSONObject & out) override;
|
||||
void toJSON(JSONObject& out) override;
|
||||
|
||||
void convertToArgs(Args & args, const std::string & category) override;
|
||||
void convertToArgs(Args& args, const std::string& category) override;
|
||||
|
||||
struct Register
|
||||
{
|
||||
Register(Config * config);
|
||||
};
|
||||
struct Register {
|
||||
Register(Config* config);
|
||||
};
|
||||
};
|
||||
|
||||
extern GlobalConfig globalConfig;
|
||||
|
||||
}
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue