Changeset 2103 for code/trunk/src/core/ConfigFileManager.h
- Timestamp:
- Nov 2, 2008, 12:22:42 AM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/core/ConfigFileManager.h
r1887 r2103 41 41 namespace orxonox 42 42 { 43 enum _CoreExport ConfigFileType 44 { 45 CFT_Settings, 46 CFT_Keybindings, 47 CFT_JoyStickCalibration 48 }; 49 43 // Use unsigned int as config file type to have an arbitrary number of files 44 class ConfigFileType 45 { 46 public: 47 ConfigFileType() { } 48 ConfigFileType(unsigned int type) { type_ = type; } 49 ConfigFileType(const ConfigFileType& instance) { type_ = instance.type_; } 50 51 operator unsigned int() { return type_; } 52 ConfigFileType& operator =(unsigned int type) { type_ = type; return *this; } 53 bool operator <(const ConfigFileType& right) const { return (type_ < right.type_); } 54 55 /* *** Put the different config file types here *** */ 56 static const unsigned int NoType = 0; 57 static const unsigned int Settings = 1; 58 static const unsigned int JoyStickCalibration = 2; 59 60 static const unsigned int numberOfReservedTypes = 1024; 61 62 private: 63 unsigned int type_; 64 }; 50 65 51 66 bool config(const std::string& classname, const std::string& varname, const std::string& value); … … 55 70 void cleanConfig(); 56 71 void loadSettings(const std::string& filename); 57 void loadKeybindings(const std::string& filename);58 72 59 73 … … 218 232 { 219 233 public: 220 inline ConfigFile(const std::string& filename) : filename_(filename), bUpdated_(false) {} 234 inline ConfigFile(const std::string& filename, ConfigFileType type) 235 : filename_(filename) 236 , type_(type) 237 , bUpdated_(false) 238 { } 221 239 ~ConfigFile(); 222 240 223 241 void load(bool bCreateIfNotExisting = true); 224 242 void save() const; 225 void save (const std::string& filename);243 void saveAs(const std::string& filename); 226 244 void clean(bool bCleanComments = false); 245 void clear(); 246 247 const std::string& getFilename() { return this->filename_; } 227 248 228 249 inline void setValue(const std::string& section, const std::string& name, const std::string& value, bool bString) … … 241 262 { return this->getSection(section)->getVectorSize(name); } 242 263 264 void updateConfigValues(); 265 243 266 private: 244 267 ConfigFileSection* getSection(const std::string& section); … … 246 269 247 270 std::string filename_; 271 ConfigFileType type_; 248 272 std::list<ConfigFileSection*> sections_; 249 273 bool bUpdated_; … … 257 281 { 258 282 public: 259 static ConfigFileManager& getInstance(); 260 261 void setFile(ConfigFileType type, const std::string& filename, bool bCreateIfNotExisting = true); 262 263 void load(bool bCreateIfNotExisting = true); 283 ConfigFileManager(); 284 ~ConfigFileManager(); 285 286 void load(); 264 287 void save(); 265 288 void clean(bool bCleanComments = false); 266 289 267 void load(ConfigFileType type, bool bCreateIfNotExisting = true); 290 void setFilename(ConfigFileType type, const std::string& filename); 291 const std::string& getFilename(ConfigFileType type); 292 293 ConfigFileType getNewConfigFileType() { return mininmalFreeType_++; } 294 295 void load(ConfigFileType type); 268 296 void save(ConfigFileType type); 269 void save (ConfigFileType type, const std::string& filename);297 void saveAs(ConfigFileType type, const std::string& saveFilename); 270 298 void clean(ConfigFileType type, bool bCleanComments = false); 271 299 … … 285 313 { return this->getFile(type)->getVectorSize(section, name); } 286 314 287 void updateConfigValues() const;288 void updateConfigValues(ConfigFileType type) const;289 290 private:291 ConfigFileManager(); 292 ConfigFileManager(const ConfigFileManager& other);293 ~ConfigFileManager();315 void updateConfigValues(); 316 void updateConfigValues(ConfigFileType type); 317 318 static ConfigFileManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } 319 320 private: 321 ConfigFileManager(const ConfigFileManager&); 294 322 295 323 ConfigFile* getFile(ConfigFileType type); 296 324 297 std::string getFilePath(const std::string& name) const;298 299 325 std::map<ConfigFileType, ConfigFile*> configFiles_; 326 unsigned int mininmalFreeType_; 327 328 static ConfigFileManager* singletonRef_s; 300 329 }; 301 330 }
Note: See TracChangeset
for help on using the changeset viewer.