Changeset 11071 for code/trunk/src/libraries/core/config
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/config/ConfigFile.cc
r10624 r11071 35 35 36 36 #include <boost/filesystem.hpp> 37 38 #include <iterator> 39 #include <algorithm> 40 #include <fstream> 37 41 38 42 #include "util/Convert.h" … … 93 97 try 94 98 { 95 boost::filesystem::copy_file(defaultFilepath, filepath); 99 std::ifstream input(defaultFilepath.string().c_str(), std::ifstream::in | std::ifstream::binary); 100 std::ofstream output(filepath.string().c_str(), std::ofstream::out | std::ofstream::binary); 101 copy(std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>(), std::ostream_iterator<char>(output)); 96 102 orxout(internal_info, context::config) << "Copied " << this->filename_ << " from the default config folder." << endl; 97 103 } … … 108 114 if (file.is_open()) 109 115 { 110 ConfigFileSection* newsection = 0;116 ConfigFileSection* newsection = nullptr; 111 117 112 118 while (file.good() && !file.eof()) … … 135 141 } 136 142 137 if (newsection != 0)143 if (newsection != nullptr) 138 144 { 139 145 if (isComment(line)) … … 228 234 } 229 235 230 for ( std::list<ConfigFileSection*>::const_iterator it = this->sections_.begin(); it != this->sections_.end(); ++it)231 { 232 file << (*it)->getFileEntry() << endl;233 234 for ( std::list<ConfigFileEntry*>::const_iterator it_entries = (*it)->getEntriesBegin(); it_entries != (*it)->getEntriesEnd(); ++it_entries)235 file << (*it_entries)->getFileEntry() << endl;236 for (ConfigFileSection* section : this->sections_) 237 { 238 file << section->getFileEntry() << endl; 239 240 for (ConfigFileEntry* entry : section->getEntries()) 241 file << entry->getFileEntry() << endl; 236 242 237 243 file << endl; … … 270 276 271 277 /** 272 @brief Returns a pointer to the section with given name (or NULLif the section doesn't exist).273 */ 274 ConfigFileSection* ConfigFile::getSection(const std::string& section ) const275 { 276 for ( std::list<ConfigFileSection*>::const_iterator it = this->sections_.begin(); it != this->sections_.end(); ++it)277 if ( (*it)->getName() == section)278 return (*it);279 return NULL;278 @brief Returns a pointer to the section with given name (or nullptr if the section doesn't exist). 279 */ 280 ConfigFileSection* ConfigFile::getSection(const std::string& sectionName) const 281 { 282 for (ConfigFileSection* section : this->sections_) 283 if (section->getName() == sectionName) 284 return section; 285 return nullptr; 280 286 } 281 287 … … 283 289 @brief Returns a pointer to the section with given name. If it doesn't exist, the section is created. 284 290 */ 285 ConfigFileSection* ConfigFile::getOrCreateSection(const std::string& section )286 { 287 for ( std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); ++it)288 if ( (*it)->getName() == section)289 return (*it);291 ConfigFileSection* ConfigFile::getOrCreateSection(const std::string& sectionName) 292 { 293 for (ConfigFileSection* section : this->sections_) 294 if (section->getName() == sectionName) 295 return section; 290 296 291 297 this->bUpdated_ = true; 292 298 293 return (*this->sections_.insert(this->sections_.end(), new ConfigFileSection(section )));299 return (*this->sections_.insert(this->sections_.end(), new ConfigFileSection(sectionName))); 294 300 } 295 301 … … 301 307 bool sectionsUpdated = false; 302 308 303 for ( std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); ++it)304 { 305 if ( (*it)->bUpdated_)309 for (ConfigFileSection* section : this->sections_) 310 { 311 if (section->bUpdated_) 306 312 { 307 313 sectionsUpdated = true; 308 (*it)->bUpdated_ = false;314 section->bUpdated_ = false; 309 315 } 310 316 } -
code/trunk/src/libraries/core/config/ConfigFileEntry.h
r9559 r11071 51 51 public: 52 52 /// Destructor 53 virtual ~ConfigFileEntry() {};53 virtual ~ConfigFileEntry() = default; 54 54 55 55 /// Changes the value of the entry. -
code/trunk/src/libraries/core/config/ConfigFileEntryComment.h
r9559 r11071 54 54 55 55 /// Destructor 56 inline virtual ~ConfigFileEntryComment() {}56 virtual inline ~ConfigFileEntryComment() = default; 57 57 58 inline virtual const std::string& getName() const58 virtual inline const std::string& getName() const override 59 59 { return this->comment_; } 60 60 61 inline virtual void setComment(const std::string& comment)61 virtual inline void setComment(const std::string& comment) override 62 62 { this->comment_ = comment; } 63 63 64 inline virtual void setValue(const std::string& value)64 virtual inline void setValue(const std::string& value) override 65 65 {} 66 inline virtual const std::string& getValue() const66 virtual inline const std::string& getValue() const override 67 67 { return BLANKSTRING; } 68 68 69 inline void setString(bool bString)69 virtual inline void setString(bool bString) override 70 70 {} 71 71 72 inline virtual const std::string& getFileEntry() const72 virtual inline const std::string& getFileEntry() const override 73 73 { return this->comment_; } 74 74 -
code/trunk/src/libraries/core/config/ConfigFileEntryValue.h
r9684 r11071 67 67 68 68 /// Destructor 69 inline virtual ~ConfigFileEntryValue() {}69 virtual inline ~ConfigFileEntryValue() = default; 70 70 71 inline virtual const std::string& getName() const71 virtual inline const std::string& getName() const override 72 72 { return this->name_; } 73 73 74 inline virtual void setComment(const std::string& comment)74 virtual inline void setComment(const std::string& comment) override 75 75 { this->additionalComment_ = comment; this->update(); } 76 76 77 inline virtual void setValue(const std::string& value)77 virtual inline void setValue(const std::string& value) override 78 78 { this->value_ = value; this->update(); } 79 inline virtual const std::string& getValue() const79 virtual inline const std::string& getValue() const override 80 80 { return this->value_; } 81 81 82 inline void virtual setString(bool bString)82 virtual inline void setString(bool bString) override 83 83 { this->bString_ = bString; this->update(); } 84 84 85 inline virtual const std::string& getFileEntry() const85 virtual inline const std::string& getFileEntry() const override 86 86 { return this->fileEntry_; } 87 87 88 88 /// Returns the "key" of the value (in this case it's just the name of the entry, but for vectors it's different) 89 inline virtualconst std::string& getKeyString() const89 virtual inline const std::string& getKeyString() const 90 90 { return this->name_; } 91 91 -
code/trunk/src/libraries/core/config/ConfigFileEntryVectorValue.h
r9559 r11071 65 65 66 66 /// Destructor 67 inline ~ConfigFileEntryVectorValue() {}67 inline ~ConfigFileEntryVectorValue() = default; 68 68 69 inline unsigned int getIndex() const69 virtual inline unsigned int getIndex() const override 70 70 { return this->index_; } 71 71 72 72 /// Returns the "key" of the value (the name of the vector plus the index of the element) 73 inline const std::string& getKeyString() const73 virtual inline const std::string& getKeyString() const override 74 74 { return this->keyString_; } 75 75 76 76 private: 77 v oid update();77 virtual void update() override; 78 78 79 79 unsigned int index_; ///< The index of the element in the vector -
code/trunk/src/libraries/core/config/ConfigFileManager.cc
r9559 r11071 42 42 /////////////////////// 43 43 44 ConfigFileManager* ConfigFileManager::singletonPtr_s = 0;44 ConfigFileManager* ConfigFileManager::singletonPtr_s = nullptr; 45 45 46 /// Constructor: Initializes the array of config files with NULL.46 /// Constructor: Initializes the array of config files with nullptr. 47 47 ConfigFileManager::ConfigFileManager() 48 48 { 49 this->configFiles_. assign(NULL);49 this->configFiles_.fill(nullptr); 50 50 } 51 51 … … 53 53 ConfigFileManager::~ConfigFileManager() 54 54 { 55 for ( boost::array<ConfigFile*, 3>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it)56 if ( *it)57 delete (*it);55 for (ConfigFile* configFile : this->configFiles_) 56 if (configFile) 57 delete configFile; 58 58 } 59 59 -
code/trunk/src/libraries/core/config/ConfigFileManager.h
r9559 r11071 38 38 #include "core/CorePrereqs.h" 39 39 40 #include < boost/array.hpp>40 #include <array> 41 41 42 42 #include "util/Singleton.h" … … 67 67 68 68 private: 69 ConfigFileManager(const ConfigFileManager&); ///< Copy-constructor: not implemented 69 // non-copyable: 70 ConfigFileManager(const ConfigFileManager&) = delete; 71 ConfigFileManager& operator=(const ConfigFileManager&) = delete; 70 72 71 boost::array<ConfigFile*, 3> configFiles_;///< Stores the config files for each type in an array (must have the same size like ConfigFileType::Value)73 std::array<ConfigFile*, 3> configFiles_; ///< Stores the config files for each type in an array (must have the same size like ConfigFileType::Value) 72 74 static ConfigFileManager* singletonPtr_s; ///< Stores the singleton-pointer 73 75 }; -
code/trunk/src/libraries/core/config/ConfigFileSection.cc
r9559 r11071 80 80 { 81 81 unsigned int size = 0; 82 for ( std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)83 if ( (*it)->getName() == name)84 if ( (*it)->getIndex() >= size)85 size = (*it)->getIndex() + 1;82 for (ConfigFileEntry* entry : this->entries_) 83 if (entry->getName() == name) 84 if (entry->getIndex() >= size) 85 size = entry->getIndex() + 1; 86 86 return size; 87 87 } … … 99 99 100 100 /** 101 @brief Returns the entry with given name (or NULLif it doesn't exist).101 @brief Returns the entry with given name (or nullptr if it doesn't exist). 102 102 103 103 @param name The name of the entry … … 105 105 ConfigFileEntry* ConfigFileSection::getEntry(const std::string& name) const 106 106 { 107 for ( std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)107 for (ConfigFileEntry* entry : this->entries_) 108 108 { 109 if ( (*it)->getName() == name)110 return *it;109 if (entry->getName() == name) 110 return entry; 111 111 } 112 return NULL;112 return nullptr; 113 113 } 114 114 115 115 /** 116 @brief Returns the entry of a vector element with given name and index (or NULLif it doesn't exist).116 @brief Returns the entry of a vector element with given name and index (or nullptr if it doesn't exist). 117 117 118 118 @param name The name of the vector … … 121 121 ConfigFileEntry* ConfigFileSection::getEntry(const std::string& name, unsigned int index) const 122 122 { 123 for ( std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)123 for (ConfigFileEntry* entry : this->entries_) 124 124 { 125 if (( (*it)->getName() == name) && ((*it)->getIndex() == index))126 return *it;125 if ((entry->getName() == name) && (entry->getIndex() == index)) 126 return entry; 127 127 } 128 return NULL;128 return nullptr; 129 129 } 130 130 -
code/trunk/src/libraries/core/config/ConfigFileSection.h
r9684 r11071 39 39 #include <string> 40 40 #include <list> 41 #include "util/StringUtils.h" 41 42 #include "ConfigFileEntry.h" 42 43 … … 160 161 std::list<ConfigFileEntry*>& getEntries() 161 162 { return this->entries_; } 162 /// Returns the begin-iterator of the list of entries in this section. 163 std::list<ConfigFileEntry*>::const_iterator getEntriesBegin() const 164 { return this->entries_.begin(); } 165 /// Returns the end-iterator of the list of entries in this section. 166 std::list<ConfigFileEntry*>::const_iterator getEntriesEnd() const 167 { return this->entries_.end(); } 163 const std::list<ConfigFileEntry*>& getEntries() const 164 { return this->entries_; } 168 165 169 166 std::list<ConfigFileEntry*>::iterator getOrCreateEntryIterator(const std::string& name, const std::string& fallback, bool bString); -
code/trunk/src/libraries/core/config/ConfigValueContainer.cc
r9559 r11071 53 53 this->sectionname_ = sectionname; 54 54 this->varname_ = varname; 55 this->callback_ = 0;55 this->callback_ = nullptr; 56 56 this->bContainerIsNew_ = true; 57 57 this->bDoInitialCallback_ = false; … … 191 191 for (unsigned int i = this->valueVector_.size(); i <= index; i++) 192 192 { 193 this->valueVector_. push_back(MultiType());193 this->valueVector_.emplace_back(); 194 194 } 195 195 } -
code/trunk/src/libraries/core/config/ConfigValueContainer.h
r9667 r11071 59 59 public: 60 60 virtual void call(void* object) = 0; 61 inline virtual~ConfigValueCallbackBase() {}61 virtual inline ~ConfigValueCallbackBase() {} 62 62 }; 63 63 … … 67 67 public: 68 68 inline ConfigValueCallback(void (T::*function) (void)) : function_(function) {} 69 inline virtual ~ConfigValueCallback() {}70 inline virtual void call(void* object)69 virtual inline ~ConfigValueCallback() = default; 70 virtual inline void call(void* object) override 71 71 { 72 72 if (!IdentifierManager::getInstance().isCreatingHierarchy()) … … 130 130 131 131 this->value_ = V(); 132 for ( unsigned int i = 0; i < defvalue.size(); i++)133 this->valueVector_. push_back(MultiType(defvalue[i]));132 for (const D& defvalueElement : defvalue) 133 this->valueVector_.emplace_back(defvalueElement); 134 134 135 135 this->initVector(); … … 183 183 std::vector<T> temp = *value; 184 184 value->clear(); 185 for ( unsigned int i = 0; i < this->valueVector_.size(); ++i)186 value->push_back( this->valueVector_[i]);185 for (const MultiType& vectorEntry : this->valueVector_) 186 value->push_back(vectorEntry); 187 187 188 188 if (value->size() != temp.size()) … … 211 211 { 212 212 value->clear(); 213 for ( unsigned int i = 0; i < this->valueVector_.size(); ++i)214 value->push_back( this->valueVector_[i]);213 for (const MultiType& vectorEntry : this->valueVector_) 214 value->push_back(vectorEntry); 215 215 } 216 216 return *this; … … 223 223 inline const std::string& getSectionName() const 224 224 { return this->sectionname_; } 225 /// Returns the associated identifier (can be NULL).225 /// Returns the associated identifier (can be nullptr). 226 226 inline Identifier* getIdentifier() const 227 227 { return this->identifier_; } -
code/trunk/src/libraries/core/config/SettingsConfigFile.cc
r10624 r11071 57 57 SetConsoleCommand(__CC_getConfig_name, &SettingsConfigFile::getConfig).argumentCompleter(0, autocompletion::settingssections()).argumentCompleter(1, autocompletion::settingsentries()); 58 58 59 SettingsConfigFile* SettingsConfigFile::singletonPtr_s = 0;59 SettingsConfigFile* SettingsConfigFile::singletonPtr_s = nullptr; 60 60 61 61 /** … … 77 77 SettingsConfigFile::~SettingsConfigFile() 78 78 { 79 ModifyConsoleCommand(__CC_load_name).setObject( 0);80 ModifyConsoleCommand(__CC_setFilename_name).setObject( 0);81 ModifyConsoleCommand(__CC_config_name).setObject( 0);82 ModifyConsoleCommand(__CC_tconfig_name).setObject( 0);83 ModifyConsoleCommand(__CC_getConfig_name).setObject( 0);79 ModifyConsoleCommand(__CC_load_name).setObject(nullptr); 80 ModifyConsoleCommand(__CC_setFilename_name).setObject(nullptr); 81 ModifyConsoleCommand(__CC_config_name).setObject(nullptr); 82 ModifyConsoleCommand(__CC_tconfig_name).setObject(nullptr); 83 ModifyConsoleCommand(__CC_getConfig_name).setObject(nullptr); 84 84 } 85 85 … … 106 106 void SettingsConfigFile::addConfigValueContainer(ConfigValueContainer* container) 107 107 { 108 if (container == NULL)108 if (container == nullptr) 109 109 return; 110 110 std::pair<std::string, ConfigValueContainer*> second(getLowercase(container->getName()), container); … … 118 118 void SettingsConfigFile::removeConfigValueContainer(ConfigValueContainer* container) 119 119 { 120 if (container == NULL)120 if (container == nullptr) 121 121 return; 122 122 const std::string& sectionLC = getLowercase(container->getSectionName()); … … 142 142 // todo: can this be done more efficiently? looks like some identifiers will be updated multiple times. 143 143 144 for ( ContainerMap::const_iterator it = this->containers_.begin(); it != this->containers_.end(); ++it)145 { 146 it->second.second->update();147 it->second.second->getIdentifier()->updateConfigValues();144 for (const auto& mapEntry : this->containers_) 145 { 146 mapEntry.second.second->update(); 147 mapEntry.second.second->getIdentifier()->updateConfigValues(); 148 148 } 149 149 } … … 269 269 { 270 270 std::string value; 271 it->second.second->getValue<std::string, void>(&value, NULL);271 it->second.second->getValue<std::string, void>(&value, nullptr); 272 272 return value; 273 273 } -
code/trunk/src/libraries/core/config/SettingsConfigFile.h
r9684 r11071 63 63 64 64 public: 65 typedef std::multimap<std::string, std::pair<std::string, ConfigValueContainer*> 65 typedef std::multimap<std::string, std::pair<std::string, ConfigValueContainer*>> ContainerMap; 66 66 67 67 SettingsConfigFile(const std::string& filename); 68 68 ~SettingsConfigFile(); 69 69 70 v oid load(); // tolua_export70 virtual void load() override; // tolua_export 71 71 void setFilename(const std::string& filename); // tolua_export 72 72 void clean(bool bCleanComments = false); // tolua_export
Note: See TracChangeset
for help on using the changeset viewer.