- Timestamp:
- Apr 10, 2008, 4:39:06 PM (17 years ago)
- Location:
- code/branches/core2/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/Orxonox.cc
r993 r1020 89 89 #include "core/CommandExecutor.h" 90 90 #include "core/InputBuffer.h" 91 #include "core/ConfigFileManager.h" 91 92 92 93 #include "Orxonox.h" … … 250 251 ogre_->startRender(); 251 252 //TODO: run engine 253 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini"); 252 254 Factory::createClassHierarchy(); 253 255 createScene(); … … 1231 1233 setupInputSystem(); 1232 1234 createFrameListener(); 1235 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini"); 1233 1236 Factory::createClassHierarchy(); 1234 1237 startRenderLoop();*/ … … 1245 1248 initializeResourceGroups(); 1246 1249 setupInputSystem(); 1250 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini"); 1247 1251 Factory::createClassHierarchy(); 1248 1252 createScene(); -
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()) -
code/branches/core2/src/orxonox/core/ConfigFileManager.h
r1006 r1020 76 76 { 77 77 public: 78 inline ConfigFileEntryValue(const std::string& name, const std::string& value = "", const std::string& additionalComment = "") : name_(name), value_(value), additionalComment_(additionalComment), bString_(false) { }78 inline ConfigFileEntryValue(const std::string& name, const std::string& value = "", const std::string& additionalComment = "") : name_(name), value_(value), additionalComment_(additionalComment), bString_(false) { std::cout << "************* " << value << std::endl; } 79 79 inline virtual ~ConfigFileEntryValue() {} 80 80 … … 161 161 162 162 inline void setValue(const std::string& name, const std::string& value) 163 { this->getEntry(name )->setValue(value); }164 inline const std::string& getValue(const std::string& name )165 { return this->getEntry(name )->getValue(); }163 { this->getEntry(name, value)->setValue(value); } 164 inline const std::string& getValue(const std::string& name, const std::string& fallback) 165 { return this->getEntry(name, fallback)->getValue(); } 166 166 167 167 inline void setValue(const std::string& name, unsigned int index, const std::string& value) 168 { this->getEntry(name, index )->setValue(value); }169 inline const std::string& getValue(const std::string& name, unsigned int index )170 { return this->getEntry(name, index )->getValue(); }168 { this->getEntry(name, index, value)->setValue(value); } 169 inline const std::string& getValue(const std::string& name, unsigned int index, const std::string& fallback) 170 { return this->getEntry(name, index, fallback)->getValue(); } 171 171 172 172 std::string getFileEntry() const; … … 180 180 { return this->entries_.end(); } 181 181 182 std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, unsigned int index); 183 184 inline ConfigFileEntry* getEntry(const std::string& name) 185 { return (*this->getEntryIterator(name, 0)); } 186 inline ConfigFileEntry* getEntry(const std::string& name, unsigned int index) 187 { return (*this->getEntryIterator(name, index)); } 182 std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, const std::string& fallback = ""); 183 std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, unsigned int index, const std::string& fallback = ""); 184 185 inline ConfigFileEntry* getEntry(const std::string& name, const std::string& fallback) 186 { return (*this->getEntryIterator(name, fallback)); } 187 inline ConfigFileEntry* getEntry(const std::string& name, unsigned int index, const std::string& fallback) 188 { return (*this->getEntryIterator(name, index, fallback)); } 188 189 189 190 std::string name_; … … 209 210 inline void setValue(const std::string& section, const std::string& name, const std::string& value) 210 211 { this->getSection(section)->setValue(name, value); this->save(); } 211 inline const std::string& getValue(const std::string& section, const std::string& name )212 { return this->getSection(section)->getValue(name ); this->saveIfUpdated(); }212 inline const std::string& getValue(const std::string& section, const std::string& name, const std::string& fallback) 213 { return this->getSection(section)->getValue(name, fallback); this->saveIfUpdated(); } 213 214 214 215 inline void setValue(const std::string& section, const std::string& name, unsigned int index, const std::string& value) 215 216 { this->getSection(section)->setValue(name, index, value); this->save(); } 216 inline const std::string& getValue(const std::string& section, const std::string& name, unsigned int index )217 { return this->getSection(section)->getValue(name, index ); this->saveIfUpdated(); }217 inline const std::string& getValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback) 218 { return this->getSection(section)->getValue(name, index, fallback); this->saveIfUpdated(); } 218 219 219 220 private: … … 233 234 { 234 235 public: 235 static ConfigFileManager* get Instance();236 static ConfigFileManager* getSingleton(); 236 237 237 238 void setFile(ConfigFileType type, const std::string& filename); … … 247 248 inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& value) 248 249 { this->getFile(type)->setValue(section, name, value); } 249 inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name )250 { return this->getFile(type)->getValue(section, name ); }250 inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& fallback) 251 { return this->getFile(type)->getValue(section, name, fallback); } 251 252 252 253 inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& value) 253 254 { this->getFile(type)->setValue(section, name, index, value); } 254 inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index )255 { return this->getFile(type)->getValue(section, name, index ); }255 inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& fallback) 256 { return this->getFile(type)->getValue(section, name, index, fallback); } 256 257 257 258 void updateConfigValues() const; -
code/branches/core2/src/orxonox/core/ConfigValueContainer.cc
r989 r1020 35 35 #include "ConfigValueContainer.h" 36 36 #include "Language.h" 37 #include "Iterator.h"38 #include "BaseObject.h"39 37 40 #define CONFIGFILEPATH "orxonox.ini"41 38 42 39 namespace orxonox … … 49 46 @param defvalue The default-value 50 47 */ 51 ConfigValueContainer::ConfigValueContainer( Identifier* identifier, const std::string& varname, MultiTypeMath defvalue)48 ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, MultiTypeMath defvalue) 52 49 { 53 this-> bAddedDescription_ = false;50 this->type_ = type; 54 51 this->identifier_ = identifier; 52 this->sectionname_ = identifier->getName(); 55 53 this->varname_ = varname; 56 54 57 this->defvalueString_ = defvalue.toString(); // Convert the default-value to a string 58 this->searchLineInConfigFile(); // Search the entry in the config-file 55 this->bAddedDescription_ = false; 59 56 60 std::string valueString = this->parseValueStringFromConfigFile(!(defvalue.isA(MT_string) || defvalue.isA(MT_constchar))); // Parses the value string from the config-file-entry 61 if (!this->parse(valueString, defvalue)) // Try to convert the string to a value 62 this->resetLineInConfigFile(); // The conversion failed 57 this->defvalueString_ = defvalue.toString(); 58 this->update(); 63 59 } 64 60 … … 94 90 { 95 91 return this->set(this->defvalueString_); 92 } 93 94 /** 95 @brief Retrieves the configured value from the currently loaded config-file. 96 */ 97 void ConfigValueContainer::update() 98 { 99 std::cout << "AAA1: " << this->value_ << std::endl; 100 std::cout << " : " << ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_) << std::endl; 101 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_)); 102 std::cout << "AAA2: " << this->value_ << std::endl; 96 103 } 97 104 … … 138 145 void ConfigValueContainer::setLineInConfigFile(const std::string& input) 139 146 { 140 (*this->configFileLine_) = this->varname_ + "=" + input; 141 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 147 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input); 142 148 } 143 149 … … 147 153 void ConfigValueContainer::resetLineInConfigFile() 148 154 { 149 this->setLineInConfigFile(this->defvalueString_); 150 } 151 152 /** 153 @brief Searches the corresponding entry in the config-file and creates it, if there is no entry. 154 */ 155 void ConfigValueContainer::searchLineInConfigFile() 156 { 157 // Read the file if needed 158 if (!ConfigValueContainer::finishedReadingConfigFile()) 159 ConfigValueContainer::readConfigFile(CONFIGFILEPATH); 160 161 // The string of the section we're searching 162 std::string section = ""; 163 section.append("["); 164 section.append(this->identifier_->getName()); 165 section.append("]"); 166 167 // Iterate through all config-file-lines 168 bool success = false; 169 std::list<std::string>::iterator it1; 170 for(it1 = ConfigValueContainer::getConfigFileLines().begin(); it1 != ConfigValueContainer::getConfigFileLines().end(); ++it1) 171 { 172 // Don't try to parse comments 173 if (isComment(*it1)) 174 continue; 175 176 if ((*it1).find(section) < (*it1).length()) 177 { 178 // We found the right section 179 bool bLineIsEmpty = false; 180 std::list<std::string>::iterator positionToPutNewLineAt; 181 182 // Iterate through all lines in the section 183 std::list<std::string>::iterator it2; 184 for(it2 = ++it1; it2 != ConfigValueContainer::getConfigFileLines().end(); ++it2) 185 { 186 // Don't try to parse comments 187 if (isComment(*it2)) 188 continue; 189 190 // This if-else block is used to write a new line right after the last line of the 191 // section but in front of the following empty lines before the next section. 192 // (So this helps to keep a nice formatting with empty-lines between sections in the config-file) 193 if (isEmpty(*it2)) 194 { 195 if (!bLineIsEmpty) 196 { 197 bLineIsEmpty = true; 198 positionToPutNewLineAt = it2; 199 } 200 } 201 else 202 { 203 if (!bLineIsEmpty) 204 positionToPutNewLineAt = it2; 205 206 bLineIsEmpty = false; 207 } 208 209 // Look out for the beginning of the next section 210 unsigned int open = (*it2).find("["); 211 unsigned int close = (*it2).find("]"); 212 if ((open < (*it2).length()) && (close < (*it2).length()) && (open < close)) 213 { 214 // The next section startet, so our line isn't yet in the file - now we add it and safe the file 215 this->configFileLine_ = this->getConfigFileLines().insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalueString_); 216 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 217 success = true; 218 break; 219 } 220 221 // Look out for the variable-name 222 if ((*it2).find(this->varname_) < (*it2).length()) 223 { 224 // We found the right line - safe it and return 225 this->configFileLine_ = it2; 226 success = true; 227 break; 228 } 229 } 230 231 // Check if we succeeded 232 if (!success) 233 { 234 // Looks like we found the right section, but the file ended without containing our variable - so we add it and safe the file 235 this->configFileLine_ = this->getConfigFileLines().insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalueString_); 236 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 237 success = true; 238 } 239 break; 240 } 241 } 242 243 // Check if we succeeded 244 if (!success) 245 { 246 // We obviously didn't found the right section, so we'll create it 247 this->getConfigFileLines().push_back("[" + this->identifier_->getName() + "]"); // Create the section 248 this->getConfigFileLines().push_back(this->varname_ + "=" + this->defvalueString_); // Create the line 249 this->configFileLine_ = --this->getConfigFileLines().end(); // Set the pointer to the last element 250 success = true; 251 this->getConfigFileLines().push_back(""); // Add an empty line - this is needed for the algorithm in the searchLineInConfigFile-function 252 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); // Save the changed config-file 253 } 254 } 255 256 /** 257 @brief Returns the part in the corresponding config-file-entry of the container that defines the value. 258 @param bStripped True = strip the value-string 259 @return The value-string 260 */ 261 std::string ConfigValueContainer::parseValueStringFromConfigFile(bool bStripped) 262 { 263 std::string output; 264 if (bStripped) 265 output = getStripped(*this->configFileLine_); 266 else 267 output = *this->configFileLine_; 268 269 return output.substr(output.find("=") + 1); 270 } 271 272 /** 273 @brief Rreturns a list, containing all entrys in the config-file. 274 @return The list 275 */ 276 std::list<std::string>& ConfigValueContainer::getConfigFileLines() 277 { 278 // This is done to avoid problems while executing this code before main() 279 static std::list<std::string> configFileLinesStaticReference = std::list<std::string>(); 280 return configFileLinesStaticReference; 281 } 282 283 /** 284 @brief Returns true if the ConfigFile is read and stored into the ConfigFile-lines-list. 285 @param finished This is used to change the state 286 @return True if the ConfigFile is read and stored into the ConfigFile-lines-list 287 */ 288 bool ConfigValueContainer::finishedReadingConfigFile(bool finished) 289 { 290 // This is done to avoid problems while executing this code before main() 291 static bool finishedReadingConfigFileStaticVariable = false; 292 293 if (finished) 294 finishedReadingConfigFileStaticVariable = true; 295 296 return finishedReadingConfigFileStaticVariable; 297 } 298 299 /** 300 @brief Reads the config-file and stores the lines in a list. 301 @param filename The name of the config-file 302 */ 303 void ConfigValueContainer::readConfigFile(const std::string& filename) 304 { 305 // This creates the file if it's not existing 306 std::ofstream createFile; 307 createFile.open(filename.c_str(), std::fstream::app); 308 createFile.close(); 309 310 // Open the file 311 std::ifstream file; 312 file.open(filename.c_str(), std::fstream::in); 313 314 if (!file.is_open()) 315 { 316 COUT(1) << "An error occurred in ConfigValueContainer.cc:" << std::endl; 317 COUT(1) << "Error: Couldn't open config-file " << filename << " to read the config values!" << std::endl; 318 return; 319 } 320 321 char line[1024]; 322 323 // Iterate through the file and add the lines into the list 324 while (file.good() && !file.eof()) 325 { 326 file.getline(line, 1024); 327 ConfigValueContainer::getConfigFileLines().push_back(line); 328 } 329 330 // The last line is useless 331 ConfigValueContainer::getConfigFileLines().pop_back(); 332 333 // Add an empty line to the end of the file if needed 334 // this is needed for the algorithm in the searchLineInConfigFile-function 335 if ((ConfigValueContainer::getConfigFileLines().size() > 0) && !isEmpty(*ConfigValueContainer::getConfigFileLines().rbegin())) 336 ConfigValueContainer::getConfigFileLines().push_back(""); 337 338 file.close(); 339 340 ConfigValueContainer::finishedReadingConfigFile(true); 341 } 342 343 /** 344 @brief Writes the content of the list, containing all lines of the config-file, into the config-file. 345 @param filename The name of the config-file 346 */ 347 void ConfigValueContainer::writeConfigFile(const std::string& filename) 348 { 349 // Make sure we stored the config-file in the list 350 if (!ConfigValueContainer::finishedReadingConfigFile()) 351 ConfigValueContainer::readConfigFile(filename); 352 353 // Open the file 354 std::ofstream file; 355 file.open(filename.c_str(), std::fstream::out); 356 file.setf(std::ios::fixed, std::ios::floatfield); 357 file.precision(6); 358 359 if (!file.is_open()) 360 { 361 COUT(1) << "An error occurred in ConfigValueContainer.cc:" << std::endl; 362 COUT(1) << "Error: Couldn't open config-file " << filename << " to write the config values!" << std::endl; 363 return; 364 } 365 366 // Iterate through the list an write the lines into the file 367 std::list<std::string>::iterator it; 368 for (it = ConfigValueContainer::getConfigFileLines().begin(); it != ConfigValueContainer::getConfigFileLines().end(); ++it) 369 { 370 file << (*it) << std::endl; 371 } 372 373 file.close(); 155 this->setLineInConfigFile(this->value_.toString()); 374 156 } 375 157 -
code/branches/core2/src/orxonox/core/ConfigValueContainer.h
r972 r1020 50 50 #include "util/Math.h" 51 51 #include "util/MultiTypeMath.h" 52 #include "ConfigFileManager.h" 52 53 53 54 namespace orxonox … … 72 73 { 73 74 public: 74 ConfigValueContainer( Identifier* identifier, const std::string& varname, MultiTypeMath defvalue);75 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, MultiTypeMath defvalue); 75 76 76 77 /** @brief Returns the configured value. @param value This is only needed to determine the right type. @return The value */ … … 88 89 bool tset(const std::string& input); 89 90 bool reset(); 91 void update(); 90 92 91 93 /** @brief Converts the config-value to a string. @return The string */ … … 97 99 98 100 private: 99 static void readConfigFile(const std::string& filename);100 static void writeConfigFile(const std::string& filename);101 static std::list<std::string>& getConfigFileLines();102 static bool finishedReadingConfigFile(bool finished = false);103 104 101 bool parse(const std::string& input); 105 102 bool parse(const std::string& input, const MultiTypeMath& defvalue); … … 107 104 void setLineInConfigFile(const std::string& input); 108 105 void resetLineInConfigFile(); 109 void searchLineInConfigFile();110 106 111 std::string parseValueStringFromConfigFile(bool bStripped = true);112 113 Identifier* identifier_;//!< The name of the class the variable belongs to107 ConfigFileType type_; //!< The type of the corresponding config-file 108 Identifier* identifier_; //!< The identifier of the class 109 std::string sectionname_; //!< The name of the class the variable belongs to 114 110 std::string varname_; //!< The name of the variable 115 111 std::string defvalueString_; //!< The string of the default-variable -
code/branches/core2/src/orxonox/core/CoreIncludes.h
r957 r1020 50 50 #include "OrxonoxClass.h" 51 51 #include "ConfigValueContainer.h" 52 #include "ConfigFileManager.h" 52 53 #include "Debug.h" 53 54 … … 120 121 if (!container##varname) \ 121 122 { \ 122 container##varname = new orxonox::ConfigValueContainer( this->getIdentifier(), #varname, varname = defvalue); \123 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, varname = defvalue); \ 123 124 this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \ 124 125 } \ … … 139 140 COUT(2) << "Warning: Couldn't reset variable " << #varname << ", corresponding container doesn't exist." << std::endl 140 141 142 /** 143 @brief Assigns the command, defined in the keybind-file, to the key-variable (or an empty string, if there is no entry in the file). 144 @param varname The name of the key-variable 145 */ 146 #define SetKeybind(keyname) \ 147 orxonox::ConfigValueContainer* container##keyname = this->getIdentifier()->getConfigValueContainer(#keyname); \ 148 if (!container##keyname) \ 149 { \ 150 container##keyname = new orxonox::ConfigValueContainer(CFT_Keybindings, this->getIdentifier(), #keyname, keyname = ""); \ 151 this->getIdentifier()->addConfigValueContainer(#keyname, container##keyname); \ 152 } \ 153 container##keyname->getValue(&varname) 154 141 155 #endif /* _CoreIncludes_H__ */ -
code/branches/core2/src/orxonox/core/DebugLevel.cc
r948 r1020 95 95 96 96 // Return a constant value while we're creating the object 97 return 2;97 return 4; 98 98 } 99 99 } -
code/branches/core2/src/orxonox/core/Language.cc
r931 r1020 108 108 109 109 // Read the translation file after the language was configured 110 std::cout << "asdfasdfkjsfkdjaslfkjsaflkjsdfkl\n"; 110 111 this->readTranslatedLanguageFile(); 111 112 } -
code/branches/core2/src/util/MultiTypeMath.cc
r1003 r1020 169 169 ConvertValue(&output, this->vector3_); 170 170 else if (this->type_ == MT_colourvalue) 171 { std::cout << "3_1\n"; 172 ConvertValue(&output, this->colourvalue_);} 171 ConvertValue(&output, this->colourvalue_); 173 172 else if (this->type_ == MT_quaternion) 174 173 ConvertValue(&output, this->quaternion_); … … 190 189 return ConvertValue(&this->vector3_, value, orxonox::Vector3(0, 0, 0)); 191 190 else if (this->type_ == MT_colourvalue) 192 { std::cout << "4_1\n"; 193 return ConvertValue(&this->colourvalue_, value, orxonox::ColourValue(0, 0, 0, 0)); } 191 return ConvertValue(&this->colourvalue_, value, orxonox::ColourValue(0, 0, 0, 0)); 194 192 else if (this->type_ == MT_quaternion) 195 193 return ConvertValue(&this->quaternion_, value, orxonox::Quaternion(1, 0, 0, 0)); -
code/branches/core2/src/util/String.cc
r1006 r1020 62 62 std::string removeTrailingWhitespaces(const std::string& str) 63 63 { 64 unsigned int pos1 = 0; 65 unsigned int pos2 = str.size() - 1; 66 for (; pos1 < str.size() && (str[pos1] == ' ' || str[pos1] == '\t' || str[pos1] == '\n'); pos1++); 67 for (; pos2 >= 0 && (str[pos2] == ' ' || str[pos2] == '\t' || str[pos2] == '\n'); pos2--); 68 return str.substr(pos1, pos2 - pos1 + 1); 69 } 70 71 /** 72 @brief Returns the position of the next quote in the string, starting with start. 73 @param str The string 74 @param start The startposition 75 @return The position of the next quote (std::string::npos if there is no next quote) 76 */ 77 unsigned int getNextQuote(const std::string& str, unsigned int start) 78 { 79 unsigned int quote = start - 1; 80 81 while ((quote = str.find('\"', quote + 1)) != std::string::npos) 82 { 83 unsigned int backslash = quote; 84 unsigned int numbackslashes = 0; 85 for (; backslash > 0; backslash--, numbackslashes++) 86 if (str[backslash - 1] != '\\') 87 break; 88 89 if (numbackslashes % 2 == 0) 90 break; 91 } 92 93 return quote; 64 94 } 65 95 … … 71 101 bool hasStringBetweenQuotes(const std::string& str) 72 102 { 103 unsigned int pos1 = getNextQuote(str, 0); 104 unsigned int pos2 = getNextQuote(str, pos1 + 1); 105 return (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1); 73 106 } 74 107 … … 80 113 std::string getStringBetweenQuotes(const std::string& str) 81 114 { 115 unsigned int pos1 = getNextQuote(str, 0); 116 unsigned int pos2 = getNextQuote(str, pos1 + 1); 117 if (pos1 != std::string::npos && pos2 != std::string::npos) 118 return str.substr(pos1, pos2 - pos1 + 1); 119 else 120 return ""; 82 121 } 83 122 -
code/branches/core2/src/util/String.h
r1006 r1020 38 38 39 39 _UtilExport std::string removeTrailingWhitespaces(const std::string& str); 40 41 _UtilExport unsigned int getNextQuote(const std::string& str, unsigned int start); 40 42 41 43 _UtilExport bool hasStringBetweenQuotes(const std::string& str);
Note: See TracChangeset
for help on using the changeset viewer.