Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/core/ConfigValueContainer.h @ 708

Last change on this file since 708 was 708, checked in by rgrieder, 16 years ago
  • added Vector2, Vector3, Matrix3, ColourValue, Quaternion and String to the misc folder as header files (each of them contains #include <string> … typedef std::string String , etc.)
  • please use String from now on by including <misc/String.h"
  • removed #include <OgreVector3.h", etc. from "CoreIncludes.h" (adjusted all source files)
  • adjusted all the source files (except network, that keeps <string> for the moment) (what a mess..)
  • moved usleep hack to misc/Sleep.h
  • relative include paths for files from other root directories (like misc, network, etc.) (but it stills writes "../Orxonox.h" when in folder orxonox/objects)
  • "OgreSceneManager.h" —> <OgreSceneManager.h>
  • included OrxonoxPrereqs in every file in folder orxonox
  • moved HUD and ParticleInterface to namespace orxonox
  • removed some using namespace Ogre/std when appropriate
  • I hope I haven't forgotten important points..
File size: 11.4 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28/*!
29    @file ConfigValueContainer.h
30    @brief Definition of the ConfigValueContainer class.
31
32    The ConfigValueContainer class contains all needed informations about a configurable variable:
33     - the name of the variable
34     - the name of the class the variable belongs to
35     - the default value
36     - the user-specified value
37     - a pointer to the entry in the config-file
38
39    This is needed to assign the configured values to all newly created objects.
40*/
41
42#ifndef _ConfigValueContainer_H__
43#define _ConfigValueContainer_H__
44
45#include <list>
46
47#include "CorePrereqs.h"
48
49#include "misc/Vector2.h"
50#include "misc/Vector3.h"
51#include "misc/Matrix3.h"
52#include "misc/Quaternion.h"
53#include "misc/String.h"
54#include "misc/ColourValue.h"
55#include "Language.h"
56
57namespace orxonox
58{
59    //! The ConfigValuecontainer contains all needed informations about a configurable variable.
60    /**
61        The ConfigValueContainer class contains all needed informations about a configurable variable:
62         - the name of the variable
63         - the name of the class the variable belongs to
64         - the default value
65         - the user-specified value
66         - a pointer to the entry in the config-file
67
68        This is needed to assign the configured values to all newly created objects.
69
70        The container searches for the entry in the config file.
71        If there is an entry, it parses the specified value and assigns it to the variable of the right type.
72        If there is no entry, it adds the entry with the default-value to the section of the variables class.
73        If there is no section, the section and the entry are added to the end of the config-file.
74    */
75    class _CoreExport ConfigValueContainer
76    {
77        public:
78            enum VariableType
79            {
80                Int,
81                uInt,
82                Char,
83                uChar,
84                Float,
85                Double,
86                LongDouble,
87                Bool,
88                ConstChar,
89                _String,
90                _Vector2,
91                _Vector3,
92                _ColourValue
93            };
94
95            ConfigValueContainer(const String& classname, const String& varname, int defvalue);
96            ConfigValueContainer(const String& classname, const String& varname, unsigned int defvalue);
97            ConfigValueContainer(const String& classname, const String& varname, char defvalue);
98            ConfigValueContainer(const String& classname, const String& varname, unsigned char defvalue);
99            ConfigValueContainer(const String& classname, const String& varname, float defvalue);
100            ConfigValueContainer(const String& classname, const String& varname, double defvalue);
101            ConfigValueContainer(const String& classname, const String& varname, long double defvalue);
102            ConfigValueContainer(const String& classname, const String& varname, bool defvalue);
103            ConfigValueContainer(const String& classname, const String& varname, const String& defvalue);
104            ConfigValueContainer(const String& classname, const String& varname, const char* defvalue);
105            ConfigValueContainer(const String& classname, const String& varname, Vector2 defvalue);
106            ConfigValueContainer(const String& classname, const String& varname, Vector3 defvalue);
107            ConfigValueContainer(const String& classname, const String& varname, ColourValue defvalue);
108
109            /** @returns the value. @param value This is only needed to determine the right type. */
110            inline ConfigValueContainer& getValue(int& value)                           { value = this->value_.value_int_; return *this; }
111            /** @returns the value. @param value This is only needed to determine the right type. */
112            inline ConfigValueContainer& getValue(unsigned int& value)                  { value = this->value_.value_uint_; return *this; }
113            /** @returns the value. @param value This is only needed to determine the right type. */
114            inline ConfigValueContainer& getValue(char& value)                          { value = this->value_.value_char_; return *this; }
115            /** @returns the value. @param value This is only needed to determine the right type. */
116            inline ConfigValueContainer& getValue(unsigned char& value)                 { value = this->value_.value_uchar_; return *this; }
117            /** @returns the value. @param value This is only needed to determine the right type. */
118            inline ConfigValueContainer& getValue(float& value)                         { value = this->value_.value_float_; return *this; }
119            /** @returns the value. @param value This is only needed to determine the right type. */
120            inline ConfigValueContainer& getValue(double& value)                        { value = this->value_.value_double_; return *this; }
121            /** @returns the value. @param value This is only needed to determine the right type. */
122            inline ConfigValueContainer& getValue(long double& value)                   { value = this->value_.value_long_double_; return *this; }
123            /** @returns the value. @param value This is only needed to determine the right type. */
124            inline ConfigValueContainer& getValue(bool& value)                          { value = this->value_.value_bool_; return *this; }
125            /** @returns the value. @param value This is only needed to determine the right type. */
126            inline ConfigValueContainer& getValue(String& value)                   { value = this->value_string_; return *this; }
127            /** @returns the value. @param value This is only needed to determine the right type. */
128            inline ConfigValueContainer& getValue(const char* value)                    { value = this->value_string_.c_str(); return *this; }
129            /** @returns the value. @param value This is only needed to determine the right type. */
130            inline ConfigValueContainer& getValue(Vector2& value)                 { value = this->value_vector2_; return *this; }
131            /** @returns the value. @param value This is only needed to determine the right type. */
132            inline ConfigValueContainer& getValue(Vector3& value)                 { value = this->value_vector3_; return *this; }
133            /** @returns the value. @param value This is only needed to determine the right type. */
134            inline ConfigValueContainer& getValue(ColourValue& value)             { value = this->value_colourvalue_; return *this; }
135
136            void description(const String& description);
137
138            bool parseSting(const String& input);
139            void resetConfigFileEntry();
140            void resetConfigValue();
141
142            static String getStrippedLine(const String& line);
143            static bool isEmpty(const String& line);
144            static bool isComment(const String& line);
145
146        private:
147            bool parseSting(const String& input, int defvalue);
148            bool parseSting(const String& input, unsigned int defvalue);
149            bool parseSting(const String& input, char defvalue);
150            bool parseSting(const String& input, unsigned char defvalue);
151            bool parseSting(const String& input, float defvalue);
152            bool parseSting(const String& input, double defvalue);
153            bool parseSting(const String& input, long double defvalue);
154            bool parseSting(const String& input, bool defvalue);
155            bool parseSting(const String& input, const String& defvalue);
156            bool parseSting(const String& input, const char* defvalue);
157            bool parseSting(const String& input, const Vector2& defvalue);
158            bool parseSting(const String& input, const Vector3& defvalue);
159            bool parseSting(const String& input, const ColourValue& defvalue);
160
161            static std::list<String>& getConfigFileLines();
162            static bool finishedReadingConfigFile(bool finished = false);
163            void searchConfigFileLine();
164            String parseValueString(bool bStripped = true);
165
166            static void readConfigFile(const String& filename);
167            static void writeConfigFile(const String& filename);
168
169            String         classname_;                     //!< The name of the class the variable belongs to
170            String         varname_;                       //!< The name of the variable
171            String         defvalueString_;                //!< The string of the default-variable
172
173            union MultiType
174            {
175                int                 value_int_;                 //!< The value, if the variable is of the type int
176                unsigned int        value_uint_;                //!< The value, if the variable is of the type unsigned int
177                char                value_char_;                //!< The value, if the variable is of the type char
178                unsigned char       value_uchar_;               //!< The value, if the variable is of the type unsigned char
179                float               value_float_;               //!< The value, if the variable is of the type float
180                double              value_double_;              //!< The value, if the variable is of the type double
181                long double         value_long_double_;         //!< The value, if the variable is of the type long double
182                bool                value_bool_;                //!< The value, if the variable is of the type bool
183            } value_;                                           //!< The value of the variable
184
185            String         value_string_;                  //!< The value, if the variable is of the type string
186            Vector2       value_vector2_;                 //!< The value, if the variable is of the type Vector2
187            Vector3       value_vector3_;                 //!< The value, if the variable is of the type Vector3
188            ColourValue   value_colourvalue_;             //!< The value, if the variable is of the type ColourValue
189
190            std::list<String>::iterator configFileLine_;   //!< An iterator, pointing to the entry of the variable in the config-file
191
192            VariableType type_;                                 //!< The type of the variable
193            bool bAddedDescription_;                            //!< True if a description was added
194            LanguageEntryName description_;                     //!< The description
195    };
196}
197
198#endif /* _ConfigValueContainer_H__ */
Note: See TracBrowser for help on using the repository browser.