summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/xml.cpp17
-rw-r--r--src/utils/xml.h6
2 files changed, 23 insertions, 0 deletions
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index 140da72df..f7350ce92 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -122,6 +122,23 @@ namespace XML
return ret;
}
+ int getIntProperty(XmlNodePtr node, const char* name, int def, int min, int max)
+ {
+ int &ret = def;
+
+ xmlChar *prop = xmlGetProp(node, BAD_CAST name);
+ if (prop)
+ {
+ ret = atoi(reinterpret_cast<char*>(prop));
+ xmlFree(prop);
+ }
+ if (ret < min)
+ ret = min;
+ else if (ret > max)
+ ret = max;
+ return ret;
+ }
+
double getFloatProperty(XmlNodePtr node, const char* name, double def)
{
double &ret = def;
diff --git a/src/utils/xml.h b/src/utils/xml.h
index eb5ee88b0..a4ff7eb2e 100644
--- a/src/utils/xml.h
+++ b/src/utils/xml.h
@@ -86,6 +86,12 @@ namespace XML
int getProperty(XmlNodePtr node, const char *name, int def);
/**
+ * Gets an integer property from an XmlNodePtr.
+ */
+ int getIntProperty(XmlNodePtr node, const char* name, int def,
+ int min, int max);
+
+ /**
* Gets a string property from an XmlNodePtr.
*/
std::string getProperty(XmlNodePtr node, const char *name,