[682] | 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 | |
---|
[871] | 28 | /** |
---|
[497] | 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> |
---|
[715] | 46 | #include <string> |
---|
[497] | 47 | |
---|
[682] | 48 | #include "CorePrereqs.h" |
---|
| 49 | |
---|
[742] | 50 | #include "util/Math.h" |
---|
[871] | 51 | #include "util/MultiTypeMath.h" |
---|
[497] | 52 | |
---|
| 53 | namespace orxonox |
---|
| 54 | { |
---|
| 55 | //! The ConfigValuecontainer contains all needed informations about a configurable variable. |
---|
| 56 | /** |
---|
| 57 | The ConfigValueContainer class contains all needed informations about a configurable variable: |
---|
| 58 | - the name of the variable |
---|
| 59 | - the name of the class the variable belongs to |
---|
| 60 | - the default value |
---|
| 61 | - the user-specified value |
---|
| 62 | - a pointer to the entry in the config-file |
---|
| 63 | |
---|
| 64 | This is needed to assign the configured values to all newly created objects. |
---|
| 65 | |
---|
| 66 | The container searches for the entry in the config file. |
---|
| 67 | If there is an entry, it parses the specified value and assigns it to the variable of the right type. |
---|
| 68 | If there is no entry, it adds the entry with the default-value to the section of the variables class. |
---|
| 69 | If there is no section, the section and the entry are added to the end of the config-file. |
---|
| 70 | */ |
---|
[682] | 71 | class _CoreExport ConfigValueContainer |
---|
[497] | 72 | { |
---|
| 73 | public: |
---|
[957] | 74 | ConfigValueContainer(Identifier* identifier, const std::string& varname, MultiTypeMath defvalue); |
---|
[703] | 75 | |
---|
[871] | 76 | /** @brief Returns the configured value. @param value This is only needed to determine the right type. @return The value */ |
---|
[957] | 77 | template <typename T> |
---|
| 78 | inline ConfigValueContainer& getValue(T* value) |
---|
| 79 | { this->value_.getValue(value); return *this; } |
---|
[497] | 80 | |
---|
[715] | 81 | void description(const std::string& description); |
---|
[871] | 82 | const std::string& getDescription() const; |
---|
[705] | 83 | |
---|
[957] | 84 | bool set(const std::string& input); |
---|
| 85 | bool tset(const std::string& input); |
---|
| 86 | bool reset(); |
---|
[703] | 87 | |
---|
[957] | 88 | /** @brief Converts the config-value to a string. @return The string */ |
---|
| 89 | inline std::string toString() const |
---|
| 90 | { return this->value_.toString(); } |
---|
| 91 | /** @brief Returns the typename of the assigned config-value. @return The typename */ |
---|
[947] | 92 | inline std::string getTypename() const |
---|
| 93 | { return this->value_.getTypename(); } |
---|
| 94 | |
---|
[497] | 95 | private: |
---|
[957] | 96 | static void readConfigFile(const std::string& filename); |
---|
| 97 | static void writeConfigFile(const std::string& filename); |
---|
[715] | 98 | static std::list<std::string>& getConfigFileLines(); |
---|
[703] | 99 | static bool finishedReadingConfigFile(bool finished = false); |
---|
| 100 | |
---|
[957] | 101 | bool parse(const std::string& input); |
---|
| 102 | bool parse(const std::string& input, const MultiTypeMath& defvalue); |
---|
[703] | 103 | |
---|
[957] | 104 | void setLineInConfigFile(const std::string& input); |
---|
| 105 | void resetLineInConfigFile(); |
---|
| 106 | void searchLineInConfigFile(); |
---|
| 107 | |
---|
| 108 | std::string parseValueStringFromConfigFile(bool bStripped = true); |
---|
| 109 | |
---|
| 110 | Identifier* identifier_; //!< The name of the class the variable belongs to |
---|
[715] | 111 | std::string varname_; //!< The name of the variable |
---|
| 112 | std::string defvalueString_; //!< The string of the default-variable |
---|
[497] | 113 | |
---|
[871] | 114 | MultiTypeMath value_; //!< The value |
---|
[497] | 115 | |
---|
[715] | 116 | std::list<std::string>::iterator configFileLine_; //!< An iterator, pointing to the entry of the variable in the config-file |
---|
[667] | 117 | |
---|
[705] | 118 | bool bAddedDescription_; //!< True if a description was added |
---|
[871] | 119 | LanguageEntryLabel description_; //!< The description |
---|
[497] | 120 | }; |
---|
| 121 | } |
---|
| 122 | |
---|
[673] | 123 | #endif /* _ConfigValueContainer_H__ */ |
---|