bool Settings::checkNameValid(const std::string &name)
{
bool valid = name.find_first_of("=\"{}#") == std::string::npos;
- if (valid) valid = trim(name) == name;
+ if (valid)
+ valid = std::find_if(name.begin(), name.end(), ::isspace) == name.end();
+
if (!valid) {
errorstream << "Invalid setting name \"" << name << "\""
<< std::endl;
{
MutexAutoLock lock(m_mutex);
- for (SettingEntries::const_iterator it = m_settings.begin();
- it != m_settings.end(); ++it)
- printEntry(os, it->first, it->second, tab_depth);
+ for (const auto &setting_it : m_settings)
+ printEntry(os, setting_it.first, setting_it.second, tab_depth);
}
case SPE_KVPAIR:
it = m_settings.find(name);
if (it != m_settings.end() &&
- (it->second.is_group || it->second.value != value)) {
+ (it->second.is_group || it->second.value != value)) {
printEntry(os, name, it->second, tab_depth);
was_modified = true;
+ } else if (it == m_settings.end()) {
+ // Remove by skipping
+ was_modified = true;
+ break;
} else {
os << line << "\n";
if (event == SPE_MULTILINE)
sanity_check(it->second.group != NULL);
was_modified |= it->second.group->updateConfigObject(is, os,
"}", tab_depth + 1);
+ } else if (it == m_settings.end()) {
+ // Remove by skipping
+ was_modified = true;
+ Settings removed_group; // Move 'is' to group end
+ std::stringstream ss;
+ removed_group.updateConfigObject(is, ss, "}", tab_depth + 1);
+ break;
} else {
printEntry(os, name, it->second, tab_depth);
was_modified = true;
ValueType type = n->second.type;
- std::string value = "";
+ std::string value;
if (type == VALUETYPE_FLAG) {
value = "true";
}
+const SettingsEntry &Settings::getEntryDefault(const std::string &name) const
+{
+ MutexAutoLock lock(m_mutex);
+
+ SettingEntries::const_iterator n;
+ if ((n = m_defaults.find(name)) == m_defaults.end()) {
+ throw SettingNotFoundException("Setting [" + name + "] not found.");
+ }
+ return n->second;
+}
+
+
Settings *Settings::getGroup(const std::string &name) const
{
const SettingsEntry &entry = getEntry(name);
}
+const std::string &Settings::getDefault(const std::string &name) const
+{
+ const SettingsEntry &entry = getEntryDefault(name);
+ if (entry.is_group)
+ throw SettingNotFoundException("Setting [" + name + "] is a group.");
+ return entry.value;
+}
+
+
bool Settings::getBool(const std::string &name) const
{
return is_yes(get(name));
}
+u32 Settings::getU32(const std::string &name) const
+{
+ return (u32) stoi(get(name));
+}
+
s32 Settings::getS32(const std::string &name) const
{
return stoi(get(name));
np.persist = stof(f.next(","));
std::string optional_params = f.next("");
- if (optional_params != "")
+ if (!optional_params.empty())
np.lacunarity = stof(optional_params);
return true;
std::vector<std::string> Settings::getNames() const
{
std::vector<std::string> names;
- for (SettingEntries::const_iterator i = m_settings.begin();
- i != m_settings.end(); ++i) {
- names.push_back(i->first);
+ for (const auto &settings_it : m_settings) {
+ names.push_back(settings_it.first);
}
return names;
}
}
+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
{
try {
}
+bool Settings::getDefaultNoEx(const std::string &name, std::string &val) const
+{
+ try {
+ val = getDefault(name);
+ return true;
+ } catch (SettingNotFoundException &e) {
+ return false;
+ }
+}
+
+
bool Settings::getFlag(const std::string &name) const
{
try {
if (it != m_settings.end()) {
delete it->second.group;
m_settings.erase(it);
+
+ doCallbacks(name);
return true;
- } else {
- return false;
}
+
+ return false;
}
MutexAutoLock lock(m_mutex);
try {
- std::string val = other.get(name);
- m_settings[name] = val;
+ m_settings[name] = other.get(name);
} catch (SettingNotFoundException &e) {
}
}
SettingsChangedCallback cbf, void *userdata)
{
MutexAutoLock lock(m_callback_mutex);
- m_callbacks[name].push_back(std::make_pair(cbf, userdata));
+ m_callbacks[name].emplace_back(cbf, userdata);
}
void Settings::deregisterChangedCallback(const std::string &name,