aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2014-02-03 22:40:57 -0500
committerkwolekr <kwolekr@minetest.net>2014-02-03 22:47:40 -0500
commita439343844cf821e4922e23f1638b92e2cfb14ac (patch)
treeeab79a9c799fee31767764c8732e2adcb48478af /src
parent458045d49fd96cf19bdd61b2f8dbdbc0fd11b587 (diff)
downloadminetest-a439343844cf821e4922e23f1638b92e2cfb14ac.tar.gz
minetest-a439343844cf821e4922e23f1638b92e2cfb14ac.tar.bz2
minetest-a439343844cf821e4922e23f1638b92e2cfb14ac.zip
Settings: Add no-exception variants of each get method
Diffstat (limited to 'src')
-rw-r--r--src/settings.h127
1 files changed, 123 insertions, 4 deletions
diff --git a/src/settings.h b/src/settings.h
index e19f83e3f..f019ce50c 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -467,6 +467,7 @@ public:
return n->second;
}
+ //////////// Get setting
bool getBool(std::string name)
{
return is_yes(get(name));
@@ -581,13 +582,19 @@ public:
{
size_t len = olen;
std::vector<std::string *> strs_alloced;
- std::string *str;
- std::string valstr = get(name);
+ std::string *str, valstr;
+ char *f, *snext;
+ size_t pos;
+
+ try {
+ valstr = get(name);
+ } catch (SettingNotFoundException &e) {
+ return false;
+ }
+
char *s = &valstr[0];
char *buf = new char[len];
char *bufpos = buf;
- char *f, *snext;
- size_t pos;
char *fmtpos, *fmt = &format[0];
while ((f = strtok_r(fmt, ",", &fmtpos)) && s) {
@@ -737,6 +744,118 @@ fail:
return true;
}
+ //////////// Try to get value, no exception thrown
+ bool tryGet(std::string name, std::string &val)
+ {
+ try {
+ val = get(name);
+ return true;
+ } catch (SettingNotFoundException &e) {
+ return false;
+ }
+ }
+
+ bool tryGetFlagStr(std::string name, u32 &val, FlagDesc *flagdesc)
+ {
+ try {
+ val = getFlagStr(name, flagdesc);
+ return true;
+ } catch (SettingNotFoundException &e) {
+ return false;
+ }
+ }
+
+ bool tryGetFloat(std::string name, float &val)
+ {
+ try {
+ val = getFloat(name);
+ return true;
+ } catch (SettingNotFoundException &e) {
+ return false;
+ }
+ }
+
+ bool tryGetU16(std::string name, int &val)
+ {
+ try {
+ val = getU16(name);
+ return true;
+ } catch (SettingNotFoundException &e) {
+ return false;
+ }
+ }
+
+ bool tryGetU16(std::string name, u16 &val)
+ {
+ try {
+ val = getU16(name);
+ return true;
+ } catch (SettingNotFoundException &e) {
+ return false;
+ }
+ }
+
+ bool tryGetS16(std::string name, int &val)
+ {
+ try {
+ val = getU16(name);
+ return true;
+ } catch (SettingNotFoundException &e) {
+ return false;
+ }
+ }
+
+ bool tryGetS16(std::string name, s16 &val)
+ {
+ try {
+ val = getS16(name);
+ return true;
+ } catch (SettingNotFoundException &e) {
+ return false;
+ }
+ }
+
+ bool tryGetS32(std::string name, s32 &val)
+ {
+ try {
+ val = getS32(name);
+ return true;
+ } catch (SettingNotFoundException &e) {
+ return false;
+ }
+ }
+
+ bool tryGetV3F(std::string name, v3f &val)
+ {
+ try {
+ val = getV3F(name);
+ return true;
+ } catch (SettingNotFoundException &e) {
+ return false;
+ }
+ }
+
+ bool tryGetV2F(std::string name, v2f &val)
+ {
+ try {
+ val = getV2F(name);
+ return true;
+ } catch (SettingNotFoundException &e) {
+ return false;
+ }
+ }
+
+ bool tryGetU64(std::string name, u64 &val)
+ {
+ try {
+ val = getU64(name);
+ return true;
+ } catch (SettingNotFoundException &e) {
+ return false;
+ }
+ }
+
+ //////////// Set setting
bool setStruct(std::string name, std::string format, void *value)
{
char sbuf[2048];