1 | /*! |
---|
2 | @file ConfigValueContainer.h |
---|
3 | @brief Definition of the ConfigValueContainer class. |
---|
4 | |
---|
5 | The ConfigValueContainer class contains all needed informations about a configurable variable: |
---|
6 | - the name of the variable |
---|
7 | - the name of the class the variable belongs to |
---|
8 | - the default value |
---|
9 | - the user-specified value |
---|
10 | - a pointer to the entry in the config-file |
---|
11 | |
---|
12 | This is needed to assign the configured values to all newly created objects. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifndef _ConfigValueContainer_H__ |
---|
16 | #define _ConfigValueContainer_H__ |
---|
17 | |
---|
18 | #include <string> |
---|
19 | #include <list> |
---|
20 | |
---|
21 | #include "OgreVector2.h" |
---|
22 | #include "OgreVector3.h" |
---|
23 | #include "OgreColourValue.h" |
---|
24 | |
---|
25 | namespace orxonox |
---|
26 | { |
---|
27 | //! The ConfigValuecontainer contains all needed informations about a configurable variable. |
---|
28 | /** |
---|
29 | The ConfigValueContainer class contains all needed informations about a configurable variable: |
---|
30 | - the name of the variable |
---|
31 | - the name of the class the variable belongs to |
---|
32 | - the default value |
---|
33 | - the user-specified value |
---|
34 | - a pointer to the entry in the config-file |
---|
35 | |
---|
36 | This is needed to assign the configured values to all newly created objects. |
---|
37 | |
---|
38 | The container searches for the entry in the config file. |
---|
39 | If there is an entry, it parses the specified value and assigns it to the variable of the right type. |
---|
40 | If there is no entry, it adds the entry with the default-value to the section of the variables class. |
---|
41 | If there is no section, the section and the entry are added to the end of the config-file. |
---|
42 | */ |
---|
43 | class ConfigValueContainer |
---|
44 | { |
---|
45 | public: |
---|
46 | ConfigValueContainer(const std::string& classname, const std::string& varname, int defvalue); |
---|
47 | ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned int defvalue); |
---|
48 | ConfigValueContainer(const std::string& classname, const std::string& varname, char defvalue); |
---|
49 | ConfigValueContainer(const std::string& classname, const std::string& varname, unsigned char defvalue); |
---|
50 | ConfigValueContainer(const std::string& classname, const std::string& varname, float defvalue); |
---|
51 | ConfigValueContainer(const std::string& classname, const std::string& varname, double defvalue); |
---|
52 | ConfigValueContainer(const std::string& classname, const std::string& varname, bool defvalue); |
---|
53 | ConfigValueContainer(const std::string& classname, const std::string& varname, const std::string& defvalue); |
---|
54 | ConfigValueContainer(const std::string& classname, const std::string& varname, const char* defvalue); |
---|
55 | ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector2 defvalue); |
---|
56 | ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector3 defvalue); |
---|
57 | ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::ColourValue defvalue); |
---|
58 | |
---|
59 | void setConfigFileEntyToDefault(); |
---|
60 | void searchConfigFileLine(); |
---|
61 | std::string parseValueString(bool bStripped = true); |
---|
62 | |
---|
63 | static std::string getStrippedLine(const std::string& line); |
---|
64 | static bool isEmpty(const std::string& line); |
---|
65 | static bool isComment(const std::string& line); |
---|
66 | static void readConfigFile(const std::string& filename); |
---|
67 | static void writeConfigFile(const std::string& filename); |
---|
68 | |
---|
69 | /** @returns the value. @param value This is only needed to determine the right type. */ |
---|
70 | inline int getValue(int value) { return this->value_.value_int_; } |
---|
71 | /** @returns the value. @param value This is only needed to determine the right type. */ |
---|
72 | inline unsigned int getValue(unsigned int value) { return this->value_.value_uint_; } |
---|
73 | /** @returns the value. @param value This is only needed to determine the right type. */ |
---|
74 | inline char getValue(char value) { return this->value_.value_char_; } |
---|
75 | /** @returns the value. @param value This is only needed to determine the right type. */ |
---|
76 | inline unsigned char getValue(unsigned char value) { return this->value_.value_uchar_; } |
---|
77 | /** @returns the value. @param value This is only needed to determine the right type. */ |
---|
78 | inline float getValue(float value) { return this->value_.value_float_; } |
---|
79 | /** @returns the value. @param value This is only needed to determine the right type. */ |
---|
80 | inline double getValue(double value) { return this->value_.value_double_; } |
---|
81 | /** @returns the value. @param value This is only needed to determine the right type. */ |
---|
82 | inline bool getValue(bool value) { return this->value_.value_bool_; } |
---|
83 | /** @returns the value. @param value This is only needed to determine the right type. */ |
---|
84 | inline const std::string& getValue(const std::string& value) { return this->value_string_; } |
---|
85 | /** @returns the value. @param value This is only needed to determine the right type. */ |
---|
86 | inline const char* getValue(const char* value) { return this->value_string_.c_str(); } |
---|
87 | /** @returns the value. @param value This is only needed to determine the right type. */ |
---|
88 | inline Ogre::Vector2 getValue(const Ogre::Vector2& value) { return this->value_vector2_; } |
---|
89 | /** @returns the value. @param value This is only needed to determine the right type. */ |
---|
90 | inline Ogre::Vector3 getValue(const Ogre::Vector3& value) { return this->value_vector3_; } |
---|
91 | /** @returns the value. @param value This is only needed to determine the right type. */ |
---|
92 | inline Ogre::ColourValue getValue(const Ogre::ColourValue& value) { return this->value_colourvalue_; } |
---|
93 | |
---|
94 | private: |
---|
95 | std::string classname_; //!< The name of the class the variable belongs to |
---|
96 | std::string varname_; //!< The name of the variable |
---|
97 | std::string defvalueString_; //!< The string of the default-variable |
---|
98 | |
---|
99 | union MultiType |
---|
100 | { |
---|
101 | int value_int_; //!< The value, if the variable is of the type int |
---|
102 | unsigned int value_uint_; //!< The value, if the variable is of the type unsigned int |
---|
103 | char value_char_; //!< The value, if the variable is of the type char |
---|
104 | unsigned char value_uchar_; //!< The value, if the variable is of the type unsigned char |
---|
105 | float value_float_; //!< The value, if the variable is of the type float |
---|
106 | double value_double_; //!< The value, if the variable is of the type double |
---|
107 | bool value_bool_; //!< The value, if the variable is of the type bool |
---|
108 | } value_; //!< The value of the variable |
---|
109 | |
---|
110 | std::string value_string_; //!< The value, if the variable is of the type string |
---|
111 | Ogre::Vector2 value_vector2_; //!< The value, if the variable is of the type Vector2 |
---|
112 | Ogre::Vector3 value_vector3_; //!< The value, if the variable is of the type Vector3 |
---|
113 | Ogre::ColourValue value_colourvalue_; //!< The value, if the variable is of the type ColourValue |
---|
114 | |
---|
115 | std::list<std::string>::iterator configFileLine_; //!< An iterator, pointing to the entry of the variable in the config-file |
---|
116 | static std::list<std::string>* configFileLines_s; //!< A list, containing all entrys in the config-file |
---|
117 | static bool readConfigFile_s; //!< True if the config-file is read and stored in the list |
---|
118 | |
---|
119 | enum VariableType |
---|
120 | { |
---|
121 | Int, |
---|
122 | uInt, |
---|
123 | Char, |
---|
124 | uChar, |
---|
125 | Float, |
---|
126 | Double, |
---|
127 | Bool, |
---|
128 | ConstChar, |
---|
129 | String, |
---|
130 | Vector2, |
---|
131 | Vector3, |
---|
132 | ColourValue |
---|
133 | } type_; //!< The type of the variable |
---|
134 | }; |
---|
135 | } |
---|
136 | |
---|
137 | #endif |
---|