fysxasteroids/engine/VariablesGlobal.h

69 lines
2.1 KiB
C++

#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);
/** \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;
}
void SetStringValue (const std::string &value) {
mStringValue = value;
}
void SetFloatValue (float value) {
mFloatValue = value;
}
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);
std::string mName;
std::string mStringValue;
float mFloatValue;
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.);
}
#endif // _VARIABLESGLOBAL_H