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, double defvalue); |
---|
48 | ConfigValueContainer(const std::string& classname, const std::string& varname, bool defvalue); |
---|
49 | ConfigValueContainer(const std::string& classname, const std::string& varname, const char* defvalue); |
---|
50 | ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector2 defvalue); |
---|
51 | ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector3 defvalue); |
---|
52 | ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::ColourValue defvalue); |
---|
53 | |
---|
54 | void setDefaultValues(const std::string& classname, const std::string& varname); |
---|
55 | void searchConfigFileLine(); |
---|
56 | std::string getValueString(bool bStripped = true); |
---|
57 | |
---|
58 | static std::string getStrippedLine(const std::string& line); |
---|
59 | static bool isEmpty(const std::string& line); |
---|
60 | static bool isComment(const std::string& line); |
---|
61 | static void readConfigFile(const std::string& filename); |
---|
62 | static void writeConfigFile(const std::string& filename); |
---|
63 | |
---|
64 | /** @returns the value of the type int. @param value This is only needed to determine the right type. */ |
---|
65 | inline int getValue(int value) { return this->value_.value_int_; } |
---|
66 | /** @returns the value of the type double. @param value This is only needed to determine the right type. */ |
---|
67 | inline double getValue(double value) { return this->value_.value_double_; } |
---|
68 | /** @returns the value of the type bool. @param value This is only needed to determine the right type. */ |
---|
69 | inline bool getValue(bool value) { return this->value_.value_bool_; } |
---|
70 | /** @returns the value of the type std::string. @param value This is only needed to determine the right type. */ |
---|
71 | inline std::string getValue(const std::string& value) { return this->value_string_; } |
---|
72 | /** @returns the value of the type Vector2. @param value This is only needed to determine the right type. */ |
---|
73 | inline Ogre::Vector2 getValue(const Ogre::Vector2& value) { return this->value_vector2_; } |
---|
74 | /** @returns the value of the type Vector3. @param value This is only needed to determine the right type. */ |
---|
75 | inline Ogre::Vector3 getValue(const Ogre::Vector3& value) { return this->value_vector3_; } |
---|
76 | /** @returns the value of the type Colour£Value. @param value This is only needed to determine the right type. */ |
---|
77 | inline Ogre::ColourValue getValue(const Ogre::ColourValue& value) { return this->value_colourvalue_; } |
---|
78 | |
---|
79 | private: |
---|
80 | std::string classname_; //!< The name of the class the variable belongs to |
---|
81 | std::string varname_; //!< The name of the variable |
---|
82 | std::string defvalue_; //!< The string of the default-variable |
---|
83 | |
---|
84 | union MultiType |
---|
85 | { |
---|
86 | int value_int_; //!< The value, if the variable is of the type int |
---|
87 | double value_double_; //!< The value, if the variable is of the type double |
---|
88 | bool value_bool_; //!< The value, if the variable is of the type bool |
---|
89 | } value_; |
---|
90 | |
---|
91 | std::string value_string_; //!< The value, if the variable is of the type string |
---|
92 | Ogre::Vector2 value_vector2_; //!< The value, if the variable is of the type Vector2 |
---|
93 | Ogre::Vector3 value_vector3_; //!< The value, if the variable is of the type Vector3 |
---|
94 | Ogre::ColourValue value_colourvalue_; //!< The value, if the variable is of the type ColourValue |
---|
95 | |
---|
96 | std::list<std::string>::iterator configFileLine_; //!< An iterator, pointing to the entry of the variable in the config-file |
---|
97 | static std::list<std::string>* configFileLines_s; //!< A list, containing all entrys in the config-file |
---|
98 | static bool readConfigFile_s; //!< True if the config-file is read and stored in the list |
---|
99 | }; |
---|
100 | } |
---|
101 | |
---|
102 | #endif |
---|