summaryrefslogtreecommitdiff
path: root/src/properties.h
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-10-07 14:57:15 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-10-07 14:57:15 +0000
commite4530c6d0cd180ab18469bf8e32fb978229dedde (patch)
tree218175c6d472315e59c988b168a25b7452cc3b00 /src/properties.h
parent7b9a9c55d6e73ba9151042e27ad4bc330d11617f (diff)
downloadmana-e4530c6d0cd180ab18469bf8e32fb978229dedde.tar.gz
mana-e4530c6d0cd180ab18469bf8e32fb978229dedde.tar.bz2
mana-e4530c6d0cd180ab18469bf8e32fb978229dedde.tar.xz
mana-e4530c6d0cd180ab18469bf8e32fb978229dedde.zip
Added support for gzip compressed map layer data. Increased version to 0.0.22.
Cleaned up overlay initialization a bit.
Diffstat (limited to 'src/properties.h')
-rw-r--r--src/properties.h29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/properties.h b/src/properties.h
index 92690cd3..56e90c0e 100644
--- a/src/properties.h
+++ b/src/properties.h
@@ -26,6 +26,7 @@
#include <map>
#include <string>
+#include <sstream>
/**
* A class holding a set of properties.
@@ -39,16 +40,36 @@ class Properties
/**
* Get a map property.
*
- * @return the value of the given property or an empty string when it
+ * @param def default value, empty string by default
+ * @return the value of the given property or the given default when it
* doesn't exist.
*/
const std::string&
- getProperty(const std::string &name)
+ getProperty(const std::string &name, const std::string &def = "")
{
- const static std::string undefined = "";
PropertyMap::const_iterator i = mProperties.find(name);
+ return (i != mProperties.end()) ? i->second : def;
+ }
- return (i != mProperties.end()) ? i->second : undefined;
+ /**
+ * Gets a map property as a float.
+ *
+ * @param def default value, 0.0f by default
+ * @return the value of the given property, or 0.0f when it doesn't
+ * exist.
+ */
+ const float
+ getFloatProperty(const std::string &name, float def = 0.0f)
+ {
+ PropertyMap::const_iterator i = mProperties.find(name);
+ float ret = def;
+ if (i != mProperties.end())
+ {
+ std::stringstream ss;
+ ss.str(i->second);
+ ss >> ret;
+ }
+ return ret;
}
/**