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.h | |
parent | fa2cf9bea837e17d08218d0070a60905adec268f (diff) | |
download | mana-client-96187972ff9ac50a2a7fa280abbb21bd3c7f0737.tar.gz mana-client-96187972ff9ac50a2a7fa280abbb21bd3c7f0737.tar.bz2 mana-client-96187972ff9ac50a2a7fa280abbb21bd3c7f0737.tar.xz mana-client-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.h')
-rw-r--r-- | src/event.h | 91 |
1 files changed, 84 insertions, 7 deletions
diff --git a/src/event.h b/src/event.h index 1e057a05..7acd2190 100644 --- a/src/event.h +++ b/src/event.h @@ -40,33 +40,110 @@ typedef std::map<std::string, VariableData *> VariableMap; class Event { public: - // String passed can be retivered with getName() - // and is to used to identify what type of event - // this is. + /** + * Makes an event with the given name. + */ Event(const std::string &name) { mEventName = name; } ~Event(); + /** + * Returns the name of the event. + */ const std::string &getName() const { return mEventName; } - // Sets or gets a interger with a key to identify + /** + * Sets the given variable to the given integer, if it isn't already set. + */ void setInt(const std::string &key, int value) throw (BadEvent); + + /** + * Returns the given variable if it is set and an integer. + */ int getInt(const std::string &key) const throw (BadEvent); - // Sets or gets a string with a key to identify + /** + * Returns the given variable if it is set and an integer, returning the + * given default otherwise. + */ + inline int getInt(const std::string &key, int defaultValue) const + { try { return getInt(key); } catch (BadEvent) { return defaultValue; }} + + /** + * Returns true if the given variable exists and is an integer. + */ + bool hasInt(const std::string &key); + + /** + * Sets the given variable to the given string, if it isn't already set. + */ void setString(const std::string &key, const std::string &value) throw (BadEvent); + + /** + * Returns the given variable if it is set and a string. + */ const std::string &getString(const std::string &key) const throw (BadEvent); - // Sets or gets a floating point number with key to identify + /** + * Returns the given variable if it is set and a string, returning the + * given default otherwise. + */ + inline const std::string &getString(const std::string &key, + const std::string &defaultValue) const + { try { return getString(key); } catch (BadEvent) { return defaultValue; }} + + /** + * Returns true if the given variable exists and is a string. + */ + bool hasString(const std::string &key); + + /** + * Sets the given variable to the given floating-point, if it isn't already + * set. + */ void setFloat(const std::string &key, double value) throw (BadEvent); + + /** + * Returns the given variable if it is set and a floating-point. + */ double getFloat(const std::string &key) const throw (BadEvent); - // Sets or gets a boolean with key to identify + /** + * Returns the given variable if it is set and a floating-point, returning + * the given default otherwise. + */ + inline double getFloat(const std::string &key, float defaultValue) const + { try { return getFloat(key); } catch (BadEvent) { return defaultValue; }} + + /** + * Returns true if the given variable exists and is a floating-point. + */ + bool hasFloat(const std::string &key); + + /** + * Sets the given variable to the given boolean, if it isn't already set. + */ void setBool(const std::string &key, bool value) throw (BadEvent); + + /** + * Returns the given variable if it is set and a boolean. + */ bool getBool(const std::string &key) const throw (BadEvent); + /** + * Returns the given variable if it is set and a boolean, returning the + * given default otherwise. + */ + inline bool getBool(const std::string &key, bool defaultValue) const + { try { return getBool(key); } catch (BadEvent) { return defaultValue; }} + + /** + * Returns true if the given variable exists and is a boolean. + */ + bool hasBool(const std::string &key); + private: std::string mEventName; |