- Timestamp:
- Sep 7, 2010, 11:24:47 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/doc/src/libraries/core/ConfigFileManager.cc
r7284 r7373 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of ConfigFileManager and its helper classes. 32 */ 33 29 34 #include "ConfigFileManager.h" 30 35 … … 43 48 // ConfigFileEntryValue // 44 49 ////////////////////////// 45 50 /** 51 @brief Updates the string that will be stored in the file after one of it's components (name, value, comment) has changed. 52 */ 46 53 void ConfigFileEntryValue::update() 47 54 { … … 63 70 // ConfigFileEntryVectorValue // 64 71 //////////////////////////////// 72 /** 73 @brief Updates the string that will be stored in the file after one of it's components (name, value, index, comment) has changed. 74 */ 65 75 void ConfigFileEntryVectorValue::update() 66 76 { … … 73 83 // ConfigFileSection // 74 84 /////////////////////// 85 /** 86 @brief Destructor: Deletes all entries. 87 */ 75 88 ConfigFileSection::~ConfigFileSection() 76 89 { … … 79 92 } 80 93 94 /** 95 @brief Deletes all elements of a config vector if their index is greater or equal to @a startindex. 96 97 @param name The name of the vector 98 @param startindex The index of the first element that will be deleted 99 */ 81 100 void ConfigFileSection::deleteVectorEntries(const std::string& name, unsigned int startindex) 82 101 { … … 95 114 } 96 115 116 /** 117 @brief Returns the size of a config vector. 118 @param name The name of the vector 119 */ 97 120 unsigned int ConfigFileSection::getVectorSize(const std::string& name) const 98 121 { … … 108 131 } 109 132 133 /** 134 @brief Returns the title and comment of the section as it will be stored in the file. 135 */ 110 136 std::string ConfigFileSection::getFileEntry() const 111 137 { … … 116 142 } 117 143 144 /** 145 @brief Returns the entry with given name (or NULL if it doesn't exist). 146 147 @param name The name of the entry 148 */ 118 149 ConfigFileEntry* ConfigFileSection::getEntry(const std::string& name) const 119 150 { … … 126 157 } 127 158 159 /** 160 @brief Returns the entry of a vector element with given name and index (or NULL if it doesn't exist). 161 162 @param name The name of the vector 163 @param index The index of the element in the vector 164 */ 128 165 ConfigFileEntry* ConfigFileSection::getEntry(const std::string& name, unsigned int index) const 129 166 { … … 136 173 } 137 174 175 /** 176 @brief Returns the iterator to the entry with given name. If the entry doesn't exist, it is created using the fallback value. 177 178 @param name The name of the entry 179 @param fallback The value that will be used if the entry doesn't exist 180 @param bString If true, the value is treated as string which means some special treatment of special characters. 181 */ 138 182 std::list<ConfigFileEntry*>::iterator ConfigFileSection::getOrCreateEntryIterator(const std::string& name, const std::string& fallback, bool bString) 139 183 { … … 152 196 } 153 197 198 /** 199 @brief Returns the iterator to the entry of a vector element with given name and index. If the entry doesn't exist, it is created using the fallback value. 200 201 @param name The name of the vector 202 @param index The index of the element in the vector 203 @param fallback The value that will be used if the entry doesn't exist 204 @param bString If true, the value is treated as string which means some special treatment of special characters. 205 */ 154 206 std::list<ConfigFileEntry*>::iterator ConfigFileSection::getOrCreateEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString) 155 207 { … … 178 230 const char* ConfigFile::DEFAULT_CONFIG_FOLDER = "defaultConfig"; 179 231 232 /** 233 @brief Constructor: Initializes the config file. 234 @param filename The file-name of this config file 235 @param bCopyFallbackFile If true, the default config file is copied into the config-directory before loading the file 236 */ 180 237 ConfigFile::ConfigFile(const std::string& filename, bool bCopyFallbackFile) 181 238 : filename_(filename) … … 185 242 } 186 243 244 /** 245 @brief Destructor: Deletes all sections and entries. 246 */ 187 247 ConfigFile::~ConfigFile() 188 248 { … … 190 250 } 191 251 252 /** 253 @brief Loads the config file from the hard-disk and reads the sections and their values. 254 */ 192 255 void ConfigFile::load() 193 256 { … … 318 381 } 319 382 383 /** 384 @brief Writes the sections and values to the hard-disk. 385 */ 320 386 void ConfigFile::save() const 321 387 { … … 323 389 } 324 390 391 /** 392 @brief Writes the sections and values to a given file on the hard-disk. 393 */ 325 394 void ConfigFile::saveAs(const std::string& filename) const 326 395 { … … 354 423 } 355 424 425 /** 426 @brief Deletes all sections (which again delete all their values) and clears the list of sections. 427 */ 356 428 void ConfigFile::clear() 357 429 { … … 361 433 } 362 434 363 const std::string& ConfigFile::getOrCreateValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString) 364 { 365 const std::string& output = this->getOrCreateSection(section)->getOrCreateValue(name, fallback, bString); 366 this->saveIfUpdated(); 367 return output; 368 } 369 370 const std::string& ConfigFile::getOrCreateValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString) 371 { 372 const std::string& output = this->getOrCreateSection(section)->getOrCreateValue(name, index, fallback, bString); 373 this->saveIfUpdated(); 374 return output; 375 } 376 435 /** 436 @brief Deletes all elements of a config vector if their index is greater or equal to @a startindex. 437 438 @param section The name of the section 439 @param name The name of the vector 440 @param startindex The index of the first element that will be deleted 441 */ 377 442 void ConfigFile::deleteVectorEntries(const std::string& section, const std::string& name, unsigned int startindex) 378 443 { … … 384 449 } 385 450 451 /** 452 @brief Returns a pointer to the section with given name (or NULL if the section doesn't exist). 453 */ 386 454 ConfigFileSection* ConfigFile::getSection(const std::string& section) const 387 455 { … … 392 460 } 393 461 462 /** 463 @brief Returns a pointer to the section with given name. If it doesn't exist, the section is created. 464 */ 394 465 ConfigFileSection* ConfigFile::getOrCreateSection(const std::string& section) 395 466 { … … 403 474 } 404 475 476 /** 477 @brief Saves the config file if it was updated (or if any of its sections were updated). 478 */ 405 479 void ConfigFile::saveIfUpdated() 406 480 { … … 442 516 SettingsConfigFile* SettingsConfigFile::singletonPtr_s = 0; 443 517 518 /** 519 @brief Constructor: Activates the console commands. 520 */ 444 521 SettingsConfigFile::SettingsConfigFile(const std::string& filename) 445 522 : ConfigFile(filename) … … 452 529 } 453 530 531 /** 532 @brief Destructor: Deactivates the console commands. 533 */ 454 534 SettingsConfigFile::~SettingsConfigFile() 455 535 { … … 461 541 } 462 542 543 /** 544 @brief Loads the config file and updates the @ref ConfigValueContainer "config value containers". 545 */ 463 546 void SettingsConfigFile::load() 464 547 { … … 467 550 } 468 551 552 /** 553 @brief Changes the file-name. 554 */ 469 555 void SettingsConfigFile::setFilename(const std::string& filename) 470 556 { … … 472 558 } 473 559 560 /** 561 @brief Registers a new @ref ConfigValueContainer "config value container". 562 */ 474 563 void SettingsConfigFile::addConfigValueContainer(ConfigValueContainer* container) 475 564 { … … 481 570 } 482 571 572 /** 573 @brief Unregisters a @ref ConfigValueContainer "config value container". 574 */ 483 575 void SettingsConfigFile::removeConfigValueContainer(ConfigValueContainer* container) 484 576 { … … 500 592 } 501 593 594 /** 595 @brief Updates all @ref ConfigValueContainer "config value containers". 596 */ 502 597 void SettingsConfigFile::updateConfigValues() 503 598 { 599 // todo: can this be done more efficiently? looks like some identifiers will be updated multiple times. 600 504 601 for (ContainerMap::const_iterator it = this->containers_.begin(); it != this->containers_.end(); ++it) 505 602 { … … 509 606 } 510 607 608 /** 609 @brief Removes entries and sections from the file that don't exist anymore (i.e. if there's no corresponding @ref ConfigValueContainer "config value container"). 610 @param bCleanComments If true, comments are also removed from the file 611 */ 511 612 void SettingsConfigFile::clean(bool bCleanComments) 512 613 { … … 558 659 } 559 660 661 /** 662 @brief Console-command: Changes the value of an entry and stores it the file. 663 664 @param section The section of the config value 665 @param entry The name of the config value 666 @param value The new value 667 */ 560 668 void SettingsConfigFile::config(const std::string& section, const std::string& entry, const std::string& value) 561 669 { … … 564 672 } 565 673 674 /** 675 @brief Console-command: Changes the value of an entry, but doesn't store it in the file (it's only a temporary change). 676 677 @param section The section of the config value 678 @param entry The name of the config value 679 @param value The new value 680 */ 566 681 void SettingsConfigFile::tconfig(const std::string& section, const std::string& entry, const std::string& value) 567 682 { … … 570 685 } 571 686 687 /** 688 @brief Changes the value of an entry, depending on @a function, either by using "set" or "tset" 689 690 @param section The section of the config value 691 @param entry The name of the config value 692 @param value The new value 693 @param function The function ("set" or "tset") that will be used to change the value. 694 */ 572 695 bool SettingsConfigFile::configImpl(const std::string& section, const std::string& entry, const std::string& value, bool (ConfigValueContainer::*function)(const MultiType&)) 573 696 { … … 586 709 } 587 710 711 /** 712 @brief Console-command: Returns the value of a given entry. 713 714 @param section The section of the config value 715 @param entry The name of the config value 716 */ 588 717 std::string SettingsConfigFile::getConfig(const std::string& section, const std::string& entry) 589 718 { … … 611 740 ConfigFileManager* ConfigFileManager::singletonPtr_s = 0; 612 741 742 /// Constructor: Initializes the array of config files with NULL. 613 743 ConfigFileManager::ConfigFileManager() 614 744 { … … 616 746 } 617 747 748 /// Destructor: Deletes the config files. 618 749 ConfigFileManager::~ConfigFileManager() 619 750 { … … 623 754 } 624 755 756 /// Defines the file-name for the config file of a given type (settings, calibration, etc.). 625 757 void ConfigFileManager::setFilename(ConfigFileType::Value type, const std::string& filename) 626 758 {
Note: See TracChangeset
for help on using the changeset viewer.