Changeset 1027
- Timestamp:
- Apr 10, 2008, 6:44:38 PM (17 years ago)
- Location:
- code/branches/core2/src/orxonox/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/ConfigFileManager.cc
r1026 r1027 38 38 { 39 39 ConsoleCommandShortcutExtern(reloadConfig, AccessLevel::None); 40 ConsoleCommandShortcutExtern(saveConfig, AccessLevel::None);41 40 ConsoleCommandShortcutExtern(cleanConfig, AccessLevel::None); 42 41 ConsoleCommandShortcutExtern(loadSettings, AccessLevel::None); … … 48 47 } 49 48 50 void saveConfig()51 {52 ConfigFileManager::getSingleton()->save();53 }54 55 49 void cleanConfig() 56 50 { … … 60 54 void loadSettings(const std::string& filename) 61 55 { 62 ConfigFileManager::getSingleton()->setFile(CFT_Settings, filename );56 ConfigFileManager::getSingleton()->setFile(CFT_Settings, filename, false); 63 57 } 64 58 … … 145 139 } 146 140 147 void ConfigFile::load() 148 { 149 // This creates the file if it's not existing 150 std::ofstream createFile; 151 createFile.open(this->filename_.c_str(), std::fstream::app); 152 createFile.close(); 141 void ConfigFile::load(bool bCreateIfNotExisting) 142 { 143 if (bCreateIfNotExisting) 144 { 145 // This creates the default config file if it's not existing 146 std::ofstream createFile; 147 createFile.open(this->filename_.c_str(), std::fstream::app); 148 createFile.close(); 149 } 153 150 154 151 // Open the file … … 289 286 void ConfigFile::clean() 290 287 { 288 for (std::list<ConfigFileSection*>::iterator it1 = this->sections_.begin(); it1 != this->sections_.end(); ) 289 { 290 std::map<std::string, Identifier*>::const_iterator it2 = Identifier::getIdentifierMap().find((*it1)->getName()); 291 if (it2 != Identifier::getIdentifierMapEnd() && (*it2).second->hasConfigValues()) 292 { 293 // The section exists, delete comment 294 (*it1)->setComment(""); 295 for (std::list<ConfigFileEntry*>::iterator it3 = (*it1)->entries_.begin(); it3 != (*it1)->entries_.end(); ) 296 { 297 std::map<std::string, ConfigValueContainer*>::const_iterator it4 = (*it2).second->getConfigValueMap().find((*it3)->getName()); 298 if (it4 != (*it2).second->getConfigValueMapEnd()) 299 { 300 // The config-value exists, delete comment 301 (*it3)->setComment(""); 302 ++it3; 303 } 304 else 305 { 306 // The config-value doesn't exist 307 delete (*it3); 308 (*it1)->entries_.erase(it3++); 309 } 310 } 311 ++it1; 312 } 313 else 314 { 315 // The section doesn't exist 316 delete (*it1); 317 this->sections_.erase(it1++); 318 } 319 } 320 321 // Save the file 322 this->save(); 291 323 } 292 324 … … 343 375 } 344 376 345 void ConfigFileManager::setFile(ConfigFileType type, const std::string& filename )377 void ConfigFileManager::setFile(ConfigFileType type, const std::string& filename, bool bCreateIfNotExisting) 346 378 { 347 379 std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.find(type); … … 351 383 352 384 this->configFiles_[type] = new ConfigFile(this->getFilePath(filename)); 353 this->load(type );354 } 355 356 void ConfigFileManager::load( )385 this->load(type, bCreateIfNotExisting); 386 } 387 388 void ConfigFileManager::load(bool bCreateIfNotExisting) 357 389 { 358 390 for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it) 359 (*it).second->load( );391 (*it).second->load(bCreateIfNotExisting); 360 392 361 393 this->updateConfigValues(); … … 374 406 } 375 407 376 void ConfigFileManager::load(ConfigFileType type )377 { 378 this->getFile(type)->load( );408 void ConfigFileManager::load(ConfigFileType type, bool bCreateIfNotExisting) 409 { 410 this->getFile(type)->load(bCreateIfNotExisting); 379 411 this->updateConfigValues(type); 380 412 } -
code/branches/core2/src/orxonox/core/ConfigFileManager.h
r1025 r1027 65 65 virtual const std::string& getValue() const = 0; 66 66 virtual const std::string& getName() const = 0; 67 virtual void setComment(const std::string& comment) = 0; 67 68 virtual unsigned int getIndex() const { return 0; } 68 69 virtual std::string getFileEntry() const = 0; … … 81 82 inline virtual const std::string& getName() const 82 83 { return this->name_; } 84 85 inline virtual void setComment(const std::string& comment) 86 { this->additionalComment_ = comment; } 83 87 84 88 inline virtual void setValue(const std::string& value) … … 133 137 { return this->comment_; } 134 138 139 inline virtual void setComment(const std::string& comment) 140 { this->comment_ = comment; } 141 135 142 inline virtual void setValue(const std::string& value) 136 143 {} … … 159 166 inline const std::string& getName() const 160 167 { return this->name_; } 168 169 inline void setComment(const std::string& comment) 170 { this->additionalComment_ = comment; } 161 171 162 172 inline void setValue(const std::string& name, const std::string& value) … … 204 214 ~ConfigFile(); 205 215 206 void load( );216 void load(bool bCreateIfNotExisting = true); 207 217 void save() const; 208 218 void clean(); … … 236 246 static ConfigFileManager* getSingleton(); 237 247 238 void setFile(ConfigFileType type, const std::string& filename );239 240 void load( );248 void setFile(ConfigFileType type, const std::string& filename, bool bCreateIfNotExisting = true); 249 250 void load(bool bCreateIfNotExisting = true); 241 251 void save(); 242 252 void clean(); 243 253 244 void load(ConfigFileType type );254 void load(ConfigFileType type, bool bCreateIfNotExisting = true); 245 255 void save(ConfigFileType type); 246 256 void clean(ConfigFileType type);
Note: See TracChangeset
for help on using the changeset viewer.