- Timestamp:
- Apr 12, 2008, 3:34:55 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/ConfigFileManager.cc
r1027 r1030 49 49 void cleanConfig() 50 50 { 51 ConfigFileManager::getSingleton()->clean( );51 ConfigFileManager::getSingleton()->clean(false); 52 52 } 53 53 … … 76 76 77 77 /////////////////////////////// 78 // ConfigFileEntry ArrayValue //78 // ConfigFileEntryVectorValue // 79 79 /////////////////////////////// 80 std::string ConfigFileEntry ArrayValue::getFileEntry() const80 std::string ConfigFileEntryVectorValue::getFileEntry() const 81 81 { 82 82 if (this->additionalComment_ == "" || this->additionalComment_.size() == 0) 83 return (this->name_ + "[" + getConvertedValue<unsigned int, std::string>(this->index_, 0) + "]" + "=" + this->value_);83 return (this->name_ + "[" + getConvertedValue<unsigned int, std::string>(this->index_, "0") + "]" + "=" + this->value_); 84 84 else 85 return (this->name_ + "[" + getConvertedValue<unsigned int, std::string>(this->index_, 0) + "]=" + this->value_ + " " + this->additionalComment_);85 return (this->name_ + "[" + getConvertedValue<unsigned int, std::string>(this->index_, "0") + "]=" + this->value_ + " " + this->additionalComment_); 86 86 } 87 87 … … 96 96 } 97 97 98 void ConfigFileSection::deleteVectorEntries(const std::string& name, unsigned int startindex) 99 { 100 for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ) 101 { 102 if (((*it)->getName() == name) && ((*it)->getIndex() >= startindex)) 103 { 104 delete (*it); 105 this->entries_.erase(it++); 106 } 107 else 108 { 109 ++it; 110 } 111 } 112 } 113 114 unsigned int ConfigFileSection::getVectorSize(const std::string& name) 115 { 116 unsigned int size = 0; 117 for (std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it) 118 if ((*it)->getName() == name) 119 if ((*it)->getIndex() > size) 120 size = (*it)->getIndex(); 121 return (size + 1); 122 } 123 98 124 std::string ConfigFileSection::getFileEntry() const 99 125 { … … 124 150 125 151 if (index == 0) 126 return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntry ArrayValue(name, index, fallback)));152 return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryVectorValue(name, index, fallback))); 127 153 else 128 return this->entries_.insert( this->getEntryIterator(name, index - 1), (ConfigFileEntry*)(new ConfigFileEntryArrayValue(name, index, fallback)));154 return this->entries_.insert(++this->getEntryIterator(name, index - 1), (ConfigFileEntry*)(new ConfigFileEntryVectorValue(name, index, fallback))); 129 155 } 130 156 … … 173 199 if (!isEmpty(temp) && !isComment(temp)) 174 200 { 175 unsigned int pos1 = line.find('['); 176 unsigned int pos2 = line.find(']'); 201 unsigned int pos1 = temp.find('['); 202 if (pos1 == 0) pos1 = line.find('['); else pos1 = std::string::npos; 203 unsigned int pos2 = line.find(']'); 177 204 178 205 if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1) 179 206 { 180 207 // New section 181 std::string comment = temp.substr(pos2 + 1);208 std::string comment = line.substr(pos2 + 1); 182 209 if (isComment(comment)) 183 210 newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1), comment); … … 232 259 { 233 260 // New array 234 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryArrayValue(getStripped(line.substr(0, pos2)), index, value, comment)); 261 std::list<ConfigFileEntry*>::iterator it = newsection->getEntryIterator(getStripped(line.substr(0, pos2)), index, value); 262 (*it)->setValue(value); 263 (*it)->setComment(comment); 235 264 continue; 236 265 } … … 284 313 } 285 314 286 void ConfigFile::clean( )315 void ConfigFile::clean(bool bCleanComments) 287 316 { 288 317 for (std::list<ConfigFileSection*>::iterator it1 = this->sections_.begin(); it1 != this->sections_.end(); ) … … 292 321 { 293 322 // The section exists, delete comment 294 (*it1)->setComment(""); 323 if (bCleanComments) 324 (*it1)->setComment(""); 295 325 for (std::list<ConfigFileEntry*>::iterator it3 = (*it1)->entries_.begin(); it3 != (*it1)->entries_.end(); ) 296 326 { … … 299 329 { 300 330 // The config-value exists, delete comment 301 (*it3)->setComment(""); 331 if (bCleanComments) 332 (*it3)->setComment(""); 302 333 ++it3; 303 334 } … … 331 362 this->bUpdated_ = true; 332 363 333 return (*this->sections_.insert(this->sections_. begin(), new ConfigFileSection(section)));364 return (*this->sections_.insert(this->sections_.end(), new ConfigFileSection(section))); 334 365 } 335 366 … … 400 431 } 401 432 402 void ConfigFileManager::clean( )433 void ConfigFileManager::clean(bool bCleanComments) 403 434 { 404 435 for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it) 405 this->clean((*it).first );436 this->clean((*it).first, bCleanComments); 406 437 } 407 438 … … 417 448 } 418 449 419 void ConfigFileManager::clean(ConfigFileType type) 420 { 421 this->getFile(type)->clean(); 422 this->getFile(type)->save(); 450 void ConfigFileManager::clean(ConfigFileType type, bool bCleanComments) 451 { 452 this->getFile(type)->clean(bCleanComments); 423 453 } 424 454
Note: See TracChangeset
for help on using the changeset viewer.