Changeset 1638 for code/branches/gui/src/orxonox/Settings.h
- Timestamp:
- Jul 20, 2008, 7:49:26 PM (16 years ago)
- Location:
- code/branches/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui
-
Property
svn:mergeinfo
set to
/code/branches/input merged eligible
-
Property
svn:mergeinfo
set to
-
code/branches/gui/src/orxonox/Settings.h
r1535 r1638 29 29 /** 30 30 @file Core.h 31 @brief De finition of the Settings class.31 @brief Declaration of the Settings class. 32 32 33 33 The static Settings class is only used to configure some variables … … 41 41 #include <string> 42 42 #include "core/OrxonoxClass.h" 43 #include "core/Debug.h" 44 #include "util/MultiTypeMath.h" 45 #include "util/Convert.h" 43 46 44 47 namespace orxonox 45 48 { 46 class _OrxonoxExport Settings : public OrxonoxClass 47 { 49 /** 50 @brief 51 Defines a bit field structure that holds the mode as enum plus 52 the attributes as single named bits. 53 Every different GameMode is stored as static const, but if you wish to 54 compare two modes, you will have to use the 'mode' member variable. 55 */ 56 struct GameMode 57 { 58 enum Mode 59 { 60 None, 61 Unspecified, 62 Server, 63 Client, 64 Standalone, 65 Dedicated, 66 }; 67 68 Mode mode; 69 bool showsGraphics; 70 bool isMaster; 71 bool hasServer; 72 std::string name; 73 74 static const GameMode GM_None; 75 static const GameMode GM_Unspecified; 76 static const GameMode GM_Server; 77 static const GameMode GM_Client; 78 static const GameMode GM_Standalone; 79 static const GameMode GM_Dedicated; 80 }; 81 82 83 class _OrxonoxExport Settings : public OrxonoxClass 84 { 48 85 public: 49 void setConfigValues(); 86 struct CommandLineArgument 87 { 88 std::string name_; 89 MultiTypeMath value_; 90 bool bHasDefaultValue_; 91 }; 50 92 51 static const std::string& getDataPath();93 void setConfigValues(); 52 94 53 static void tsetDataPath(const std::string& path); 95 static const std::string& getDataPath(); 96 static void tsetDataPath(const std::string& path); 97 98 static const GameMode& getGameMode(); 99 static const GameMode& getGameMode(const std::string& name); 100 static void setGameMode(const GameMode& mode); 101 static void setGameMode(const std::string& mode); 102 static bool addGameMode(const GameMode* mode); 103 104 static const CommandLineArgument* getCommandLineArgument(const std::string& name); 105 template <class T> 106 static bool addCommandLineArgument(const std::string &name, const std::string& valueStr, const T& defaultValue); 54 107 55 108 private: 56 Settings();57 Settings(const Settings& instance);58 ~Settings();59 static Settings& getSingleton();109 Settings(); 110 Settings(const Settings& instance); 111 ~Settings() { } 112 static Settings& getInstance(); 60 113 61 void _tsetDataPath(const std::string& path);114 void _tsetDataPath(const std::string& path); 62 115 63 std::string dataPath_; //!< Path to the game data 64 }; 116 std::string dataPath_; //!< Path to the game data 117 GameMode gameMode_; //!< Current game mode 118 std::map<std::string, const GameMode*> gameModes_; //!< Holds all game modes for easy string access 119 //! holds all command line arguments (even if not given!) 120 std::map<std::string, CommandLineArgument> commandArguments_; 121 }; 122 123 /** 124 @brief 125 Returns the relative path to the game data. 126 */ 127 inline const std::string& Settings::getDataPath() 128 { 129 return getInstance().dataPath_; 130 } 131 132 inline void Settings::tsetDataPath(const std::string& path) 133 { 134 getInstance()._tsetDataPath(path); 135 } 136 137 inline const GameMode& Settings::getGameMode() 138 { 139 return getInstance().gameMode_; 140 } 141 142 inline const GameMode& Settings::getGameMode(const std::string& name) 143 { 144 if (getInstance().gameModes_.find(name) != getInstance().gameModes_.end()) 145 return *getInstance().gameModes_[name]; 146 else 147 { 148 COUT(2) << "Warning: GameMode '" << name << "' doesn't exist." << std::endl; 149 return GameMode::GM_None; 150 } 151 } 152 153 inline void Settings::setGameMode(const GameMode& mode) 154 { 155 getInstance().gameMode_ = mode; 156 } 157 158 /** 159 @brief 160 Adds one argument of the command line to the map of command line arguments. 161 @param name 162 Name of the command line option. 163 @param valueStr 164 The value of the command line option as string 165 @param defaultValue 166 Default value for the option (marked when used). 167 @return 168 Dummy return value to enable code execution before main(). 169 */ 170 template <class T> 171 bool Settings::addCommandLineArgument(const std::string &name, const std::string& valueStr, const T& defaultValue) 172 { 173 T value; 174 bool useDefault = false; 175 if (valueStr == "") 176 { 177 // note: ArgReader only returns "" for not found arguments, " " otherwise for empty ones. 178 value = defaultValue; 179 useDefault = true; 180 } 181 else if (!convertValue(&value, valueStr)) 182 { 183 COUT(1) << "Command Line: Couldn't read option '" << name << "'." << std::endl; 184 return false; 185 } 186 CommandLineArgument arg = { name, MultiTypeMath(value), useDefault }; 187 getInstance().commandArguments_[name] = arg; 188 return true; 189 } 65 190 } 66 191
Note: See TracChangeset
for help on using the changeset viewer.