Settings: Remove unused functions

Make Settings-internal functions private
This commit is contained in:
SmallJoker 2020-09-20 12:52:35 +02:00 committed by Loïc Blot
parent a69bc67ce2
commit 79414aa3e5
2 changed files with 33 additions and 103 deletions

View File

@ -45,7 +45,13 @@ Settings::~Settings()
Settings & Settings::operator += (const Settings &other) Settings & Settings::operator += (const Settings &other)
{ {
update(other); if (&other == this)
return *this;
MutexAutoLock lock(m_mutex);
MutexAutoLock lock2(other.m_mutex);
updateNoLock(other);
return *this; return *this;
} }
@ -512,25 +518,6 @@ u32 Settings::getFlagStr(const std::string &name, const FlagDesc *flagdesc,
return flags; return flags;
} }
// N.B. if getStruct() is used to read a non-POD aggregate type,
// the behavior is undefined.
bool Settings::getStruct(const std::string &name, const std::string &format,
void *out, size_t olen) const
{
std::string valstr;
try {
valstr = get(name);
} catch (SettingNotFoundException &e) {
return false;
}
if (!deSerializeStringToStruct(valstr, format, out, olen))
return false;
return true;
}
bool Settings::getNoiseParams(const std::string &name, NoiseParams &np) const bool Settings::getNoiseParams(const std::string &name, NoiseParams &np) const
{ {
@ -546,6 +533,7 @@ bool Settings::getNoiseParamsFromValue(const std::string &name,
if (!getNoEx(name, value)) if (!getNoEx(name, value))
return false; return false;
// Format: f32,f32,(f32,f32,f32),s32,s32,f32[,f32]
Strfnd f(value); Strfnd f(value);
np.offset = stof(f.next(",")); np.offset = stof(f.next(","));
@ -615,28 +603,6 @@ std::vector<std::string> Settings::getNames() const
* Getters that don't throw exceptions * * Getters that don't throw exceptions *
***************************************/ ***************************************/
bool Settings::getEntryNoEx(const std::string &name, SettingsEntry &val) const
{
try {
val = getEntry(name);
return true;
} catch (SettingNotFoundException &e) {
return false;
}
}
bool Settings::getEntryDefaultNoEx(const std::string &name, SettingsEntry &val) const
{
try {
val = getEntryDefault(name);
return true;
} catch (SettingNotFoundException &e) {
return false;
}
}
bool Settings::getGroupNoEx(const std::string &name, Settings *&val) const bool Settings::getGroupNoEx(const std::string &name, Settings *&val) const
{ {
try { try {
@ -908,17 +874,6 @@ bool Settings::setFlagStr(const std::string &name, u32 flags,
} }
bool Settings::setStruct(const std::string &name, const std::string &format,
void *value)
{
std::string structstr;
if (!serializeStructToString(&structstr, format, value))
return false;
return set(name, structstr);
}
bool Settings::setNoiseParams(const std::string &name, bool Settings::setNoiseParams(const std::string &name,
const NoiseParams &np, bool set_default) const NoiseParams &np, bool set_default)
{ {
@ -969,32 +924,6 @@ void Settings::clearDefaults()
clearDefaultsNoLock(); clearDefaultsNoLock();
} }
void Settings::updateValue(const Settings &other, const std::string &name)
{
if (&other == this)
return;
MutexAutoLock lock(m_mutex);
try {
m_settings[name] = other.get(name);
} catch (SettingNotFoundException &e) {
}
}
void Settings::update(const Settings &other)
{
if (&other == this)
return;
MutexAutoLock lock(m_mutex);
MutexAutoLock lock2(other.m_mutex);
updateNoLock(other);
}
SettingsParseEvent Settings::parseConfigObject(const std::string &line, SettingsParseEvent Settings::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)
{ {

View File

@ -113,23 +113,10 @@ public:
bool parseConfigLines(std::istream &is, const std::string &end = ""); 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);
bool updateConfigObject(std::istream &is, std::ostream &os,
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 void printEntry(std::ostream &os, const std::string &name,
const SettingsEntry &entry, u32 tab_depth=0);
/*********** /***********
* Getters * * Getters *
***********/ ***********/
const SettingsEntry &getEntry(const std::string &name) const;
const SettingsEntry &getEntryDefault(const std::string &name) const;
Settings *getGroup(const std::string &name) const; Settings *getGroup(const std::string &name) const;
const std::string &get(const std::string &name) const; const std::string &get(const std::string &name) const;
const std::string &getDefault(const std::string &name) const; const std::string &getDefault(const std::string &name) const;
@ -144,10 +131,6 @@ public:
v3f getV3F(const std::string &name) const; v3f getV3F(const std::string &name) const;
u32 getFlagStr(const std::string &name, const FlagDesc *flagdesc, u32 getFlagStr(const std::string &name, const FlagDesc *flagdesc,
u32 *flagmask) const; 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 getNoiseParams(const std::string &name, NoiseParams &np) const; bool getNoiseParams(const std::string &name, NoiseParams &np) const;
bool getNoiseParamsFromValue(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; bool getNoiseParamsFromGroup(const std::string &name, NoiseParams &np) const;
@ -161,8 +144,6 @@ public:
* Getters that don't throw exceptions * * Getters that don't throw exceptions *
***************************************/ ***************************************/
bool getEntryNoEx(const std::string &name, SettingsEntry &val) const;
bool getEntryDefaultNoEx(const std::string &name, SettingsEntry &val) const;
bool getGroupNoEx(const std::string &name, Settings *&val) const; bool getGroupNoEx(const std::string &name, Settings *&val) const;
bool getNoEx(const std::string &name, std::string &val) const; bool getNoEx(const std::string &name, std::string &val) const;
bool getDefaultNoEx(const std::string &name, std::string &val) const; bool getDefaultNoEx(const std::string &name, std::string &val) const;
@ -206,16 +187,11 @@ public:
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 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);
// remove a setting // remove a setting
bool remove(const std::string &name); bool remove(const std::string &name);
void clear(); void clear();
void clearDefaults(); void clearDefaults();
void updateValue(const Settings &other, const std::string &name);
void update(const Settings &other);
/************** /**************
* Miscellany * * Miscellany *
@ -232,6 +208,31 @@ public:
SettingsChangedCallback cbf, void *userdata = NULL); SettingsChangedCallback cbf, void *userdata = NULL);
private: private:
/***********************
* Reading and writing *
***********************/
SettingsParseEvent parseConfigObject(const std::string &line,
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);
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 void printEntry(std::ostream &os, const std::string &name,
const SettingsEntry &entry, u32 tab_depth=0);
/***********
* Getters *
***********/
const SettingsEntry &getEntry(const std::string &name) const;
const SettingsEntry &getEntryDefault(const std::string &name) const;
// Allow TestSettings to run sanity checks using private functions.
friend class TestSettings;
void updateNoLock(const Settings &other); void updateNoLock(const Settings &other);
void clearNoLock(); void clearNoLock();
void clearDefaultsNoLock(); void clearDefaultsNoLock();