Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 792 was 792, checked in by landauf, 16 years ago

upload of the work i did before the exams (not yet finished nor working)

File size: 8.7 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#include <string>
47
48#include "CorePrereqs.h"
49
50#include "util/Math.h"
51#include "util/MultiTypeMath.h"
52#include "Language.h"
53
54namespace orxonox
55{
56    //! The ConfigValuecontainer contains all needed informations about a configurable variable.
57    /**
58        The ConfigValueContainer class contains all needed informations about a configurable variable:
59         - the name of the variable
60         - the name of the class the variable belongs to
61         - the default value
62         - the user-specified value
63         - a pointer to the entry in the config-file
64
65        This is needed to assign the configured values to all newly created objects.
66
67        The container searches for the entry in the config file.
68        If there is an entry, it parses the specified value and assigns it to the variable of the right type.
69        If there is no entry, it adds the entry with the default-value to the section of the variables class.
70        If there is no section, the section and the entry are added to the end of the config-file.
71    */
72    class _CoreExport ConfigValueContainer
73    {
74        public:
75            ConfigValueContainer(const std::string& classname, const std::string& varname, MultiTypeMath defvalue);
76
77            /** @returns the value. @param value This is only needed to determine the right type. */
78/*            template <typename T>
79            inline ConfigValueContainer& getValue(T& value)                           { this->value_.getValue(value); return *this; }
80*/
81            inline ConfigValueContainer& getValue(int* value)            { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
82            inline ConfigValueContainer& getValue(unsigned int* value)   { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
83            inline ConfigValueContainer& getValue(char* value)           { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
84            inline ConfigValueContainer& getValue(unsigned char* value)  { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
85            inline ConfigValueContainer& getValue(short* value)          { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
86            inline ConfigValueContainer& getValue(unsigned short* value) { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
87            inline ConfigValueContainer& getValue(long* value)           { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
88            inline ConfigValueContainer& getValue(unsigned long* value)  { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
89            inline ConfigValueContainer& getValue(float* value)          { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
90            inline ConfigValueContainer& getValue(double* value)         { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
91            inline ConfigValueContainer& getValue(long double* value)    { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
92            inline ConfigValueContainer& getValue(bool* value)           { ((MultiTypePrimitive)this->value_).getValue(value); return *this; }
93            inline ConfigValueContainer& getValue(std::string* value)    { ((MultiTypeString)this->value_).getValue(value); return *this; }
94            inline ConfigValueContainer& getValue(Vector2* value)        { this->value_.getValue(value); return *this; }
95            inline ConfigValueContainer& getValue(Vector3* value)        { this->value_.getValue(value); return *this; }
96            inline ConfigValueContainer& getValue(ColourValue* value)    { this->value_.getValue(value); return *this; }
97            inline ConfigValueContainer& getValue(Quaternion* value)     { this->value_.getValue(value); return *this; }
98            inline ConfigValueContainer& getValue(Radian* value)         { this->value_.getValue(value); return *this; }
99            inline ConfigValueContainer& getValue(Degree* value)         { this->value_.getValue(value); return *this; }
100
101            void description(const std::string& description);
102
103            bool parseString(const std::string& input, MultiTypeMath& defvalue = MT_null);
104            bool valueToString(std::string* output, MultiTypeMath& input);
105            void resetConfigFileEntry();
106            void resetConfigValue();
107
108            static std::string getStrippedLine(const std::string& line);
109            static bool isEmpty(const std::string& line);
110            static bool isComment(const std::string& line);
111
112        private:
113            bool parseString(const std::string& input, int defvalue);
114            bool parseString(const std::string& input, unsigned int defvalue);
115            bool parseString(const std::string& input, char defvalue);
116            bool parseString(const std::string& input, unsigned char defvalue);
117            bool parseString(const std::string& input, short defvalue);
118            bool parseString(const std::string& input, unsigned short defvalue);
119            bool parseString(const std::string& input, long defvalue);
120            bool parseString(const std::string& input, unsigned long defvalue);
121            bool parseString(const std::string& input, float defvalue);
122            bool parseString(const std::string& input, double defvalue);
123            bool parseString(const std::string& input, long double defvalue);
124            bool parseString(const std::string& input, bool defvalue);
125            bool parseString(const std::string& input, const std::string& defvalue);
126            bool parseString(const std::string& input, const char* defvalue);
127            bool parseString(const std::string& input, const Vector2& defvalue);
128            bool parseString(const std::string& input, const Vector3& defvalue);
129            bool parseString(const std::string& input, const ColourValue& defvalue);
130            bool parseString(const std::string& input, const Quaternion& defvalue);
131            bool parseString(const std::string& input, const Radian& defvalue);
132            bool parseString(const std::string& input, const Degree& defvalue);
133
134            static std::list<std::string>& getConfigFileLines();
135            static bool finishedReadingConfigFile(bool finished = false);
136            void searchConfigFileLine();
137            std::string parseValueString(bool bStripped = true);
138
139            static void readConfigFile(const std::string& filename);
140            static void writeConfigFile(const std::string& filename);
141
142            std::string         classname_;                     //!< The name of the class the variable belongs to
143            std::string         varname_;                       //!< The name of the variable
144            std::string         defvalueString_;                //!< The string of the default-variable
145
146            MultiTypeMath       value_;                         //!< The value
147
148            std::list<std::string>::iterator configFileLine_;   //!< An iterator, pointing to the entry of the variable in the config-file
149
150            bool bAddedDescription_;                            //!< True if a description was added
151            LanguageEntryName description_;                     //!< The description
152    };
153}
154
155#endif /* _ConfigValueContainer_H__ */
Note: See TracBrowser for help on using the repository browser.