Changeset 6432 for code/branches/gamestate/src
- Timestamp:
- Dec 29, 2009, 10:30:19 PM (15 years ago)
- Location:
- code/branches/gamestate/src/libraries/core
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gamestate/src/libraries/core/ArgumentCompletionFunctions.cc
r6417 r6432 36 36 #include "util/StringUtils.h" 37 37 #include "Identifier.h" 38 #include "ConfigFileManager.h" 38 39 #include "ConfigValueContainer.h" 39 40 #include "TclThreadManager.h" … … 96 97 } 97 98 98 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION( configvalueclasses)()99 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingssections)() 99 100 { 100 ArgumentCompletionList classlist;101 ArgumentCompletionList sectionList; 101 102 102 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin(); it != Identifier::getStringIdentifierMapEnd(); ++it)103 if (it->second->hasConfigValues())104 classlist.push_back(ArgumentCompletionListElement(it->first, getLowercase(it->first)));103 const std::set<std::string>& names = SettingsConfigFile::getInstance().getSectionNames(); 104 for (std::set<std::string>::const_iterator it = names.begin(); it != names.end(); ++it) 105 sectionList.push_back(ArgumentCompletionListElement(*it, getLowercase(*it))); 105 106 106 return classlist;107 return sectionList; 107 108 } 108 109 109 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION( configvalues)(const std::string& fragment, const std::string& classname)110 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsentries)(const std::string& fragment, const std::string& section) 110 111 { 111 ArgumentCompletionList configvalues; 112 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname)); 112 ArgumentCompletionList entryList; 113 SettingsConfigFile& settings = SettingsConfigFile::getInstance(); 114 const std::string& sectionLC = getLowercase(section); 113 115 114 if (identifier != Identifier::getLowercaseStringIdentifierMapEnd() && identifier->second->hasConfigValues()) 116 SettingsConfigFile::ContainerMap::const_iterator upper = settings.getContainerUpperBound(sectionLC); 117 for (SettingsConfigFile::ContainerMap::const_iterator it = settings.getContainerLowerBound(sectionLC); it != upper; ++it) 118 entryList.push_back(ArgumentCompletionListElement(it->second.second->getName(), it->second.first)); 119 120 return entryList; 121 } 122 123 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsvalue)(const std::string& fragment, const std::string& entry, const std::string& section) 124 { 125 ArgumentCompletionList oldValue; 126 SettingsConfigFile& settings = SettingsConfigFile::getInstance(); 127 const std::string& sectionLC = getLowercase(section); 128 const std::string& entryLC = getLowercase(entry); 129 130 SettingsConfigFile::ContainerMap::const_iterator upper = settings.getContainerUpperBound(sectionLC); 131 for (SettingsConfigFile::ContainerMap::const_iterator it = settings.getContainerLowerBound(sectionLC); it != upper; ++it) 115 132 { 116 for (std::map<std::string, ConfigValueContainer*>::const_iterator it = identifier->second->getConfigValueMapBegin(); it != identifier->second->getConfigValueMapEnd(); ++it) 117 configvalues.push_back(ArgumentCompletionListElement(it->first, getLowercase(it->first))); 133 if (it->second.first == entryLC) 134 { 135 const std::string& valuestring = it->second.second->toString(); 136 oldValue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring)); 137 } 118 138 } 119 139 120 return configvalues; 121 } 122 123 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalue)(const std::string& fragment, const std::string& varname, const std::string& classname) 124 { 125 ArgumentCompletionList oldvalue; 126 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname)); 127 if (identifier != Identifier::getLowercaseStringIdentifierMapEnd()) 128 { 129 std::map<std::string, ConfigValueContainer*>::const_iterator variable = identifier->second->getLowercaseConfigValueMap().find(getLowercase(varname)); 130 if (variable != identifier->second->getLowercaseConfigValueMapEnd()) 131 { 132 const std::string& valuestring = variable->second->toString(); 133 oldvalue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring)); 134 } 135 } 136 return oldvalue; 140 return oldValue; 137 141 } 138 142 -
code/branches/gamestate/src/libraries/core/ArgumentCompletionFunctions.h
r5781 r6432 54 54 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(fallback)(); 55 55 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(files)(const std::string& fragment); 56 ARGUMENT_COMPLETION_FUNCTION_DECLARATION( configvalueclasses)();57 ARGUMENT_COMPLETION_FUNCTION_DECLARATION( configvalues)(const std::string& fragment, const std::string& classname);58 ARGUMENT_COMPLETION_FUNCTION_DECLARATION( configvalue)(const std::string& fragment, const std::string& varname, const std::string& classname);56 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(settingssections)(); 57 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(settingsentries)(const std::string& fragment, const std::string& section); 58 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(settingsvalue)(const std::string& fragment, const std::string& entry, const std::string& section); 59 59 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(tclthreads)(); 60 60 } -
code/branches/gamestate/src/libraries/core/ConfigFileManager.cc
r6425 r6432 40 40 namespace orxonox 41 41 { 42 SetConsoleCommandShortcutExtern(config).argumentCompleter(0, autocompletion::configvalueclasses()).argumentCompleter(1, autocompletion::configvalues()).argumentCompleter(2, autocompletion::configvalue());43 SetConsoleCommandShortcutExtern(tconfig).argumentCompleter(0, autocompletion::configvalueclasses()).argumentCompleter(1, autocompletion::configvalues()).argumentCompleter(2, autocompletion::configvalue());44 SetConsoleCommandShortcutExtern(reloadConfig);45 SetConsoleCommandShortcutExtern(cleanConfig);46 SetConsoleCommandShortcutExtern(loadSettings).argumentCompleter(0, autocompletion::files());47 48 bool config(const std::string& classname, const std::string& varname, const std::string& value)49 {50 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname));51 if (identifier != Identifier::getLowercaseStringIdentifierMapEnd())52 {53 std::map<std::string, ConfigValueContainer*>::const_iterator variable = identifier->second->getLowercaseConfigValueMap().find(getLowercase(varname));54 if (variable != identifier->second->getLowercaseConfigValueMapEnd())55 return variable->second->set(value);56 }57 return false;58 }59 60 const std::string& getConfig(const std::string& classname, const std::string& varname)61 {62 return ConfigFileManager::getInstance().getValue(ConfigFileType::Settings, classname, varname, "", true);63 }64 65 bool tconfig(const std::string& classname, const std::string& varname, const std::string& value)66 {67 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname));68 if (identifier != Identifier::getLowercaseStringIdentifierMapEnd())69 {70 std::map<std::string, ConfigValueContainer*>::const_iterator variable = identifier->second->getLowercaseConfigValueMap().find(getLowercase(varname));71 if (variable != identifier->second->getLowercaseConfigValueMapEnd())72 return variable->second->tset(value);73 }74 return false;75 }76 77 void reloadConfig()78 {79 ConfigFileManager::getInstance().load();80 }81 82 void cleanConfig()83 {84 ConfigFileManager::getInstance().clean(false);85 }86 87 void loadSettings(const std::string& filename)88 {89 ConfigFileManager::getInstance().setFilename(ConfigFileType::Settings, filename);90 }91 92 42 ////////////////////////// 93 43 // ConfigFileEntryValue // … … 101 51 // Assemble the entry line 102 52 this->fileEntry_ = this->getKeyString() + " = "; 103 if (this->bString_ )53 if (this->bString_ && !this->value_.empty()) 104 54 this->fileEntry_ += '"' + addSlashes(this->value_) + '"'; 105 55 else … … 145 95 } 146 96 147 unsigned int ConfigFileSection::getVectorSize(const std::string& name) 97 unsigned int ConfigFileSection::getVectorSize(const std::string& name) const 148 98 { 149 99 unsigned int size = 0; … … 166 116 } 167 117 168 std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, const std::string& fallback, bool bString) 118 std::list<ConfigFileEntry*>::const_iterator ConfigFileSection::getEntryIterator(const std::string& name) const 119 { 120 for (std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it) 121 { 122 if ((*it)->getName() == name) 123 return it; 124 } 125 return this->entries_.end(); 126 } 127 128 std::list<ConfigFileEntry*>::iterator ConfigFileSection::getOrCreateEntryIterator(const std::string& name, const std::string& fallback, bool bString) 169 129 { 170 130 for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it) … … 179 139 this->bUpdated_ = true; 180 140 181 return this->entries_.insert(this->entries_.end(), static_cast<ConfigFileEntry*>(new ConfigFileEntryValue(name, fallback, bString))); 182 } 183 184 std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString) 141 return this->entries_.insert(this->entries_.end(), new ConfigFileEntryValue(name, fallback, bString)); 142 } 143 144 std::list<ConfigFileEntry*>::const_iterator ConfigFileSection::getEntryIterator(const std::string& name, unsigned int index) const 145 { 146 for (std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it) 147 { 148 if (((*it)->getName() == name) && ((*it)->getIndex() == index)) 149 return it; 150 } 151 return this->entries_.end(); 152 } 153 154 std::list<ConfigFileEntry*>::iterator ConfigFileSection::getOrCreateEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString) 185 155 { 186 156 for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it) … … 196 166 197 167 if (index == 0) 198 return this->entries_.insert(this->entries_.end(), static_cast<ConfigFileEntry*>(new ConfigFileEntryVectorValue(name, index, fallback, bString)));168 return this->entries_.insert(this->entries_.end(), new ConfigFileEntryVectorValue(name, index, fallback, bString)); 199 169 else 200 return this->entries_.insert(++this->get EntryIterator(name, index - 1, "", bString), static_cast<ConfigFileEntry*>(new ConfigFileEntryVectorValue(name, index, fallback, bString)));170 return this->entries_.insert(++this->getOrCreateEntryIterator(name, index - 1, "", bString), new ConfigFileEntryVectorValue(name, index, fallback, bString)); 201 171 } 202 172 … … 205 175 // ConfigFile // 206 176 //////////////// 177 ConfigFile::ConfigFile(const std::string& filename) 178 : filename_(filename) 179 , bUpdated_(false) 180 { 181 } 182 207 183 ConfigFile::~ConfigFile() 208 184 { … … 210 186 } 211 187 212 void ConfigFile::load( bool bCreateIfNotExisting)188 void ConfigFile::load() 213 189 { 214 190 // Be sure we start from new in the memory … … 300 276 { 301 277 // New array 302 std::list<ConfigFileEntry*>::iterator it = newsection->get EntryIterator(getStripped(line.substr(0, pos2)), index, value, false);278 std::list<ConfigFileEntry*>::iterator it = newsection->getOrCreateEntryIterator(getStripped(line.substr(0, pos2)), index, value, false); 303 279 (*it)->setValue(value); 304 280 (*it)->setComment(comment); … … 319 295 COUT(3) << "Loaded config file \"" << this->filename_ << "\"." << std::endl; 320 296 321 // Save the file in case something changed (like stripped white spaces)297 // Save the file in case something changed (like stripped white space) 322 298 this->save(); 323 324 // Update all ConfigValueContainers325 this->updateConfigValues();326 299 } // end file.is_open() 327 300 } … … 329 302 void ConfigFile::save() const 330 303 { 304 this->saveAs(this->filename_); 305 } 306 307 void ConfigFile::saveAs(const std::string& filename) const 308 { 331 309 std::ofstream file; 332 file.open((PathConfig::getConfigPathString() + filename _).c_str(), std::fstream::out);310 file.open((PathConfig::getConfigPathString() + filename).c_str(), std::fstream::out); 333 311 file.setf(std::ios::fixed, std::ios::floatfield); 334 312 file.precision(6); … … 336 314 if (!file.is_open()) 337 315 { 338 COUT(1) << "An error occurred in ConfigFileManager.cc:" << std::endl; 339 COUT(1) << "Error: Couldn't open config-file \"" << this->filename_ << "\"." << std::endl; 316 COUT(1) << "Error: Couldn't open config-file \"" << filename << "\"." << std::endl; 340 317 return; 341 318 } … … 346 323 347 324 for (std::list<ConfigFileEntry*>::const_iterator it_entries = (*it)->getEntriesBegin(); it_entries != (*it)->getEntriesEnd(); ++it_entries) 348 {349 325 file << (*it_entries)->getFileEntry() << std::endl; 350 }351 326 352 327 file << std::endl; … … 355 330 file.close(); 356 331 357 COUT(4) << "Saved config file \"" << this->filename_ << "\"." << std::endl; 358 } 359 360 void ConfigFile::saveAs(const std::string& filename) 361 { 362 std::string temp = this->filename_; 363 this->filename_ = filename; 364 this->save(); 365 this->filename_ = temp; 366 } 367 368 void ConfigFile::clean(bool bCleanComments) 369 { 370 for (std::list<ConfigFileSection*>::iterator it1 = this->sections_.begin(); it1 != this->sections_.end(); ) 371 { 372 std::map<std::string, Identifier*>::const_iterator it2 = Identifier::getStringIdentifierMap().find((*it1)->getName()); 373 if (it2 != Identifier::getStringIdentifierMapEnd() && it2->second->hasConfigValues()) 374 { 375 // The section exists, delete comment 376 if (bCleanComments) 377 (*it1)->setComment(""); 378 for (std::list<ConfigFileEntry*>::iterator it3 = (*it1)->entries_.begin(); it3 != (*it1)->entries_.end(); ) 379 { 380 std::map<std::string, ConfigValueContainer*>::const_iterator it4 = it2->second->getConfigValueMap().find((*it3)->getName()); 381 if (it4 != it2->second->getConfigValueMapEnd()) 382 { 383 // The config-value exists, delete comment 384 if (bCleanComments) 385 (*it3)->setComment(""); 386 ++it3; 387 } 388 else 389 { 390 // The config-value doesn't exist 391 delete (*it3); 392 (*it1)->entries_.erase(it3++); 393 } 394 } 395 ++it1; 396 } 397 else 398 { 399 // The section doesn't exist 400 delete (*it1); 401 this->sections_.erase(it1++); 402 } 403 } 404 405 // Save the file 406 this->save(); 332 COUT(4) << "Saved config file \"" << filename << "\"." << std::endl; 407 333 } 408 334 … … 414 340 } 415 341 416 ConfigFileSection* ConfigFile::getSection(const std::string& section) 342 const std::string& ConfigFile::getOrCreateValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString) 343 { 344 const std::string& output = this->getOrCreateSection(section)->getOrCreateValue(name, fallback, bString); 345 this->saveIfUpdated(); 346 return output; 347 } 348 349 const std::string& ConfigFile::getOrCreateValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString) 350 { 351 const std::string& output = this->getOrCreateSection(section)->getOrCreateValue(name, index, fallback, bString); 352 this->saveIfUpdated(); 353 return output; 354 } 355 356 void ConfigFile::deleteVectorEntries(const std::string& section, const std::string& name, unsigned int startindex) 357 { 358 if (ConfigFileSection* sectionPtr = this->getSection(section)) 359 { 360 sectionPtr->deleteVectorEntries(name, startindex); 361 this->save(); 362 } 363 } 364 365 ConfigFileSection* ConfigFile::getSection(const std::string& section) const 366 { 367 for (std::list<ConfigFileSection*>::const_iterator it = this->sections_.begin(); it != this->sections_.end(); ++it) 368 if ((*it)->getName() == section) 369 return (*it); 370 return NULL; 371 } 372 373 ConfigFileSection* ConfigFile::getOrCreateSection(const std::string& section) 417 374 { 418 375 for (std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); ++it) … … 445 402 } 446 403 447 void ConfigFile::updateConfigValues() 448 { 449 if (this->type_ == ConfigFileType::Settings) 450 { 451 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin(); it != Identifier::getStringIdentifierMapEnd(); ++it) 452 { 453 if (it->second->hasConfigValues()) 404 405 //////////////////////// 406 // SettingsConfigFile // 407 //////////////////////// 408 409 SettingsConfigFile* SettingsConfigFile::singletonPtr_s = 0; 410 411 SettingsConfigFile::SettingsConfigFile(const std::string& filename) 412 : ConfigFile(filename) 413 { 414 ConsoleCommand* command = createConsoleCommand(createFunctor(&ConfigFile::load, this), "reloadSettings"); 415 CommandExecutor::addConsoleCommandShortcut(command); 416 command = createConsoleCommand(createFunctor(&SettingsConfigFile::setFilename, this), "setSettingsFile"); 417 CommandExecutor::addConsoleCommandShortcut(command); 418 command = createConsoleCommand(createFunctor(&SettingsConfigFile::config, this), "config"); 419 CommandExecutor::addConsoleCommandShortcut(command).argumentCompleter(0, autocompletion::settingssections()).argumentCompleter(1, autocompletion::settingsentries()).argumentCompleter(2, autocompletion::settingsvalue()); 420 command = createConsoleCommand(createFunctor(&SettingsConfigFile::tconfig, this), "tconfig"); 421 CommandExecutor::addConsoleCommandShortcut(command).argumentCompleter(0, autocompletion::settingssections()).argumentCompleter(1, autocompletion::settingsentries()).argumentCompleter(2, autocompletion::settingsvalue()); 422 command = createConsoleCommand(createFunctor(&SettingsConfigFile::getConfig, this), "getConfig"); 423 CommandExecutor::addConsoleCommandShortcut(command).argumentCompleter(0, autocompletion::settingssections()).argumentCompleter(1, autocompletion::settingsentries()); 424 } 425 426 SettingsConfigFile::~SettingsConfigFile() 427 { 428 } 429 430 void SettingsConfigFile::load() 431 { 432 ConfigFile::load(); 433 this->updateConfigValues(); 434 } 435 436 void SettingsConfigFile::setFilename(const std::string& filename) 437 { 438 ConfigFileManager::getInstance().setFilename(ConfigFileType::Settings, filename); 439 } 440 441 void SettingsConfigFile::addConfigValueContainer(ConfigValueContainer* container) 442 { 443 if (container == NULL) 444 return; 445 std::pair<std::string, ConfigValueContainer*> second(getLowercase(container->getName()), container); 446 this->containers_.insert(std::make_pair(getLowercase(container->getSectionName()), second)); 447 this->sectionNames_.insert(container->getSectionName()); 448 } 449 450 void SettingsConfigFile::removeConfigValueContainer(ConfigValueContainer* container) 451 { 452 if (container == NULL) 453 return; 454 const std::string& sectionLC = getLowercase(container->getSectionName()); 455 ContainerMap::iterator upper = this->containers_.upper_bound(sectionLC); 456 for (ContainerMap::iterator it = this->containers_.lower_bound(sectionLC); it != upper; ++it) 457 { 458 if (it->second.second == container) 459 { 460 // Remove entry from section name set this was the last container for that section 461 if (upper == this->containers_.lower_bound(sectionLC)) 462 this->sectionNames_.erase(container->getSectionName()); 463 this->containers_.erase(it); 464 break; 465 } 466 } 467 } 468 469 void SettingsConfigFile::updateConfigValues() 470 { 471 for (ContainerMap::const_iterator it = this->containers_.begin(); it != this->containers_.end(); ++it) 472 { 473 it->second.second->update(); 474 it->second.second->getIdentifier()->updateConfigValues(); 475 } 476 } 477 478 void SettingsConfigFile::clean(bool bCleanComments) 479 { 480 for (std::list<ConfigFileSection*>::iterator itSection = this->sections_.begin(); itSection != this->sections_.end(); ) 481 { 482 const std::string& sectionLC = getLowercase((*itSection)->getName()); 483 ContainerMap::const_iterator lower = this->containers_.lower_bound(sectionLC); 484 ContainerMap::const_iterator upper = this->containers_.upper_bound(sectionLC); 485 if (lower != upper) 486 { 487 // The section exists, delete comment 488 if (bCleanComments) 489 (*itSection)->setComment(""); 490 for (std::list<ConfigFileEntry*>::iterator itEntry = (*itSection)->entries_.begin(); itEntry != (*itSection)->entries_.end(); ) 454 491 { 455 for (std::map<std::string, ConfigValueContainer*>::const_iterator it2 = it->second->getConfigValueMapBegin(); it2 != it->second->getConfigValueMapEnd(); ++it2) 456 it2->second->update(); 457 458 it->second->updateConfigValues(); 492 const std::string& entryLC = getLowercase((*itEntry)->getName()); 493 bool bFound = false; 494 for (ContainerMap::const_iterator itContainer = lower; itContainer != upper; ++itContainer) 495 { 496 if (itContainer->second.first == entryLC) 497 { 498 // The config-value exists, delete comment 499 if (bCleanComments) 500 (*itEntry)->setComment(""); 501 ++itEntry; 502 bFound = true; 503 break; 504 } 505 } 506 if (!bFound) 507 { 508 // The config-value doesn't exist 509 delete (*itEntry); 510 (*itSection)->entries_.erase(itEntry++); 511 } 459 512 } 460 } 461 } 513 ++itSection; 514 } 515 else 516 { 517 // The section doesn't exist 518 delete (*itSection); 519 this->sections_.erase(itSection++); 520 } 521 } 522 523 // Save the file 524 this->save(); 525 } 526 527 bool SettingsConfigFile::config(const std::string& section, const std::string& entry, const std::string& value) 528 { 529 return this->configImpl(section, entry, value, &ConfigValueContainer::set); 530 } 531 532 bool SettingsConfigFile::tconfig(const std::string& section, const std::string& entry, const std::string& value) 533 { 534 return this->configImpl(section, entry, value, &ConfigValueContainer::tset); 535 } 536 537 bool SettingsConfigFile::configImpl(const std::string& section, const std::string& entry, const std::string& value, bool (ConfigValueContainer::*function)(const MultiType&)) 538 { 539 const std::string& sectionLC = getLowercase(section); 540 const std::string& entryLC = getLowercase(entry); 541 ContainerMap::iterator upper = this->containers_.upper_bound(sectionLC); 542 for (ContainerMap::iterator it = this->containers_.lower_bound(sectionLC); it != upper; ++it) 543 { 544 // Note: Config value vectors cannot be supported 545 if (it->second.first == entryLC && !it->second.second->isVector()) 546 { 547 return (it->second.second->*function)(value); 548 } 549 } 550 return false; 551 } 552 553 std::string SettingsConfigFile::getConfig(const std::string& section, const std::string& entry) 554 { 555 const std::string& sectionLC = getLowercase(section); 556 const std::string& entryLC = getLowercase(entry); 557 ContainerMap::iterator upper = this->containers_.upper_bound(sectionLC); 558 for (ContainerMap::iterator it = this->containers_.lower_bound(sectionLC); it != upper; ++it) 559 { 560 // Note: Config value vectors cannot be supported 561 if (it->second.first == entryLC && ! it->second.second->isVector()) 562 { 563 std::string value; 564 it->second.second->getValue<std::string, OrxonoxClass>(&value, NULL); 565 return value; 566 } 567 } 568 return ""; 462 569 } 463 570 … … 469 576 ConfigFileManager* ConfigFileManager::singletonPtr_s = 0; 470 577 471 std::string ConfigFileManager::DEFAULT_CONFIG_FILE = "default.ini";472 473 578 ConfigFileManager::ConfigFileManager() 474 : mininmalFreeType_(ConfigFileType::numberOfReservedTypes)475 {579 { 580 this->configFiles_.assign(NULL); 476 581 } 477 582 478 583 ConfigFileManager::~ConfigFileManager() 479 584 { 480 for (std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ) 481 delete (it++)->second; 482 } 483 484 void ConfigFileManager::setFilename(ConfigFileType type, const std::string& filename) 485 { 486 std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.find(type); 487 if (it != this->configFiles_.end()) 488 { 489 assert(it->second); 490 delete it->second; 491 } 492 this->configFiles_[type] = new ConfigFile(filename, type); 493 this->load(type); 494 } 495 496 void ConfigFileManager::load() 497 { 498 for (std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it) 499 it->second->load(); 500 } 501 502 void ConfigFileManager::save() 503 { 504 for (std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it) 505 it->second->save(); 506 } 507 508 void ConfigFileManager::clean(bool bCleanComments) 509 { 510 for (std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it) 511 this->clean(it->first, bCleanComments); 512 } 513 514 void ConfigFileManager::load(ConfigFileType type) 515 { 516 this->getFile(type)->load(); 517 } 518 519 void ConfigFileManager::save(ConfigFileType type) 520 { 521 this->getFile(type)->save(); 522 } 523 524 void ConfigFileManager::saveAs(ConfigFileType type, const std::string& saveFilename) 525 { 526 this->getFile(type)->saveAs(saveFilename); 527 } 528 529 void ConfigFileManager::clean(ConfigFileType type, bool bCleanComments) 530 { 531 this->getFile(type)->clean(bCleanComments); 532 } 533 534 void ConfigFileManager::updateConfigValues() 535 { 536 for (std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it) 537 it->second->updateConfigValues(); 538 } 539 540 void ConfigFileManager::updateConfigValues(ConfigFileType type) 541 { 542 this->getFile(type)->updateConfigValues(); 543 } 544 545 const std::string& ConfigFileManager::getFilename(ConfigFileType type) 546 { 547 std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.find(type); 548 if (it != this->configFiles_.end()) 549 return it->second->getFilename(); 550 else 551 return BLANKSTRING; 552 } 553 554 ConfigFile* ConfigFileManager::getFile(ConfigFileType type) 555 { 556 std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.find(type); 557 if (it != this->configFiles_.end()) 558 return it->second; 559 else 560 { 561 COUT(1) << "ConfigFileManager: Can't find a config file for type with ID " << static_cast<int>(type) << std::endl; 562 COUT(1) << "Using " << DEFAULT_CONFIG_FILE << " file." << std::endl; 563 this->setFilename(type, DEFAULT_CONFIG_FILE); 564 return getFile(type); 565 } 585 for (boost::array<ConfigFile*, 3>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it) 586 if (*it) 587 delete (*it); 588 } 589 590 void ConfigFileManager::setFilename(ConfigFileType::Value type, const std::string& filename) 591 { 592 if (this->getConfigFile(type)) 593 delete this->configFiles_[type]; 594 // Create and load config file 595 switch (type) 596 { 597 case ConfigFileType::Settings: 598 this->configFiles_[type] = new SettingsConfigFile(filename); 599 break; 600 case ConfigFileType::JoyStickCalibration: 601 case ConfigFileType::CommandHistory: 602 this->configFiles_[type] = new ConfigFile(filename); 603 break; 604 } 605 this->configFiles_[type]->load(); 566 606 } 567 607 } -
code/branches/gamestate/src/libraries/core/ConfigFileManager.h
r6427 r6432 32 32 #include "CorePrereqs.h" 33 33 34 #include <cassert>35 #include <string>36 34 #include <list> 37 35 #include <map> 38 39 #include "util/OrxEnum.h" 36 #include <set> 37 #include <string> 38 #include <boost/array.hpp> 39 40 40 #include "util/Singleton.h" 41 41 42 // tolua_begin 43 namespace orxonox 44 { 45 // tolua_end 46 // Use int as config file type to have an arbitrary number of files 47 struct ConfigFileType : OrxEnum<ConfigFileType> 48 { 49 OrxEnumConstructors(ConfigFileType); 50 51 static const int NoType = 0; 52 static const int Settings = 1; 53 static const int JoyStickCalibration = 2; 54 static const int CommandHistory = 3; 55 56 static const int numberOfReservedTypes = 1024; 57 }; 58 59 _CoreExport bool config(const std::string& classname, const std::string& varname, const std::string& value); // tolua_export 60 _CoreExport const std::string& getConfig(const std::string& classname, const std::string& varname); // tolua_export 61 _CoreExport bool tconfig(const std::string& classname, const std::string& varname, const std::string& value); 62 _CoreExport void reloadConfig(); 63 _CoreExport void saveConfig(); 64 _CoreExport void cleanConfig(); 65 _CoreExport void loadSettings(const std::string& filename); 66 42 namespace orxonox // tolua_export 43 { // tolua_export 67 44 68 45 ///////////////////// … … 196 173 { 197 174 friend class ConfigFile; 175 friend class SettingsConfigFile; 198 176 199 177 public: … … 212 190 213 191 inline void setValue(const std::string& name, const std::string& value, bool bString) 214 { this->getEntry(name, value, bString)->setValue(value); } 215 inline const std::string& getValue(const std::string& name, const std::string& fallback, bool bString) 216 { return this->getEntry(name, fallback, bString)->getValue(); } 192 { this->getOrCreateEntry(name, value, bString)->setValue(value); } 193 inline const std::string& getValue(const std::string& name, const std::string& fallback, bool bString) const 194 { 195 ConfigFileEntry* entry = this->getEntry(name); 196 return (entry ? entry->getValue() : BLANKSTRING); 197 } 198 inline const std::string& getOrCreateValue(const std::string& name, const std::string& fallback, bool bString) 199 { return this->getOrCreateEntry(name, fallback, bString)->getValue(); } 217 200 218 201 inline void setValue(const std::string& name, unsigned int index, const std::string& value, bool bString) 219 { this->getEntry(name, index, value, bString)->setValue(value); } 220 inline const std::string& getValue(const std::string& name, unsigned int index, const std::string& fallback, bool bString) 221 { return this->getEntry(name, index, fallback, bString)->getValue(); } 202 { this->getOrCreateEntry(name, index, value, bString)->setValue(value); } 203 inline const std::string& getValue(const std::string& name, unsigned int index) const 204 { 205 ConfigFileEntry* entry = this->getEntry(name, index); 206 return (entry ? entry->getValue() : BLANKSTRING); 207 } 208 inline const std::string& getOrCreateValue(const std::string& name, unsigned int index, const std::string& fallback, bool bString) 209 { return this->getOrCreateEntry(name, index, fallback, bString)->getValue(); } 222 210 223 211 void deleteVectorEntries(const std::string& name, unsigned int startindex = 0); 224 unsigned int getVectorSize(const std::string& name) ;212 unsigned int getVectorSize(const std::string& name) const; 225 213 226 214 std::string getFileEntry() const; … … 234 222 { return this->entries_.end(); } 235 223 236 std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, const std::string& fallback, bool bString); 237 std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString); 238 239 inline ConfigFileEntry* getEntry(const std::string& name, const std::string& fallback, bool bString) 240 { return (*this->getEntryIterator(name, fallback, bString)); } 241 inline ConfigFileEntry* getEntry(const std::string& name, unsigned int index, const std::string& fallback, bool bString) 242 { return (*this->getEntryIterator(name, index, fallback, bString)); } 224 std::list<ConfigFileEntry*>::const_iterator getEntryIterator(const std::string& name) const; 225 std::list<ConfigFileEntry*>::iterator getOrCreateEntryIterator(const std::string& name, const std::string& fallback, bool bString); 226 std::list<ConfigFileEntry*>::const_iterator getEntryIterator(const std::string& name, unsigned int index) const; 227 std::list<ConfigFileEntry*>::iterator getOrCreateEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString); 228 229 inline ConfigFileEntry* getEntry(const std::string& name) const 230 { return (*this->getEntryIterator(name)); } 231 inline ConfigFileEntry* getOrCreateEntry(const std::string& name, const std::string& fallback, bool bString) 232 { return (*this->getOrCreateEntryIterator(name, fallback, bString)); } 233 inline ConfigFileEntry* getEntry(const std::string& name, unsigned int index) const 234 { return (*this->getEntryIterator(name, index)); } 235 inline ConfigFileEntry* getOrCreateEntry(const std::string& name, unsigned int index, const std::string& fallback, bool bString) 236 { return (*this->getOrCreateEntryIterator(name, index, fallback, bString)); } 243 237 244 238 std::string name_; … … 255 249 { 256 250 public: 257 inline ConfigFile(const std::string& filename, ConfigFileType type) 258 : filename_(filename) 259 , type_(type) 260 , bUpdated_(false) 261 { } 262 ~ConfigFile(); 263 264 void load(bool bCreateIfNotExisting = true); 265 void save() const; 266 void saveAs(const std::string& filename); 267 void clean(bool bCleanComments = false); 268 void clear(); 269 270 const std::string& getFilename() { return this->filename_; } 251 ConfigFile(const std::string& filename); 252 virtual ~ConfigFile(); 253 254 virtual void load(); 255 virtual void save() const; 256 virtual void saveAs(const std::string& filename) const; 257 virtual void clear(); 258 259 inline const std::string& getFilename() 260 { return this->filename_; } 271 261 272 262 inline void setValue(const std::string& section, const std::string& name, const std::string& value, bool bString) 273 { this->getSection(section)->setValue(name, value, bString); this->save(); } 274 inline const std::string& getValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString) 275 { const std::string& output = this->getSection(section)->getValue(name, fallback, bString); this->saveIfUpdated(); return output; } 263 { 264 this->getOrCreateSection(section)->setValue(name, value, bString); 265 this->save(); 266 } 267 inline const std::string& getValue(const std::string& section, const std::string& name, bool bString) const 268 { 269 ConfigFileSection* sectionPtr = this->getSection(section); 270 return (sectionPtr ? sectionPtr->getValue(name, bString) : BLANKSTRING); 271 } 272 const std::string& getOrCreateValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString); 276 273 277 274 inline void setValue(const std::string& section, const std::string& name, unsigned int index, const std::string& value, bool bString) 278 { this->getSection(section)->setValue(name, index, value, bString); this->save(); } 279 inline const std::string& getValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString) 280 { const std::string& output = this->getSection(section)->getValue(name, index, fallback, bString); this->saveIfUpdated(); return output; } 281 282 inline void deleteVectorEntries(const std::string& section, const std::string& name, unsigned int startindex = 0) 283 { this->getSection(section)->deleteVectorEntries(name, startindex); } 284 inline unsigned int getVectorSize(const std::string& section, const std::string& name) 285 { return this->getSection(section)->getVectorSize(name); } 286 275 { 276 this->getSection(section)->setValue(name, index, value, bString); 277 this->save(); 278 } 279 inline const std::string& getValue(const std::string& section, const std::string& name, unsigned int index) const 280 { 281 ConfigFileSection* sectionPtr = this->getSection(section); 282 return (sectionPtr ? sectionPtr->getValue(name, index) : BLANKSTRING); 283 } 284 const std::string& getOrCreateValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString); 285 286 void deleteVectorEntries(const std::string& section, const std::string& name, unsigned int startindex = 0); 287 inline unsigned int getVectorSize(const std::string& section, const std::string& name) const 288 { 289 ConfigFileSection* sectionPtr = this->getSection(section); 290 return (sectionPtr ? sectionPtr->getVectorSize(name) : 0); 291 } 292 293 protected: 294 ConfigFileSection* getSection(const std::string& section) const; 295 ConfigFileSection* getOrCreateSection(const std::string& section); 296 297 std::list<ConfigFileSection*> sections_; 298 299 private: 300 void saveIfUpdated(); 301 const std::string filename_; 302 bool bUpdated_; 303 }; 304 305 306 //////////////////////// 307 // SettingsConfigFile // 308 //////////////////////// 309 class _CoreExport SettingsConfigFile // tolua_export 310 : public ConfigFile, public Singleton<SettingsConfigFile> 311 { // tolua_export 312 friend class Singleton<SettingsConfigFile>; 313 314 public: 315 typedef std::multimap<std::string, std::pair<std::string, ConfigValueContainer*> > ContainerMap; 316 317 SettingsConfigFile(const std::string& filename); 318 ~SettingsConfigFile(); 319 320 void load(); // tolua_export 321 void setFilename(const std::string& filename); // tolua_export 322 void clean(bool bCleanComments = false); // tolua_export 323 324 bool config(const std::string& section, const std::string& entry, const std::string& value); // tolua_export 325 bool tconfig(const std::string& section, const std::string& entry, const std::string& value); // tolua_export 326 std::string getConfig(const std::string& section, const std::string& entry); // tolua_export 327 328 void addConfigValueContainer(ConfigValueContainer* container); 329 void removeConfigValueContainer(ConfigValueContainer* container); 330 331 inline const std::set<std::string>& getSectionNames() 332 { return this->sectionNames_; } 333 inline ContainerMap::const_iterator getContainerLowerBound(const std::string section) 334 { return this->containers_.lower_bound(section); } 335 inline ContainerMap::const_iterator getContainerUpperBound(const std::string section) 336 { return this->containers_.upper_bound(section); } 337 338 static SettingsConfigFile& getInstance() { return Singleton<SettingsConfigFile>::getInstance(); } // tolua_export 339 340 private: 287 341 void updateConfigValues(); 288 289 private: 290 ConfigFileSection* getSection(const std::string& section); 291 void saveIfUpdated(); 292 293 std::string filename_; 294 ConfigFileType type_; 295 std::list<ConfigFileSection*> sections_; 296 bool bUpdated_; 297 }; 342 bool configImpl(const std::string& section, const std::string& entry, const std::string& value, bool (ConfigValueContainer::*function)(const MultiType&)); 343 344 ContainerMap containers_; 345 std::set<std::string> sectionNames_; 346 static SettingsConfigFile* singletonPtr_s; 347 }; // tolua_export 298 348 299 349 … … 308 358 ~ConfigFileManager(); 309 359 310 void load(); 311 void save(); 312 void clean(bool bCleanComments = false); 313 314 void setFilename(ConfigFileType type, const std::string& filename); 315 const std::string& getFilename(ConfigFileType type); 316 317 ConfigFileType getNewConfigFileType() { return mininmalFreeType_++; } 318 319 void load(ConfigFileType type); 320 void save(ConfigFileType type); 321 void saveAs(ConfigFileType type, const std::string& saveFilename); 322 void clean(ConfigFileType type, bool bCleanComments = false); 323 324 inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& value, bool bString) 325 { this->getFile(type)->setValue(section, name, value, bString); } 326 inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& fallback, bool bString) 327 { return this->getFile(type)->getValue(section, name, fallback, bString); } 328 329 inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& value, bool bString) 330 { this->getFile(type)->setValue(section, name, index, value, bString); } 331 inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString) 332 { return this->getFile(type)->getValue(section, name, index, fallback, bString); } 333 334 inline void deleteVectorEntries(ConfigFileType type, const std::string& section, const std::string& name, unsigned int startindex = 0) 335 { this->getFile(type)->deleteVectorEntries(section, name, startindex); } 336 inline unsigned int getVectorSize(ConfigFileType type, const std::string& section, const std::string& name) 337 { return this->getFile(type)->getVectorSize(section, name); } 338 339 void updateConfigValues(); 340 void updateConfigValues(ConfigFileType type); 341 342 static std::string DEFAULT_CONFIG_FILE; 360 void setFilename(ConfigFileType::Value type, const std::string& filename); 361 362 inline ConfigFile* getConfigFile(ConfigFileType::Value type) 363 { 364 // Check array bounds 365 return configFiles_.at(type); 366 } 343 367 344 368 private: 345 369 ConfigFileManager(const ConfigFileManager&); 346 370 347 ConfigFile* getFile(ConfigFileType type); 348 349 std::map<ConfigFileType, ConfigFile*> configFiles_; 350 unsigned int mininmalFreeType_; 351 371 boost::array<ConfigFile*, 3> configFiles_; 352 372 static ConfigFileManager* singletonPtr_s; 353 373 }; -
code/branches/gamestate/src/libraries/core/ConfigValueContainer.cc
r5738 r6432 36 36 #include "util/Convert.h" 37 37 #include "util/SubString.h" 38 #include "ConfigFileManager.h" 38 39 #include "Language.h" 39 40 … … 43 44 44 45 /** 45 @brief Initializes the ConfigValueContainer with default values.46 */ 47 void ConfigValueContainer::init(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname)46 @brief Initializes the ConfigValueContainer with default values. 47 */ 48 void ConfigValueContainer::init(ConfigFileType::Value type, Identifier* identifier, const std::string& sectionname, const std::string& varname) 48 49 { 49 50 this->type_ = type; … … 55 56 this->bDoInitialCallback_ = false; 56 57 this->bAddedDescription_ = false; 58 59 // Register containers for general settings 60 if (this->type_ == ConfigFileType::Settings) 61 SettingsConfigFile::getInstance().addConfigValueContainer(this); 57 62 } 58 63 … … 78 83 for (unsigned int i = 0; i < this->valueVector_.size(); i++) 79 84 { 80 ConfigFileManager::getInstance().get Value(this->type_,this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_Type::String));85 ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_Type::String)); 81 86 this->defvalueStringVector_.push_back(this->valueVector_[i]); 82 87 } … … 92 97 if (this->callback_) 93 98 delete this->callback_; 99 100 // Unregister general settings containers 101 if (this->type_ == ConfigFileType::Settings && SettingsConfigFile::exists()) 102 SettingsConfigFile::getInstance().removeConfigValueContainer(this); 94 103 } 95 104 … … 109 118 if (this->tset(input)) 110 119 { 111 ConfigFileManager::getInstance(). setValue(this->type_,this->sectionname_, this->varname_, input, this->value_.isType(MT_Type::String));120 ConfigFileManager::getInstance().getConfigFile(this->type_)->setValue(this->sectionname_, this->varname_, input, this->value_.isType(MT_Type::String)); 112 121 return true; 113 122 } … … 128 137 if (this->tset(index, input)) 129 138 { 130 ConfigFileManager::getInstance(). setValue(this->type_,this->sectionname_, this->varname_, index, input, this->value_.isType(MT_Type::String));139 ConfigFileManager::getInstance().getConfigFile(this->type_)->setValue(this->sectionname_, this->varname_, index, input, this->value_.isType(MT_Type::String)); 131 140 return true; 132 141 } … … 228 237 this->valueVector_.erase(this->valueVector_.begin() + index); 229 238 for (unsigned int i = index; i < this->valueVector_.size(); i++) 230 ConfigFileManager::getInstance(). setValue(this->type_,this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_Type::String));231 ConfigFileManager::getInstance(). deleteVectorEntries(this->type_,this->sectionname_, this->varname_, this->valueVector_.size());239 ConfigFileManager::getInstance().getConfigFile(this->type_)->setValue(this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_Type::String)); 240 ConfigFileManager::getInstance().getConfigFile(this->type_)->deleteVectorEntries(this->sectionname_, this->varname_, this->valueVector_.size()); 232 241 233 242 return true; … … 253 262 if (!this->set(i, this->defvalueStringVector_[i])) 254 263 success = false; 255 ConfigFileManager::getInstance(). deleteVectorEntries(this->type_,this->sectionname_, this->varname_, this->defvalueStringVector_.size());264 ConfigFileManager::getInstance().getConfigFile(this->type_)->deleteVectorEntries(this->sectionname_, this->varname_, this->defvalueStringVector_.size()); 256 265 return success; 257 266 } … … 264 273 { 265 274 if (!this->bIsVector_) 266 this->value_ = ConfigFileManager::getInstance().get Value(this->type_,this->sectionname_, this->varname_, this->defvalueString_, this->value_.isType(MT_Type::String));275 this->value_ = ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, this->defvalueString_, this->value_.isType(MT_Type::String)); 267 276 else 268 277 { 269 278 this->valueVector_.clear(); 270 unsigned int vectorSize = ConfigFileManager::getInstance().get VectorSize(this->type_,this->sectionname_, this->varname_);279 unsigned int vectorSize = ConfigFileManager::getInstance().getConfigFile(this->type_)->getVectorSize(this->sectionname_, this->varname_); 271 280 for (unsigned int i = 0; i < vectorSize; i++) 272 281 { 273 282 if (i < this->defvalueStringVector_.size()) 274 283 { 275 this->value_ = ConfigFileManager::getInstance().get Value(this->type_,this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isType(MT_Type::String));284 this->value_ = ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isType(MT_Type::String)); 276 285 } 277 286 else 278 287 { 279 this->value_ = ConfigFileManager::getInstance().get Value(this->type_,this->sectionname_, this->varname_, i, MultiType(), this->value_.isType(MT_Type::String));288 this->value_ = ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, i, MultiType(), this->value_.isType(MT_Type::String)); 280 289 } 281 290 -
code/branches/gamestate/src/libraries/core/ConfigValueContainer.h
r6417 r6432 50 50 51 51 #include "util/MultiType.h" 52 #include "ConfigFileManager.h"53 52 #include "Identifier.h" 54 53 … … 108 107 */ 109 108 template <class D, class V> 110 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname, const D& defvalue, const V& value)109 ConfigValueContainer(ConfigFileType::Value type, Identifier* identifier, const std::string& sectionname, const std::string& varname, const D& defvalue, const V& value) 111 110 { 112 111 this->init(type, identifier, sectionname, varname); … … 122 121 */ 123 122 template <class D, class V> 124 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname, const std::vector<D>& defvalue, const std::vector<V>& value)123 ConfigValueContainer(ConfigFileType::Value type, Identifier* identifier, const std::string& sectionname, const std::string& varname, const std::vector<D>& defvalue, const std::vector<V>& value) 125 124 { 126 125 this->init(type, identifier, sectionname, varname); … … 217 216 inline const std::string& getName() const 218 217 { return this->varname_; } 219 /** @brief Retu ns the name of the section this config value is in. */218 /** @brief Returns the name of the section this config value is in. */ 220 219 inline const std::string& getSectionName() const 221 220 { return this->sectionname_; } 221 /** @brief Returns the associated identifier (can be NULL). */ 222 inline Identifier* getIdentifier() const 223 { return this->identifier_; } 222 224 /** @brief Returns true if this config-value is a vector */ 223 225 inline bool isVector() const … … 271 273 272 274 private: 273 void init(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname);275 void init(ConfigFileType::Value type, Identifier* identifier, const std::string& sectionname, const std::string& varname); 274 276 void initValue(const MultiType& defvalue); 275 277 void initVector(); … … 278 280 bool bIsVector_; //!< True if the container contains a std::vector 279 281 280 ConfigFileType 282 ConfigFileType::Value type_; //!< The type of the corresponding config-file 281 283 Identifier* identifier_; //!< The identifier of the class 282 284 std::string sectionname_; //!< The name of the class the variable belongs to -
code/branches/gamestate/src/libraries/core/ConfigValueIncludes.h
r6423 r6432 40 40 #include "Identifier.h" 41 41 #include "ConfigValueContainer.h" 42 #include "ConfigFileManager.h"43 42 44 43 namespace orxonox … … 61 60 */ 62 61 template <class T, class D, class V> 63 inline ConfigValueContainer& setConfigValueGeneric(T* object, V* variable, ConfigFileType type, const std::string& sectionName, const std::string& entryName, const D& defaultValue)62 inline ConfigValueContainer& setConfigValueGeneric(T* object, V* variable, ConfigFileType::Value type, const std::string& sectionName, const std::string& entryName, const D& defaultValue) 64 63 { 65 64 ConfigValueContainer* container = ClassIdentifier<T>::getIdentifier()->getConfigValueContainer(entryName); -
code/branches/gamestate/src/libraries/core/CorePrereqs.h
r6105 r6432 84 84 } 85 85 86 namespace ConfigFileType 87 { 88 enum Value 89 { 90 Settings, 91 JoyStickCalibration, 92 CommandHistory 93 // Don't forget to adjust the array size in the ConfigFileManager when adding a new entry here! 94 }; 95 } 96 86 97 namespace KeybindMode 87 98 { … … 124 135 class ConfigFileManager; 125 136 class ConfigFileSection; 126 struct ConfigFileType;127 137 class ConfigValueContainer; 128 138 class ConsoleCommand; … … 172 182 class PathConfig; 173 183 struct ResourceInfo; 184 class SettingsConfigFile; 174 185 class Shell; 175 186 class ShellListener; -
code/branches/gamestate/src/libraries/core/Identifier.cc
r6417 r6432 416 416 this->bHasConfigValues_ = true; 417 417 this->configValues_[varname] = container; 418 this->configValues_LC_[getLowercase(varname)] = container;419 418 } 420 419 … … 428 427 std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_.find(varname); 429 428 if (it != configValues_.end()) 430 return it->second;431 else432 return 0;433 }434 435 /**436 @brief Returns the ConfigValueContainer of a variable, given by the string of its name in lowercase.437 @param varname The name of the variable in lowercase438 @return The ConfigValueContainer439 */440 ConfigValueContainer* Identifier::getLowercaseConfigValueContainer(const std::string& varname)441 {442 std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname);443 if (it != configValues_LC_.end())444 429 return it->second; 445 430 else -
code/branches/gamestate/src/libraries/core/Identifier.h
r6417 r6432 200 200 inline bool hasConfigValues() const { return this->bHasConfigValues_; } 201 201 202 /** @brief Returns the map that stores all config values. @return The const_iterator */203 inline const std::map<std::string, ConfigValueContainer*>& getConfigValueMap() const { return this->configValues_; }204 /** @brief Returns a const_iterator to the beginning of the map that stores all config values. @return The const_iterator */205 inline std::map<std::string, ConfigValueContainer*>::const_iterator getConfigValueMapBegin() const { return this->configValues_.begin(); }206 /** @brief Returns a const_iterator to the end of the map that stores all config values. @return The const_iterator */207 inline std::map<std::string, ConfigValueContainer*>::const_iterator getConfigValueMapEnd() const { return this->configValues_.end(); }208 209 /** @brief Returns the map that stores all config values with their names in lowercase. @return The const_iterator */210 inline const std::map<std::string, ConfigValueContainer*>& getLowercaseConfigValueMap() const { return this->configValues_LC_; }211 /** @brief Returns a const_iterator to the beginning of the map that stores all config values with their names in lowercase. @return The const_iterator */212 inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapBegin() const { return this->configValues_LC_.begin(); }213 /** @brief Returns a const_iterator to the end of the map that stores all config values with their names in lowercase. @return The const_iterator */214 inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapEnd() const { return this->configValues_LC_.end(); }215 216 202 void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container); 217 203 ConfigValueContainer* getConfigValueContainer(const std::string& varname); 218 ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname);219 204 220 205 … … 320 305 bool bHasConfigValues_; //!< True if this class has at least one assigned config value 321 306 std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer 322 std::map<std::string, ConfigValueContainer*> configValues_LC_; //!< A map to link the string of configurable variables with their ConfigValueContainer323 307 324 308 bool bHasConsoleCommands_; //!< True if this class has at least one assigned console command -
code/branches/gamestate/src/libraries/core/Shell.cc
r6417 r6432 34 34 #include "CommandExecutor.h" 35 35 #include "CoreIncludes.h" 36 #include "ConfigFileManager.h" 36 37 #include "ConfigValueIncludes.h" 37 38 #include "ConsoleCommand.h" -
code/branches/gamestate/src/libraries/core/Shell.h
r6417 r6432 39 39 #include "util/OutputHandler.h" 40 40 #include "OrxonoxClass.h" 41 #include "ConfigFileManager.h"42 41 #include "input/InputBuffer.h" 43 42 -
code/branches/gamestate/src/libraries/core/input/Button.cc
r6428 r6432 42 42 #include "core/CommandEvaluation.h" 43 43 #include "core/CommandExecutor.h" 44 #include "core/ConfigFileManager.h" 44 45 45 46 namespace orxonox … … 81 82 } 82 83 83 void Button::readBinding(ConfigFile Type type)84 { 85 const std::string& binding = ConfigFileManager::getInstance().getValue(type,groupName_, name_, "", true);84 void Button::readBinding(ConfigFile* configFile) 85 { 86 const std::string& binding = configFile->getOrCreateValue(groupName_, name_, "", true); 86 87 this->parse(binding); 87 88 } 88 89 89 void Button::setBinding(ConfigFile Type type, const std::string& binding, bool bTemporary)90 void Button::setBinding(ConfigFile* configFile, const std::string& binding, bool bTemporary) 90 91 { 91 92 if (!bTemporary) 92 ConfigFileManager::getInstance().setValue(type,groupName_, name_, binding, true);93 configFile->setValue(groupName_, name_, binding, true); 93 94 this->parse(binding); 94 95 } -
code/branches/gamestate/src/libraries/core/input/Button.h
r6428 r6432 41 41 #include <vector> 42 42 #include "InputCommands.h" 43 #include "core/ConfigFileManager.h"44 43 45 44 namespace orxonox … … 53 52 virtual bool addParamCommand(ParamCommand* command) { return false; } 54 53 void parse(const std::string& binding); 55 void readBinding(ConfigFile Type type);56 void setBinding(ConfigFile Type type, const std::string& binding, bool bTemporary);54 void readBinding(ConfigFile* configFile); 55 void setBinding(ConfigFile* configFile, const std::string& binding, bool bTemporary); 57 56 bool execute(KeybindMode::Value mode, float abs = 1.0f, float rel = 1.0f); 58 57 -
code/branches/gamestate/src/libraries/core/input/JoyStick.cc
r6417 r6432 106 106 { 107 107 list.resize(size); 108 unsigned int configValueVectorSize = ConfigFileManager::getInstance().get VectorSize(ConfigFileType::JoyStickCalibration,sectionName, valueName);108 unsigned int configValueVectorSize = ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)->getVectorSize(sectionName, valueName); 109 109 if (configValueVectorSize > size) 110 110 configValueVectorSize = size; … … 112 112 for (unsigned int i = 0; i < configValueVectorSize; ++i) 113 113 { 114 list[i] = multi_cast<int>(ConfigFileManager::getInstance().get Value(115 ConfigFileType::JoyStickCalibration,sectionName, valueName, i, multi_cast<std::string>(defaultValue), false));114 list[i] = multi_cast<int>(ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration) 115 ->getOrCreateValue(sectionName, valueName, i, multi_cast<std::string>(defaultValue), false)); 116 116 } 117 117 … … 153 153 if (configMinValues_[i] == INT_MAX) 154 154 configMinValues_[i] = -32768; 155 ConfigFileManager::getInstance(). setValue(ConfigFileType::JoyStickCalibration,156 deviceName_, "MinValue", i, multi_cast<std::string>(configMinValues_[i]), false);155 ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration) 156 ->getOrCreateValue(deviceName_, "MinValue", i, multi_cast<std::string>(configMinValues_[i]), false); 157 157 158 158 // Maximum values 159 159 if (configMaxValues_[i] == INT_MIN) 160 160 configMaxValues_[i] = 32767; 161 ConfigFileManager::getInstance(). setValue(ConfigFileType::JoyStickCalibration,162 deviceName_, "MaxValue", i, multi_cast<std::string>(configMaxValues_[i]), false);161 ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration) 162 ->getOrCreateValue(deviceName_, "MaxValue", i, multi_cast<std::string>(configMaxValues_[i]), false); 163 163 164 164 // Middle values 165 ConfigFileManager::getInstance(). setValue(ConfigFileType::JoyStickCalibration,166 deviceName_, "ZeroValue", i, multi_cast<std::string>(configZeroValues_[i]), false);165 ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration) 166 ->getOrCreateValue(deviceName_, "ZeroValue", i, multi_cast<std::string>(configZeroValues_[i]), false); 167 167 } 168 168 -
code/branches/gamestate/src/libraries/core/input/KeyBinder.cc
r6428 r6432 49 49 : deriveTime_(0.0f) 50 50 , filename_(filename) 51 , configFile_(NULL) 51 52 { 52 53 mouseRelative_[0] = 0; … … 93 94 mouseAxes_[i].groupName_ = "MouseAxes"; 94 95 } 95 96 // We might not even load any bindings at all (KeyDetector for instance)97 this->configFile_ = ConfigFileType::NoType;98 96 99 97 // initialise joy sticks separatly to allow for reloading … … 163 161 164 162 // load the bindings if required 165 if (configFile_ != ConfigFileType::NoType)163 if (configFile_ != NULL) 166 164 { 167 165 for (unsigned int iDev = oldValue; iDev < joySticks_.size(); ++iDev) … … 249 247 COUT(3) << "KeyBinder: Loading key bindings..." << std::endl; 250 248 251 // Get a new ConfigFileType from the ConfigFileManager 252 this->configFile_ = ConfigFileManager::getInstance().getNewConfigFileType(); 253 254 ConfigFileManager::getInstance().setFilename(this->configFile_, this->filename_); 249 this->configFile_ = new ConfigFile(this->filename_); 250 this->configFile_->load(); 255 251 256 252 // Parse bindings and create the ConfigValueContainers if necessary -
code/branches/gamestate/src/libraries/core/input/KeyBinder.h
r6428 r6432 38 38 #include <boost/shared_ptr.hpp> 39 39 40 #include "core/ConfigFileManager.h"41 40 #include "InputHandler.h" 42 41 #include "Button.h" … … 157 156 //! Name of the file used in this KeyBinder (constant!) 158 157 const std::string filename_; 159 //! Config file used. ConfigFileType::NoTypein case of KeyDetector. Also indicates whether we've already loaded.160 ConfigFile TypeconfigFile_;158 //! Config file used. NULL in case of KeyDetector. Also indicates whether we've already loaded. 159 ConfigFile* configFile_; 161 160 162 161 private:
Note: See TracChangeset
for help on using the changeset viewer.