|
From: rainbyte <rai...@us...> - 2012-07-17 10:43:58
|
Author: Tapio Vierros <tap...@gm...>
Date: Thu Dec 15 18:54:08 2011 +0200
Added a function to dynamically add enums to a ConfigItem.
---
game/configuration.cc | 8 ++++++++
game/configuration.hh | 1 +
2 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/game/configuration.cc b/game/configuration.cc
index 3f6144d..de92d67 100644
--- a/game/configuration.cc
+++ b/game/configuration.cc
@@ -144,6 +144,14 @@ namespace {
}
}
+void ConfigItem::addEnum(std::string name) {
+ verifyType("int");
+ m_enums.push_back(name);
+ m_min = 0;
+ m_max = int(m_enums.size() - 1);
+ m_step = 1;
+}
+
template <typename T> void ConfigItem::updateNumeric(xmlpp::Element& elem, int mode) {
xmlpp::NodeSet ns = elem.find("limits");
if (!ns.empty()) setLimits<T>(dynamic_cast<xmlpp::Element&>(*ns[0]), m_min, m_max, m_step);
diff --git a/game/configuration.hh b/game/configuration.hh
index 82f2e6e..93278f8 100644
--- a/game/configuration.hh
+++ b/game/configuration.hh
@@ -37,6 +37,7 @@ class ConfigItem {
std::string getValue() const; ///< Get a human-readable representation of the current value
std::string const& getShortDesc() const { return m_shortDesc; } ///< get the short description for this ConfigItem
std::string const& getLongDesc() const { return m_longDesc; } ///< get the long description for this ConfigItem
+ void addEnum(std::string name); ///< Dynamically adds an enum to all values
private:
template <typename T> void updateNumeric(xmlpp::Element& elem, int mode); ///< Used internally for loading XML
|