- Timestamp:
- Apr 10, 2008, 4:39:06 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/ConfigFileManager.cc
r1006 r1020 44 44 void reloadConfig() 45 45 { 46 ConfigFileManager::get Instance()->load();46 ConfigFileManager::getSingleton()->load(); 47 47 } 48 48 49 49 void saveConfig() 50 50 { 51 ConfigFileManager::get Instance()->save();51 ConfigFileManager::getSingleton()->save(); 52 52 } 53 53 54 54 void cleanConfig() 55 55 { 56 ConfigFileManager::get Instance()->clean();56 ConfigFileManager::getSingleton()->clean(); 57 57 } 58 58 59 59 void loadSettings(const std::string& filename) 60 60 { 61 ConfigFileManager::get Instance()->setFile(CFT_Settings, filename);61 ConfigFileManager::getSingleton()->setFile(CFT_Settings, filename); 62 62 } 63 63 64 64 void loadKeybindings(const std::string& filename) 65 65 { 66 ConfigFileManager::get Instance()->setFile(CFT_Keybindings, filename);66 ConfigFileManager::getSingleton()->setFile(CFT_Keybindings, filename); 67 67 } 68 68 … … 109 109 } 110 110 111 std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, unsigned int index) 112 { 111 std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, const std::string& fallback) 112 { 113 std::cout << "a33333333333333333333333333\n"; 114 for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it) 115 if ((*it)->getName() == name) 116 return it; 117 118 this->bUpdated_ = true; 119 120 return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryValue(name, fallback))); 121 } 122 123 std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, unsigned int index, const std::string& fallback) 124 { 125 std::cout << "b3333333333333333333333333\n"; 113 126 for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it) 114 127 if (((*it)->getName() == name) && ((*it)->getIndex() == index)) … … 118 131 119 132 if (index == 0) 120 return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryArrayValue(name, index )));133 return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryArrayValue(name, index, fallback))); 121 134 else 122 return this->entries_.insert(this->getEntryIterator(name, index - 1), (ConfigFileEntry*)(new ConfigFileEntryArrayValue(name, index )));135 return this->entries_.insert(this->getEntryIterator(name, index - 1), (ConfigFileEntry*)(new ConfigFileEntryArrayValue(name, index, fallback))); 123 136 } 124 137 … … 184 197 if (isComment(line)) 185 198 { 199 std::cout << "1_7\n"; 186 200 // New comment 187 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryComment( line));201 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryComment(removeTrailingWhitespaces(line))); 188 202 continue; 189 203 } 190 204 else 191 205 { 206 std::cout << "1_8\n"; 192 207 unsigned int pos1 = line.find('='); 193 208 194 209 if (pos1 != std::string::npos && pos1 > 0) 195 210 { 211 std::cout << "1_9\n"; 196 212 // New entry 197 198 213 unsigned int pos2 = line.find('['); 199 214 unsigned int pos3 = line.find(']'); … … 205 220 if (value.size() > 0 && value[0] == '"' && betweenQuotes != "" && betweenQuotes.size() > 0) 206 221 { 222 std::cout << "1_10\n"; 207 223 value = betweenQuotes; 208 comment = getComment(value.substr(betweenQuotes.size() + 2)); 224 if (line.size() > pos1 + 1 + betweenQuotes.size() + 2) 225 comment = removeTrailingWhitespaces(getComment(line.substr(pos1 + 1 + betweenQuotes.size() + 2))); 209 226 } 210 227 else 211 228 { 229 std::cout << "1_11\n"; 212 230 unsigned int pos4 = getCommentPosition(line); 231 std::cout << "a\n"; 232 std::cout << line << std::endl; 233 std::cout << line.substr(pos1 + 1, pos4 - pos1 - 1) << std::endl; 213 234 value = removeTrailingWhitespaces(line.substr(pos1 + 1, pos4 - pos1 - 1)); 214 comment = line.substr(pos4); 235 std::cout << value << std::endl; 236 std::cout << "b\n"; 237 if (pos4 != std::string::npos) 238 comment = removeTrailingWhitespaces(line.substr(pos4)); 239 std::cout << comment << std::endl; 240 std::cout << "c\n"; 215 241 } 216 242 217 243 std::cout << "1_12\n"; 218 244 if (pos2 != std::string::npos && pos3 != std::string::npos && pos3 > pos2 + 1) 219 245 { 246 std::cout << "1_13\n"; 220 247 // There might be an array index 221 248 unsigned int index = 0; … … 224 251 // New array 225 252 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryArrayValue(getStripped(line.substr(0, pos2)), index, value, comment)); 253 std::cout << "1_14\n"; 226 254 continue; 227 255 } … … 230 258 // New value 231 259 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryValue(getStripped(line.substr(0, pos1)), value, comment)); 260 std::cout << "1_15\n"; 232 261 continue; 233 262 } … … 235 264 } 236 265 } 266 std::cout << "1_16\n"; 237 267 238 268 file.close(); 269 270 COUT(3) << "Loaded config file \"" << this->filename_ << "\"." << std::endl; 239 271 240 272 // Save the file in case something changed (like stripped whitespaces) 241 273 this->save(); 274 std::cout << "1_17\n"; 242 275 } 243 276 … … 269 302 270 303 file.close(); 304 305 COUT(4) << "Saved config file \"" << this->filename_ << "\"." << std::endl; 271 306 } 272 307 … … 277 312 ConfigFileSection* ConfigFile::getSection(const std::string& section) 278 313 { 314 std::cout << "22222222222222222222\n"; 279 315 for (std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); ++it) 280 316 if ((*it)->getName() == section) … … 321 357 } 322 358 323 ConfigFileManager* ConfigFileManager::get Instance()359 ConfigFileManager* ConfigFileManager::getSingleton() 324 360 { 325 361 static ConfigFileManager instance; … … 397 433 ConfigFile* ConfigFileManager::getFile(ConfigFileType type) 398 434 { 435 std::cout << "111111111111111111\n"; 399 436 std::map<ConfigFileType, ConfigFile*>::iterator it = this->configFiles_.find(type); 400 437 if (it != this->configFiles_.end())
Note: See TracChangeset
for help on using the changeset viewer.