2010-04-05 23:38:59 +02:00
|
|
|
#ifndef _VARIABLESGLOBAL_H
|
|
|
|
#define _VARIABLESGLOBAL_H
|
|
|
|
|
|
|
|
namespace Engine {
|
|
|
|
/** \brief Represents a variable that can be modified and read within the game
|
|
|
|
*
|
|
|
|
* \note Variables \b MUST be declared as static variables, otherwise the memory that
|
|
|
|
* hold their values get invalidated and the system gets unstable!
|
|
|
|
*/
|
|
|
|
class Variable {
|
|
|
|
public:
|
|
|
|
/** \brief The constructor to be used when initializing a Variable
|
|
|
|
*
|
|
|
|
* \param name The name under which the variable is engine wide
|
|
|
|
* accessible
|
|
|
|
* \param value The value it is assigned to.
|
|
|
|
*
|
|
|
|
* The value string gets automatically converted to a float with atof ().
|
|
|
|
* Modification of a Variable must always be made with the Get*, Set*
|
|
|
|
* functions.
|
|
|
|
*/
|
|
|
|
Variable (const std::string &name, const std::string &value);
|
|
|
|
|
2011-03-27 22:38:26 +02:00
|
|
|
/** \brief Parses and sets the corresponding value */
|
|
|
|
void Set (const std::string &value);
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
/** \brief Returns the string value of the Variable */
|
|
|
|
std::string& GetStringValue () {
|
|
|
|
return mStringValue;
|
|
|
|
}
|
|
|
|
/** \brief Returns the float value of the Variable */
|
|
|
|
float& GetFloatValue () {
|
|
|
|
return mFloatValue;
|
|
|
|
}
|
2011-03-16 17:03:41 +01:00
|
|
|
/** \brief Returns the float value of the Variable */
|
|
|
|
bool& GetBoolValue () {
|
|
|
|
return mBoolValue;
|
|
|
|
}
|
2010-04-05 23:38:59 +02:00
|
|
|
void SetStringValue (const std::string &value) {
|
|
|
|
mStringValue = value;
|
|
|
|
}
|
|
|
|
void SetFloatValue (float value) {
|
|
|
|
mFloatValue = value;
|
|
|
|
}
|
2011-03-16 17:03:41 +01:00
|
|
|
void SetBoolValue (bool value) {
|
|
|
|
mBoolValue = value;
|
|
|
|
}
|
|
|
|
void SetBoolValueFromString (std::string str_value) {
|
|
|
|
mBoolValue = ParseBoolValue (str_value);
|
|
|
|
}
|
2010-04-05 23:38:59 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
/** \brief The default constructor must not be used.
|
|
|
|
*
|
|
|
|
* Use \code
|
|
|
|
* Variable (const std::string &name, const std::string &value)
|
|
|
|
* \endcode
|
|
|
|
* instead.
|
|
|
|
* */
|
|
|
|
Variable () { assert (0); }
|
|
|
|
/** \brief Registeres this Variable with the Variables System */
|
|
|
|
void RegisterVariable (const std::string &name);
|
|
|
|
|
2011-03-16 17:03:41 +01:00
|
|
|
/** \brief Parses the input value and checks whether it resembles true or not
|
|
|
|
*
|
|
|
|
* Valid true expressions are:
|
|
|
|
* - any float values that are unequal to zero
|
|
|
|
* - true (case insensitive)
|
|
|
|
* - yes (case insensitive)
|
|
|
|
*
|
|
|
|
* \returns true if value contains a value that qualifies as a valid "true" expression
|
|
|
|
*/
|
|
|
|
bool ParseBoolValue (std::string value);
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
std::string mName;
|
|
|
|
std::string mStringValue;
|
|
|
|
float mFloatValue;
|
2011-03-16 17:03:41 +01:00
|
|
|
bool mBoolValue;
|
2010-04-05 23:38:59 +02:00
|
|
|
|
|
|
|
friend class Variables;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** \brief Provides access to a Variable stored under the given name */
|
|
|
|
Variable* GetVariable (const std::string &name);
|
|
|
|
/** \brief Sets the vaule of the Variable */
|
|
|
|
bool SetVariableValue (const std::string &name, const std::string &value);
|
|
|
|
/** \brief Returns the string value of the Variable with the given name */
|
|
|
|
std::string& GetVariableString (const std::string &name, std::string def = "");
|
|
|
|
/** \brief Returns the float value of the Variable with the given name */
|
|
|
|
float& GetVariableFloat (const std::string &name, float def = 0.);
|
2011-03-16 17:03:41 +01:00
|
|
|
/** \brief Returns the boolean value of the Variable with the given name */
|
|
|
|
bool& GetVariableBool (const std::string &name, bool def = false);
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
#endif // _VARIABLESGLOBAL_H
|