Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/core/ConfigValueContainer.h @ 447

Last change on this file since 447 was 447, checked in by landauf, 16 years ago
  • added comments and doxygen-tags to the ConfigValueContainer
  • changed some comments in the other files
File size: 5.6 KB
Line 
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#include "OgreVector3.h"
21#include "OgreColourValue.h"
22
23namespace orxonox
24{
25    //! The ConfigValuecontainer contains all needed informations about a configurable variable.
26    /**
27        The ConfigValueContainer class contains all needed informations about a configurable variable:
28         - the name of the variable
29         - the name of the class the variable belongs to
30         - the default value
31         - the user-specified value
32         - a pointer to the entry in the config-file
33
34        This is needed to assign the configured values to all newly created objects.
35
36        The container searches for the entry in the config file.
37        If there is an entry, it parses the specified value and assigns it to the variable of the right type.
38        If there is no entry, it adds the entry with the default-value to the section of the variables class.
39        If there is no section, the section and the entry are added to the end of the config-file.
40    */
41    class ConfigValueContainer
42    {
43        public:
44            ConfigValueContainer(const std::string& classname, const std::string& varname, int defvalue);
45            ConfigValueContainer(const std::string& classname, const std::string& varname, double defvalue);
46            ConfigValueContainer(const std::string& classname, const std::string& varname, bool defvalue);
47            ConfigValueContainer(const std::string& classname, const std::string& varname, const char* defvalue);
48            ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector3 defvalue);
49            ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::ColourValue defvalue);
50
51            void setDefaultValues(const std::string& classname, const std::string& varname);
52            void searchConfigFileLine();
53            std::string getValueString(bool bStripped = true);
54
55            static std::string getStrippedLine(const std::string& line);
56            static bool isEmpty(const std::string& line);
57            static bool isComment(const std::string& line);
58            static void readConfigFile(const std::string& filename);
59            static void writeConfigFile(const std::string& filename);
60
61            /** @returns the value of the type int. @param value This is only needed to determine the right type. */
62            inline int getValue(int value)                                      { return this->value_int_; }
63            /** @returns the value of the type double. @param value This is only needed to determine the right type. */
64            inline double getValue(double value)                                { return this->value_double_; }
65            /** @returns the value of the type bool. @param value This is only needed to determine the right type. */
66            inline bool getValue(bool value)                                    { return this->value_bool_; }
67            /** @returns the value of the type std::string. @param value This is only needed to determine the right type. */
68            inline std::string getValue(const std::string& value)               { return this->value_string_; }
69            /** @returns the value of the type Vector3. @param value This is only needed to determine the right type. */
70            inline Ogre::Vector3 getValue(const Ogre::Vector3& value)           { return this->value_vector3_; }
71            /** @returns the value of the type Colour£Value. @param value This is only needed to determine the right type. */
72            inline Ogre::ColourValue getValue(const Ogre::ColourValue& value)   { return this->value_colourvalue_; }
73
74        private:
75            std::string         classname_;                     //!< The name of the class the variable belongs to
76            std::string         varname_;                       //!< The name of the variable
77            std::string         defvalue_;                      //!< The string of the default-variable
78
79            int                 value_int_;                     //!< The value, if the variable is of the type int
80            double              value_double_;                  //!< The value, if the variable is of the type double
81            bool                value_bool_;                    //!< The value, if the variable is of the type bool
82            std::string         value_string_;                  //!< The value, if the variable is of the type string
83            Ogre::Vector3       value_vector3_;                 //!< The value, if the variable is of the type Vector3
84            Ogre::ColourValue   value_colourvalue_;             //!< The value, if the variable is of the type ColourValue
85
86            std::list<std::string>::iterator configFileLine_;   //!< An iterator, pointing to the entry of the variable in the config-file
87            static std::list<std::string>* configFileLines_s;   //!< A list, containing all entrys in the config-file
88            static bool readConfigFile_s;                       //!< True if the config-file is read and stored in the list
89    };
90}
91
92#endif
Note: See TracBrowser for help on using the repository browser.