Parse the string in Settings. Also added an another getter.

This commit is contained in:
Relintai 2022-01-06 18:49:42 +01:00
parent b8442280dd
commit 2db1a0693e
2 changed files with 13 additions and 3 deletions

View File

@ -3,7 +3,16 @@
#include <stdio.h>
#include <stdlib.h>
String Settings::get_value(const String &key, const String &def) {
Variant Settings::get_value(const String &key, const Variant &def) {
std::map<String, Variant>::iterator e = _data.find(key);
if (e != _data.end()) {
return e->second;
} else {
return def;
}
}
String Settings::get_value_string(const String &key, const String &def) {
std::map<String, Variant>::iterator e = _data.find(key);
if (e != _data.end()) {
@ -92,7 +101,7 @@ void Settings::parse_ini_file(const String &path) {
String k = s.substr_index(0, eindex - 1);
String v = s.substr_index(eindex + 1, s.size() - 1);
_data[k] = v;
_data[k] = Variant::parse_string(v);
}
}

View File

@ -8,7 +8,8 @@
class Settings {
public:
String get_value(const String &key, const String &def = "");
Variant get_value(const String &key, const Variant &def = Variant());
String get_value_string(const String &key, const String &def = "");
int get_value_int(const String &key, const int def = 0);
float get_value_float(const String &key, const float def = 0);
double get_value_double(const String &key, const double def = 0);