Mark all config parsing methods as const.

This commit is contained in:
Sadie Powell 2020-04-12 05:52:10 +01:00
parent 43f6c20e40
commit d99ee13f29
2 changed files with 21 additions and 21 deletions

View File

@ -49,17 +49,17 @@ class CoreExport ConfigTag : public refcountbase
const int src_line; const int src_line;
/** Get the value of an option, using def if it does not exist */ /** Get the value of an option, using def if it does not exist */
std::string getString(const std::string& key, const std::string& def, const std::function<bool(const std::string&)>& validator); std::string getString(const std::string& key, const std::string& def, const std::function<bool(const std::string&)>& validator) const;
/** Get the value of an option, using def if it does not exist */ /** Get the value of an option, using def if it does not exist */
std::string getString(const std::string& key, const std::string& def = "", size_t minlen = 0, size_t maxlen = UINT32_MAX); std::string getString(const std::string& key, const std::string& def = "", size_t minlen = 0, size_t maxlen = UINT32_MAX) const;
/** Get the value of an option, using def if it does not exist */ /** Get the value of an option, using def if it does not exist */
long getInt(const std::string& key, long def, long min = LONG_MIN, long max = LONG_MAX); long getInt(const std::string& key, long def, long min = LONG_MIN, long max = LONG_MAX) const;
/** Get the value of an option, using def if it does not exist */ /** Get the value of an option, using def if it does not exist */
unsigned long getUInt(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX); unsigned long getUInt(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX) const;
/** Get the value of an option, using def if it does not exist */ /** Get the value of an option, using def if it does not exist */
double getFloat(const std::string& key, double def, double min = DBL_MIN, double max = DBL_MAX); double getFloat(const std::string& key, double def, double min = DBL_MIN, double max = DBL_MAX) const;
/** Get the value of an option, using def if it does not exist */ /** Get the value of an option, using def if it does not exist */
bool getBool(const std::string& key, bool def = false); bool getBool(const std::string& key, bool def = false) const;
/** Get the value in seconds of a duration that is in the user-friendly "1h2m3s" format, /** Get the value in seconds of a duration that is in the user-friendly "1h2m3s" format,
* using a default value if it does not exist or is out of bounds. * using a default value if it does not exist or is out of bounds.
@ -69,7 +69,7 @@ class CoreExport ConfigTag : public refcountbase
* @param max Maximum acceptable value (optional) * @param max Maximum acceptable value (optional)
* @return The duration in seconds * @return The duration in seconds
*/ */
unsigned long getDuration(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX); unsigned long getDuration(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX) const;
/** Get the value of an option /** Get the value of an option
* @param key The option to get * @param key The option to get
@ -77,9 +77,9 @@ class CoreExport ConfigTag : public refcountbase
* @param allow_newline Allow newlines in the option (normally replaced with spaces) * @param allow_newline Allow newlines in the option (normally replaced with spaces)
* @return true if the option exists * @return true if the option exists
*/ */
bool readString(const std::string& key, std::string& value, bool allow_newline = false); bool readString(const std::string& key, std::string& value, bool allow_newline = false) const;
std::string getTagLocation(); std::string getTagLocation() const;
inline const ConfigItems& getItems() const { return items; } inline const ConfigItems& getItems() const { return items; }

View File

@ -306,14 +306,14 @@ struct Parser
} }
else if (stdalgo::string::equalsci(name, "files")) else if (stdalgo::string::equalsci(name, "files"))
{ {
for(ConfigItems::iterator i = items->begin(); i != items->end(); i++) for(ConfigItems::const_iterator i = items->begin(); i != items->end(); i++)
{ {
stack.DoReadFile(i->first, i->second, flags, false); stack.DoReadFile(i->first, i->second, flags, false);
} }
} }
else if (stdalgo::string::equalsci(name, "execfiles")) else if (stdalgo::string::equalsci(name, "execfiles"))
{ {
for(ConfigItems::iterator i = items->begin(); i != items->end(); i++) for(ConfigItems::const_iterator i = items->begin(); i != items->end(); i++)
{ {
stack.DoReadFile(i->first, i->second, flags, true); stack.DoReadFile(i->first, i->second, flags, true);
} }
@ -486,9 +486,9 @@ bool ParseStack::ParseFile(const std::string& path, int flags, const std::string
return ok; return ok;
} }
bool ConfigTag::readString(const std::string& key, std::string& value, bool allow_lf) bool ConfigTag::readString(const std::string& key, std::string& value, bool allow_lf) const
{ {
for(ConfigItems::iterator j = items.begin(); j != items.end(); ++j) for(ConfigItems::const_iterator j = items.begin(); j != items.end(); ++j)
{ {
if(j->first != key) if(j->first != key)
continue; continue;
@ -506,7 +506,7 @@ bool ConfigTag::readString(const std::string& key, std::string& value, bool allo
return false; return false;
} }
std::string ConfigTag::getString(const std::string& key, const std::string& def, const std::function<bool(const std::string&)>& validator) std::string ConfigTag::getString(const std::string& key, const std::string& def, const std::function<bool(const std::string&)>& validator) const
{ {
std::string res; std::string res;
if (!readString(key, res)) if (!readString(key, res))
@ -521,7 +521,7 @@ std::string ConfigTag::getString(const std::string& key, const std::string& def,
return res; return res;
} }
std::string ConfigTag::getString(const std::string& key, const std::string& def, size_t minlen, size_t maxlen) std::string ConfigTag::getString(const std::string& key, const std::string& def, size_t minlen, size_t maxlen) const
{ {
std::string res; std::string res;
if (!readString(key, res)) if (!readString(key, res))
@ -598,7 +598,7 @@ namespace
} }
} }
long ConfigTag::getInt(const std::string &key, long def, long min, long max) long ConfigTag::getInt(const std::string& key, long def, long min, long max) const
{ {
std::string result; std::string result;
if(!readString(key, result)) if(!readString(key, result))
@ -615,7 +615,7 @@ long ConfigTag::getInt(const std::string &key, long def, long min, long max)
return res; return res;
} }
unsigned long ConfigTag::getUInt(const std::string& key, unsigned long def, unsigned long min, unsigned long max) unsigned long ConfigTag::getUInt(const std::string& key, unsigned long def, unsigned long min, unsigned long max) const
{ {
std::string result; std::string result;
if (!readString(key, result)) if (!readString(key, result))
@ -632,7 +632,7 @@ unsigned long ConfigTag::getUInt(const std::string& key, unsigned long def, unsi
return res; return res;
} }
unsigned long ConfigTag::getDuration(const std::string& key, unsigned long def, unsigned long min, unsigned long max) unsigned long ConfigTag::getDuration(const std::string& key, unsigned long def, unsigned long min, unsigned long max) const
{ {
std::string duration; std::string duration;
if (!readString(key, duration)) if (!readString(key, duration))
@ -650,7 +650,7 @@ unsigned long ConfigTag::getDuration(const std::string& key, unsigned long def,
return ret; return ret;
} }
double ConfigTag::getFloat(const std::string& key, double def, double min, double max) double ConfigTag::getFloat(const std::string& key, double def, double min, double max) const
{ {
std::string result; std::string result;
if (!readString(key, result)) if (!readString(key, result))
@ -661,7 +661,7 @@ double ConfigTag::getFloat(const std::string& key, double def, double min, doubl
return res; return res;
} }
bool ConfigTag::getBool(const std::string &key, bool def) bool ConfigTag::getBool(const std::string& key, bool def) const
{ {
std::string result; std::string result;
if(!readString(key, result)) if(!readString(key, result))
@ -678,7 +678,7 @@ bool ConfigTag::getBool(const std::string &key, bool def)
return def; return def;
} }
std::string ConfigTag::getTagLocation() std::string ConfigTag::getTagLocation() const
{ {
return src_name + ":" + ConvToStr(src_line); return src_name + ":" + ConvToStr(src_line);
} }