diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-08-10 18:02:30 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-08-10 18:06:01 -0600 |
commit | 96187972ff9ac50a2a7fa280abbb21bd3c7f0737 (patch) | |
tree | 3a0385dcd57e437b25e1242109ce7f2c6c16396b /src/event.cpp | |
parent | fa2cf9bea837e17d08218d0070a60905adec268f (diff) | |
download | mana-96187972ff9ac50a2a7fa280abbb21bd3c7f0737.tar.gz mana-96187972ff9ac50a2a7fa280abbb21bd3c7f0737.tar.bz2 mana-96187972ff9ac50a2a7fa280abbb21bd3c7f0737.tar.xz mana-96187972ff9ac50a2a7fa280abbb21bd3c7f0737.zip |
Add some new methods to the Event class
Adds get methods with default values, and has methods that return true if
the variable exists.
Reviewed-by: Chuck Miller
Diffstat (limited to 'src/event.cpp')
-rw-r--r-- | src/event.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/event.cpp b/src/event.cpp index d503ad58..a2f233ac 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -55,6 +55,13 @@ int Event::getInt(const std::string &key) const throw (BadEvent) return static_cast<IntData *>(it->second)->getData(); } +bool Event::hasInt(const std::string &key) +{ + VariableMap::const_iterator it = mData.find(key); + return !(it == mData.end() + || it->second->getType() != VariableData::DATA_INT); +} + void Event::setString(const std::string &key, const std::string &value) throw (BadEvent) { if (mData.find(key) != mData.end()) @@ -76,6 +83,13 @@ const std::string &Event::getString(const std::string &key) const throw (BadEven } +bool Event::hasString(const std::string &key) +{ + VariableMap::const_iterator it = mData.find(key); + return !(it == mData.end() + || it->second->getType() != VariableData::DATA_STRING); +} + void Event::setFloat(const std::string &key, double value) throw (BadEvent) { if (mData.find(key) != mData.end()) @@ -96,6 +110,13 @@ double Event::getFloat(const std::string &key) const throw (BadEvent) return static_cast<FloatData *>(it->second)->getData(); } +bool Event::hasFloat(const std::string &key) +{ + VariableMap::const_iterator it = mData.find(key); + return !(it == mData.end() + || it->second->getType() != VariableData::DATA_FLOAT); +} + void Event::setBool(const std::string &key, bool value) throw (BadEvent) { if (mData.find(key) != mData.end()) @@ -116,4 +137,11 @@ bool Event::getBool(const std::string &key) const throw (BadEvent) return static_cast<BoolData *>(it->second)->getData(); } +bool Event::hasBool(const std::string &key) +{ + VariableMap::const_iterator it = mData.find(key); + return !(it == mData.end() + || it->second->getType() != VariableData::DATA_BOOL); +} + } // namespace Mana |