aboutsummaryrefslogtreecommitdiff
path: root/src/settings.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/settings.h')
-rw-r--r--src/settings.h72
1 files changed, 32 insertions, 40 deletions
diff --git a/src/settings.h b/src/settings.h
index 0c9a155db..46adce164 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -36,21 +36,18 @@ extern std::string g_settings_path;
// Type for a settings changed callback function
typedef void (*SettingsChangedCallback)(const std::string &name, void *data);
-typedef std::vector<
- std::pair<
- SettingsChangedCallback,
- void *
- >
-> SettingsCallbackList;
+typedef std::vector<std::pair<SettingsChangedCallback, void *>> SettingsCallbackList;
typedef std::unordered_map<std::string, SettingsCallbackList> SettingsCallbackMap;
-enum ValueType {
+enum ValueType
+{
VALUETYPE_STRING,
VALUETYPE_FLAG // Doesn't take any arguments
};
-enum SettingsParseEvent {
+enum SettingsParseEvent
+{
SPE_NONE,
SPE_INVALID,
SPE_COMMENT,
@@ -60,8 +57,9 @@ enum SettingsParseEvent {
SPE_MULTILINE,
};
-struct ValueSpec {
- ValueSpec(ValueType a_type, const char *a_help=NULL)
+struct ValueSpec
+{
+ ValueSpec(ValueType a_type, const char *a_help = NULL)
{
type = a_type;
help = a_help;
@@ -71,17 +69,13 @@ struct ValueSpec {
const char *help;
};
-struct SettingsEntry {
+struct SettingsEntry
+{
SettingsEntry() = default;
- SettingsEntry(const std::string &value_) :
- value(value_)
- {}
+ SettingsEntry(const std::string &value_) : value(value_) {}
- SettingsEntry(Settings *group_) :
- group(group_),
- is_group(true)
- {}
+ SettingsEntry(Settings *group_) : group(group_), is_group(true) {}
std::string value = "";
Settings *group = nullptr;
@@ -90,14 +84,15 @@ struct SettingsEntry {
typedef std::unordered_map<std::string, SettingsEntry> SettingEntries;
-class Settings {
+class Settings
+{
public:
Settings() = default;
~Settings();
- Settings & operator += (const Settings &other);
- Settings & operator = (const Settings &other);
+ Settings &operator+=(const Settings &other);
+ Settings &operator=(const Settings &other);
/***********************
* Reading and writing *
@@ -105,24 +100,24 @@ public:
// Read configuration file. Returns success.
bool readConfigFile(const char *filename);
- //Updates configuration file. Returns success.
+ // Updates configuration file. Returns success.
bool updateConfigFile(const char *filename);
// NOTE: Types of allowed_options are ignored. Returns success.
bool parseCommandLine(int argc, char *argv[],
std::map<std::string, ValueSpec> &allowed_options);
bool parseConfigLines(std::istream &is, const std::string &end = "");
- void writeLines(std::ostream &os, u32 tab_depth=0) const;
+ void writeLines(std::ostream &os, u32 tab_depth = 0) const;
SettingsParseEvent parseConfigObject(const std::string &line,
- const std::string &end, std::string &name, std::string &value);
+ const std::string &end, std::string &name, std::string &value);
bool updateConfigObject(std::istream &is, std::ostream &os,
- const std::string &end, u32 tab_depth=0);
+ const std::string &end, u32 tab_depth = 0);
static bool checkNameValid(const std::string &name);
static bool checkValueValid(const std::string &value);
- static std::string getMultiline(std::istream &is, size_t *num_lines=NULL);
+ static std::string getMultiline(std::istream &is, size_t *num_lines = NULL);
static void printEntry(std::ostream &os, const std::string &name,
- const SettingsEntry &entry, u32 tab_depth=0);
+ const SettingsEntry &entry, u32 tab_depth = 0);
/***********
* Getters *
@@ -146,8 +141,8 @@ public:
u32 *flagmask) const;
// N.B. if getStruct() is used to read a non-POD aggregate type,
// the behavior is undefined.
- bool getStruct(const std::string &name, const std::string &format,
- void *out, size_t olen) const;
+ bool getStruct(const std::string &name, const std::string &format, void *out,
+ size_t olen) const;
bool getNoiseParams(const std::string &name, NoiseParams &np) const;
bool getNoiseParamsFromValue(const std::string &name, NoiseParams &np) const;
bool getNoiseParamsFromGroup(const std::string &name, NoiseParams &np) const;
@@ -156,7 +151,6 @@ public:
std::vector<std::string> getNames() const;
bool exists(const std::string &name) const;
-
/***************************************
* Getters that don't throw exceptions *
***************************************/
@@ -179,8 +173,7 @@ public:
// 1) Read default flags (or 0)
// 2) Override using user-defined flags
bool getFlagStrNoEx(const std::string &name, u32 &val,
- const FlagDesc *flagdesc) const;
-
+ const FlagDesc *flagdesc) const;
/***********
* Setters *
@@ -188,8 +181,8 @@ public:
// N.B. Groups not allocated with new must be set to NULL in the settings
// tree before object destruction.
- bool setEntry(const std::string &name, const void *entry,
- bool set_group, bool set_default);
+ bool setEntry(const std::string &name, const void *entry, bool set_group,
+ bool set_default);
bool set(const std::string &name, const std::string &value);
bool setDefault(const std::string &name, const std::string &value);
bool setGroup(const std::string &name, Settings *group);
@@ -203,9 +196,9 @@ public:
bool setV2F(const std::string &name, v2f value);
bool setV3F(const std::string &name, v3f value);
bool setFlagStr(const std::string &name, u32 flags,
- const FlagDesc *flagdesc = nullptr, u32 flagmask = U32_MAX);
+ const FlagDesc *flagdesc = nullptr, u32 flagmask = U32_MAX);
bool setNoiseParams(const std::string &name, const NoiseParams &np,
- bool set_default=false);
+ bool set_default = false);
// N.B. if setStruct() is used to write a non-POD aggregate type,
// the behavior is undefined.
bool setStruct(const std::string &name, const std::string &format, void *value);
@@ -226,10 +219,10 @@ public:
void overrideDefaults(Settings *other);
const FlagDesc *getFlagDescFallback(const std::string &name) const;
- void registerChangedCallback(const std::string &name,
- SettingsChangedCallback cbf, void *userdata = NULL);
+ void registerChangedCallback(const std::string &name, SettingsChangedCallback cbf,
+ void *userdata = NULL);
void deregisterChangedCallback(const std::string &name,
- SettingsChangedCallback cbf, void *userdata = NULL);
+ SettingsChangedCallback cbf, void *userdata = NULL);
private:
void updateNoLock(const Settings &other);
@@ -248,5 +241,4 @@ private:
// All methods that access m_settings/m_defaults directly should lock this.
mutable std::mutex m_mutex;
-
};