Changeset 1030
- Timestamp:
- Apr 12, 2008, 3:34:55 PM (17 years ago)
- Location:
- code/branches/core2
- Files:
-
- 1 added
- 1 deleted
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/Orxonox.cc
r1020 r1030 1196 1196 ib->registerListener(testlistener, &Testlistener::removeLast, '\b', true); 1197 1197 1198 Test3* test16_1 = new Test3; 1199 test16_1->configOutput(); 1200 1198 1201 startRenderLoop(); 1199 1202 } -
code/branches/core2/src/orxonox/core/CommandExecutor.cc
r1001 r1030 29 29 #include "ConsoleCommand.h" 30 30 #include "util/String.h" 31 #include "util/Convert.h" 31 32 #include "Identifier.h" 32 33 #include "Language.h" … … 1313 1314 { 1314 1315 AddLanguageEntry("CommandExecutor::oldvalue", "old value"); 1315 return "{" + container->getTypename() + "} (" + GetLocalisation("CommandExecutor::oldvalue") + ": " + container->toString() + ")"; 1316 if (!container->isVector()) 1317 return ("{" + container->getTypename() + "} (" + GetLocalisation("CommandExecutor::oldvalue") + ": " + container->toString() + ")"); 1318 else 1319 return ("(vector<" + container->getTypename() + ">) (size: " + getConvertedValue<unsigned int, std::string>(container->getVectorSize()) + ")"); 1316 1320 } 1317 1321 -
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 -
code/branches/core2/src/orxonox/core/ConfigFileManager.h
r1027 r1030 107 107 108 108 /////////////////////////////// 109 // ConfigFileEntry ArrayValue //109 // ConfigFileEntryVectorValue // 110 110 /////////////////////////////// 111 class _CoreExport ConfigFileEntry ArrayValue : public ConfigFileEntryValue112 { 113 public: 114 inline ConfigFileEntry ArrayValue(const std::string& name, unsigned int index, const std::string& value = "", const std::string& additionalComment = "") : ConfigFileEntryValue(name, value, additionalComment), index_(index) {}115 inline virtual ~ConfigFileEntry ArrayValue() {}111 class _CoreExport ConfigFileEntryVectorValue : public ConfigFileEntryValue 112 { 113 public: 114 inline ConfigFileEntryVectorValue(const std::string& name, unsigned int index, const std::string& value = "", const std::string& additionalComment = "") : ConfigFileEntryValue(name, value, additionalComment), index_(index) {} 115 inline virtual ~ConfigFileEntryVectorValue() {} 116 116 117 117 inline virtual unsigned int getIndex() const … … 179 179 inline const std::string& getValue(const std::string& name, unsigned int index, const std::string& fallback) 180 180 { return this->getEntry(name, index, fallback)->getValue(); } 181 182 void deleteVectorEntries(const std::string& name, unsigned int startindex = 0); 183 unsigned int getVectorSize(const std::string& name); 181 184 182 185 std::string getFileEntry() const; … … 216 219 void load(bool bCreateIfNotExisting = true); 217 220 void save() const; 218 void clean( );221 void clean(bool bCleanComments = false); 219 222 220 223 inline void setValue(const std::string& section, const std::string& name, const std::string& value) … … 228 231 { const std::string& output = this->getSection(section)->getValue(name, index, fallback); this->saveIfUpdated(); return output; } 229 232 233 inline void deleteVectorEntries(const std::string& section, const std::string& name, unsigned int startindex = 0) 234 { this->getSection(section)->deleteVectorEntries(name, startindex); } 235 inline unsigned int getVectorSize(const std::string& section, const std::string& name) 236 { return this->getSection(section)->getVectorSize(name); } 237 230 238 private: 231 239 ConfigFileSection* getSection(const std::string& section); … … 250 258 void load(bool bCreateIfNotExisting = true); 251 259 void save(); 252 void clean( );260 void clean(bool bCleanComments = false); 253 261 254 262 void load(ConfigFileType type, bool bCreateIfNotExisting = true); 255 263 void save(ConfigFileType type); 256 void clean(ConfigFileType type );264 void clean(ConfigFileType type, bool bCleanComments = false); 257 265 258 266 inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& value) … … 266 274 { return this->getFile(type)->getValue(section, name, index, fallback); } 267 275 276 inline void deleteVectorEntries(ConfigFileType type, const std::string& section, const std::string& name, unsigned int startindex = 0) 277 { this->getFile(type)->deleteVectorEntries(section, name, startindex); } 278 inline unsigned int getVectorSize(ConfigFileType type, const std::string& section, const std::string& name) 279 { return this->getFile(type)->getVectorSize(section, name); } 280 268 281 void updateConfigValues() const; 269 282 void updateConfigValues(ConfigFileType type) const; -
code/branches/core2/src/orxonox/core/ConfigValueContainer.cc
r1023 r1030 35 35 #include "ConfigValueContainer.h" 36 36 #include "Language.h" 37 #include "util/SubString.h" 38 #include "util/Convert.h" 39 40 #define MAX_VECTOR_INDEX 255 // to avoid up to 4*10^9 vector entries in the config file after accidentally using a wrong argument 37 41 38 42 … … 41 45 /** 42 46 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 43 @param value This is only needed to determine the right type.44 @param classname The nameof the class the variable belongs to47 @param type The type of the corresponding config-file 48 @param identifier The identifier of the class the variable belongs to 45 49 @param varname The name of the variable 46 50 @param defvalue The default-value 47 51 */ 48 ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, MultiTypeMathdefvalue)52 ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const MultiTypeMath& defvalue) 49 53 { 50 54 this->type_ = type; … … 55 59 this->value_ = defvalue; 56 60 this->bAddedDescription_ = false; 61 this->bIsVector_ = false; 57 62 58 63 this->defvalueString_ = defvalue.toString(); 59 64 this->update(); 65 } 66 67 /** 68 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 69 @param type The type of the corresponding config-file 70 @param identifier The identifier of the class the variable belongs to 71 @param varname The name of the variable 72 @param defvalue The default-value 73 */ 74 ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<MultiTypeMath>& defvalue) 75 { 76 this->type_ = type; 77 this->identifier_ = identifier; 78 this->sectionname_ = identifier->getName(); 79 this->varname_ = varname; 80 81 this->valueVector_ = defvalue; 82 this->bAddedDescription_ = false; 83 this->bIsVector_ = true; 84 85 if (defvalue.size() > 0) 86 this->value_ = defvalue[0]; 87 88 for (unsigned int i = 0; i < defvalue.size(); i++) 89 ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString()); 90 91 for (unsigned int i = 0; i < defvalue.size(); i++) 92 this->defvalueStringVector_.push_back(defvalue[i].toString()); 93 94 this->update(); 95 } 96 97 /** 98 @brief Adds a new entry to the end of the vector. 99 @param input The new entry 100 @return True if the new entry was successfully added 101 */ 102 bool ConfigValueContainer::add(const std::string& input) 103 { 104 if (this->bIsVector_) 105 return this->set(this->valueVector_.size(), input); 106 107 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 108 return false; 109 } 110 111 /** 112 @brief Removes an existing entry from the vector. 113 @param index The index of the entry 114 @return True if the entry was removed 115 */ 116 bool ConfigValueContainer::remove(unsigned int index) 117 { 118 if (this->bIsVector_) 119 { 120 if (index < this->valueVector_.size()) 121 { 122 this->valueVector_.erase(this->valueVector_.begin() + index); 123 for (unsigned int i = index; i < this->valueVector_.size(); i++) 124 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i]); 125 ConfigFileManager::getSingleton()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->valueVector_.size()); 126 127 return true; 128 } 129 COUT(1) << "Error: Invalid vector-index." << std::endl; 130 } 131 132 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 133 return false; 60 134 } 61 135 … … 67 141 bool ConfigValueContainer::set(const std::string& input) 68 142 { 143 if (this->bIsVector_) 144 { 145 SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0'); 146 int index = -1; 147 bool success = false; 148 149 if (token.size() > 0) 150 success = ConvertValue(&index, token[0]); 151 152 if (!success || index < 0 || index > MAX_VECTOR_INDEX) 153 { 154 if (!success) 155 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl; 156 else 157 COUT(1) << "Error: Invalid vector-index." << std::endl; 158 return false; 159 } 160 161 if (token.size() >= 2) 162 return this->set(index, token.subSet(1).join()); 163 else 164 return this->set(index, ""); 165 } 166 69 167 bool success = this->tset(input); 70 this->setLineInConfigFile(input);168 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input); 71 169 return success; 170 } 171 172 /** 173 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file. 174 @param index The index in the vector 175 @param input The new value 176 @return True if the new value was successfully assigned 177 */ 178 bool ConfigValueContainer::set(unsigned int index, const std::string& input) 179 { 180 if (this->bIsVector_) 181 { 182 bool success = this->tset(index, input); 183 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input); 184 return success; 185 } 186 187 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 188 return false; 72 189 } 73 190 … … 86 203 87 204 /** 205 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary). 206 @param index The index in the vector 207 @param input The new value 208 @return True if the new value was successfully assigned 209 */ 210 bool ConfigValueContainer::tset(unsigned int index, const std::string& input) 211 { 212 if (this->bIsVector_) 213 { 214 bool success = this->parse(index, input); 215 if (this->identifier_) 216 this->identifier_->updateConfigValues(); 217 return success; 218 } 219 220 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 221 return false; 222 } 223 224 /** 88 225 @brief Sets the value of the variable back to the default value and resets the config-file entry. 89 226 */ 90 227 bool ConfigValueContainer::reset() 91 228 { 92 return this->set(this->defvalueString_); 229 if (!this->bIsVector_) 230 return this->set(this->defvalueString_); 231 else 232 { 233 bool success = true; 234 for (unsigned int i = 0; i < this->defvalueStringVector_.size(); i++) 235 if (!this->set(i, this->defvalueStringVector_[i])) 236 success = false; 237 ConfigFileManager::getSingleton()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->defvalueStringVector_.size()); 238 return success; 239 } 93 240 } 94 241 … … 98 245 void ConfigValueContainer::update() 99 246 { 100 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_)); 247 if (!this->bIsVector_) 248 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_)); 249 else 250 { 251 this->valueVector_.clear(); 252 for (unsigned int i = 0; i < ConfigFileManager::getSingleton()->getVectorSize(this->type_, this->sectionname_, this->varname_); i++) 253 { 254 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i])); 255 this->valueVector_.push_back(this->value_); 256 } 257 } 101 258 } 102 259 … … 108 265 bool ConfigValueContainer::parse(const std::string& input) 109 266 { 267 if (this->bIsVector_) 268 { 269 SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0'); 270 int index = -1; 271 bool success = false; 272 273 if (token.size() > 0) 274 success = ConvertValue(&index, token[0]); 275 276 if (!success || index < 0 || index > MAX_VECTOR_INDEX) 277 return false; 278 279 if (token.size() >= 2) 280 return this->parse(index, token.subSet(1).join()); 281 else 282 return this->parse(index, ""); 283 } 284 110 285 MultiTypeMath temp = this->value_; 111 286 if (temp.fromString(input)) … … 114 289 return true; 115 290 } 291 return false; 292 } 293 294 /** 295 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 296 @param index The index in the vector 297 @param input The string to convert 298 @return True if the string was successfully parsed 299 */ 300 bool ConfigValueContainer::parse(unsigned int index, const std::string& input) 301 { 302 if (this->bIsVector_) 303 { 304 if (index >= this->valueVector_.size()) 305 { 306 for (unsigned int i = this->valueVector_.size(); i <= index; i++) 307 { 308 this->valueVector_.push_back(MultiTypeMath()); 309 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i]); 310 } 311 } 312 313 MultiTypeMath temp = this->value_; 314 if (temp.fromString(input)) 315 { 316 this->valueVector_[index] = temp; 317 return true; 318 } 319 return false; 320 } 321 322 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 116 323 return false; 117 324 } … … 125 332 bool ConfigValueContainer::parse(const std::string& input, const MultiTypeMath& defvalue) 126 333 { 127 MultiTypeMath temp = defvalue; 128 if (temp.fromString(input)) 129 { 130 this->value_ = temp; 334 if (this->parse(input)) 131 335 return true; 132 } 133 else 134 { 135 this->value_ = defvalue; 336 337 this->value_ = defvalue; 338 return false; 339 } 340 341 /** 342 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 343 @param index The index in the vector 344 @param input The string to convert 345 @param defvalue The default value to assign if the parsing fails 346 @return True if the string was successfully parsed 347 */ 348 bool ConfigValueContainer::parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue) 349 { 350 if (this->bIsVector_) 351 { 352 if (this->parse(index, input)) 353 return true; 354 355 this->valueVector_[index] = defvalue; 136 356 return false; 137 357 } 138 } 139 140 /** 141 @brief Sets the corresponding entry in the config-file to a given value. 142 */ 143 void ConfigValueContainer::setLineInConfigFile(const std::string& input) 144 { 145 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input); 146 } 147 148 /** 149 @brief Sets the corresponding entry in the config-file back to the default value. 150 */ 151 void ConfigValueContainer::resetLineInConfigFile() 152 { 153 this->setLineInConfigFile(this->value_.toString()); 358 359 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 360 return false; 154 361 } 155 362 -
code/branches/core2/src/orxonox/core/ConfigValueContainer.h
r1020 r1030 43 43 #define _ConfigValueContainer_H__ 44 44 45 #include <list>46 45 #include <string> 46 #include <vector> 47 47 48 48 #include "CorePrereqs.h" … … 73 73 { 74 74 public: 75 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, MultiTypeMath defvalue); 75 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const MultiTypeMath& defvalue); 76 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<MultiTypeMath>& defvalue); 76 77 77 78 /** @brief Returns the configured value. @param value This is only needed to determine the right type. @return The value */ … … 79 80 inline ConfigValueContainer& getValue(T* value) 80 81 { this->value_.getValue(value); return *this; } 82 template <typename T> 83 inline ConfigValueContainer& getValue(std::vector<T>* value) 84 { 85 value->clear(); 86 for (unsigned int i = 0; i < this->valueVector_.size(); i++) 87 value->push_back(this->valueVector_[i]); 88 return *this; 89 } 81 90 82 inline const std::string& getName() 91 inline const std::string& getName() const 83 92 { return this->varname_; } 93 inline bool isVector() const 94 { return this->bIsVector_; } 95 inline unsigned int getVectorSize() const 96 { return this->valueVector_.size(); } 84 97 85 98 void description(const std::string& description); 86 99 const std::string& getDescription() const; 87 100 101 bool add(const std::string& input); 102 bool remove(unsigned int index); 88 103 bool set(const std::string& input); 89 104 bool tset(const std::string& input); … … 102 117 bool parse(const std::string& input, const MultiTypeMath& defvalue); 103 118 104 void setLineInConfigFile(const std::string& input); 105 void resetLineInConfigFile(); 119 bool set(unsigned int index, const std::string& input); 120 bool tset(unsigned int index, const std::string& input); 121 bool parse(unsigned int index, const std::string& input); 122 bool parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue); 106 123 107 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 110 std::string varname_; //!< The name of the variable 111 std::string defvalueString_; //!< The string of the default-variable 124 bool bIsVector_; //!< True if the container contains a std::vector 112 125 113 MultiTypeMath value_; //!< The value 126 ConfigFileType type_; //!< The type of the corresponding config-file 127 Identifier* identifier_; //!< The identifier of the class 128 std::string sectionname_; //!< The name of the class the variable belongs to 129 std::string varname_; //!< The name of the variable 130 std::string defvalueString_; //!< The string of the default-value 131 std::vector<std::string> defvalueStringVector_; //!< A vector, containg the strings of the default-values in case we're storing a vector 114 132 115 std::list<std::string>::iterator configFileLine_; //!< An iterator, pointing to the entry of the variable in the config-file 133 MultiTypeMath value_; //!< The value 134 std::vector<MultiTypeMath> valueVector_; //!< A vector, containg the values in case we're storing a vector 116 135 117 bool bAddedDescription_;//!< True if a description was added118 LanguageEntryLabel description_;//!< The description136 bool bAddedDescription_; //!< True if a description was added 137 LanguageEntryLabel description_; //!< The description 119 138 }; 120 139 } -
code/branches/core2/src/orxonox/core/CoreIncludes.h
r1020 r1030 28 28 /** 29 29 @file CoreIncludes.h 30 @brief Definition of macros and typedefs.30 @brief Definition of macros for Identifier and Factory. 31 31 32 32 Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface … … 40 40 #define _CoreIncludes_H__ 41 41 42 #include "CorePrereqs.h"43 44 // All needed header-files45 42 #include "Identifier.h" 46 43 #include "ClassManager.h" 47 44 #include "Factory.h" 48 45 #include "ClassFactory.h" 49 #include "Iterator.h"50 #include "OrxonoxClass.h"51 #include "ConfigValueContainer.h"52 #include "ConfigFileManager.h"53 46 #include "Debug.h" 54 47 55 48 56 // All needed macros57 49 /** 58 50 @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject. … … 112 104 orxonox::Factory::getIdentifier(StringOrInt) 113 105 114 /**115 @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).116 @param varname The name of the variable117 @param defvalue The default-value of the variable118 */119 #define SetConfigValue(varname, defvalue) \120 orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \121 if (!container##varname) \122 { \123 container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, varname = defvalue); \124 this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \125 } \126 container##varname->getValue(&varname)127 128 /**129 @brief Sets the variable and the config-file entry back to the previously defined default-value.130 @param varname The name of the variable131 */132 #define ResetConfigValue(varname) \133 orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \134 if (container##varname##reset) \135 { \136 container##varname##reset->reset(); \137 container##varname##reset->getValue(&varname); \138 } \139 else \140 COUT(2) << "Warning: Couldn't reset variable " << #varname << ", corresponding container doesn't exist." << std::endl141 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-variable145 */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 155 106 #endif /* _CoreIncludes_H__ */ -
code/branches/core2/src/orxonox/core/DebugLevel.cc
r1023 r1030 33 33 #include "DebugLevel.h" 34 34 #include "CoreIncludes.h" 35 #include "ConfigValueIncludes.h" 35 36 36 37 namespace orxonox -
code/branches/core2/src/orxonox/core/Language.cc
r1023 r1030 35 35 #include "CoreIncludes.h" 36 36 #include "Language.h" 37 #include "ConfigValueIncludes.h" 37 38 38 39 namespace orxonox -
code/branches/core2/src/orxonox/core/OutputHandler.cc
r947 r1030 47 47 this->logfilename_ = logfilename; 48 48 this->logfile_.open(this->logfilename_.c_str(), std::fstream::out); 49 this->logfile_ << "Started log " << std::endl;49 this->logfile_ << "Started log at yyyy/mm/dd hh:mm:ss" << std::endl; 50 50 this->logfile_.flush(); 51 51 } -
code/branches/core2/src/orxonox/objects/Fighter.cc
r790 r1030 37 37 #include "util/tinyxml/tinyxml.h" 38 38 #include "util/String2Number.h" 39 #include "../core/CoreIncludes.h" 39 #include "core/CoreIncludes.h" 40 #include "core/ConfigValueIncludes.h" 40 41 #include "../Orxonox.h" 41 42 #include "../particle/ParticleInterface.h" -
code/branches/core2/src/orxonox/objects/Projectile.cc
r995 r1030 30 30 #include "core/CoreIncludes.h" 31 31 #include "core/Executor.h" 32 #include "core/ConfigValueIncludes.h" 32 33 33 34 #include "SpaceShip.h" -
code/branches/core2/src/orxonox/objects/SpaceShip.cc
r955 r1030 39 39 #include "util/String2Number.h" 40 40 #include "util/Math.h" 41 #include "../core/CoreIncludes.h" 42 #include "../core/Debug.h" 41 #include "core/CoreIncludes.h" 42 #include "core/ConfigValueIncludes.h" 43 #include "core/Debug.h" 43 44 #include "../Orxonox.h" 44 45 #include "../particle/ParticleInterface.h" -
code/branches/core2/src/orxonox/objects/test3.cc
r871 r1030 30 30 #include "test3.h" 31 31 #include "core/CoreIncludes.h" 32 #include "core/ConfigValueIncludes.h" 32 33 33 34 namespace orxonox … … 56 57 SetConfigValue(value_vector3_, Vector3(13, 26, 39)); 57 58 SetConfigValue(value_colourvalue_, ColourValue(1.0, 0.5, 0.25, 0.887)); 59 SetConfigValueVector(vector_int_, std::vector<int>(1, 13)); 60 SetConfigValueVector(vector_string_, std::vector<std::string>(3, "nothing")); 61 SetConfigValueVector(vector_vector3_, std::vector<Vector3>(1, Vector3(3, 2, 1))); 58 62 } 59 63 … … 64 68 void Test3::configOutput() 65 69 { 66 std::cout << "int: " << this->value_int_ << std::endl; 67 std::cout << "uint: " << this->value_uint_ << std::endl; 68 std::cout << "char: " << (int)this->value_char_ << std::endl; 69 std::cout << "uchar: " << (int)this->value_uchar_ << std::endl; 70 std::cout << "float: " << this->value_float_ << std::endl; 71 std::cout << "double: " << this->value_double_ << std::endl; 72 std::cout << "bool: " << this->value_bool_ << std::endl; 73 std::cout << "string: " << this->value_string_ << std::endl; 74 std::cout << "constchar: " << this->value_constchar_ << std::endl; 75 std::cout << "vector2: " << this->value_vector2_ << std::endl; 76 std::cout << "vector3: " << this->value_vector3_ << std::endl; 77 std::cout << "colourvalue: " << this->value_colourvalue_ << std::endl; 70 std::cout << "int: " << this->value_int_ << std::endl; 71 std::cout << "uint: " << this->value_uint_ << std::endl; 72 std::cout << "char: " << (int)this->value_char_ << std::endl; 73 std::cout << "uchar: " << (int)this->value_uchar_ << std::endl; 74 std::cout << "float: " << this->value_float_ << std::endl; 75 std::cout << "double: " << this->value_double_ << std::endl; 76 std::cout << "bool: " << this->value_bool_ << std::endl; 77 std::cout << "string: >" << this->value_string_ << "<" << std::endl; 78 std::cout << "constchar: >" << this->value_constchar_ << "<" << std::endl; 79 std::cout << "vector2: " << this->value_vector2_ << std::endl; 80 std::cout << "vector3: " << this->value_vector3_ << std::endl; 81 std::cout << "colourvalue: " << this->value_colourvalue_ << std::endl; 82 std::cout << std::endl; 83 for (unsigned int i = 0; i < this->vector_int_.size(); i++) 84 std::cout << "vector<int>: " << i << ": " << this->vector_int_[i] << std::endl; 85 for (unsigned int i = 0; i < this->vector_string_.size(); i++) 86 std::cout << "vector<string>: " << i << ": " << this->vector_string_[i] << std::endl; 87 for (unsigned int i = 0; i < this->vector_vector3_.size(); i++) 88 std::cout << "vector<vector3>: " << i << ": " << this->vector_vector3_[i] << std::endl; 78 89 } 79 90 -
code/branches/core2/src/orxonox/objects/test3.h
r871 r1030 1 1 #ifndef _Test3_H__ 2 2 #define _Test3_H__ 3 4 #include <vector> 3 5 4 6 #include "core/BaseObject.h" … … 36 38 Vector3 value_vector3_; 37 39 ColourValue value_colourvalue_; 40 41 std::vector<int> vector_int_; 42 std::vector<std::string> vector_string_; 43 std::vector<Vector3> vector_vector3_; 38 44 }; 39 45 }
Note: See TracChangeset
for help on using the changeset viewer.