Changeset 1747 for code/trunk/src/core/ConfigValueContainer.cc
- Timestamp:
- Sep 9, 2008, 4:25:52 AM (17 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core3 (added) merged: 1573-1574,1583-1586,1591-1594,1596-1597,1603,1606-1607,1610-1611,1655,1658,1676-1679,1681-1685,1687,1716-1723,1725-1729,1736
- Property svn:mergeinfo changed
-
code/trunk/src/core/ConfigValueContainer.cc
r1505 r1747 47 47 { 48 48 /** 49 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 50 @param type The type of the corresponding config-file 51 @param identifier The identifier of the class the variable belongs to 52 @param varname The name of the variable 53 @param defvalue The default-value 54 */ 55 ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const MultiTypeMath& defvalue) 49 @brief Initializes the ConfigValueContainer with defaultvalues. 50 */ 51 void ConfigValueContainer::init(ConfigFileType type, Identifier* identifier, const std::string& varname) 56 52 { 57 53 this->type_ = type; … … 59 55 this->sectionname_ = identifier->getName(); 60 56 this->varname_ = varname; 61 57 this->callback_ = 0; 58 this->bContainerIsNew_ = true; 59 this->bDoInitialCallback_ = false; 60 this->bAddedDescription_ = false; 61 } 62 63 /** 64 @brief Does some special initialization for single config-values. 65 */ 66 void ConfigValueContainer::initValue(const MultiType& defvalue) 67 { 62 68 this->value_ = defvalue; 63 this->bAddedDescription_ = false;64 69 this->bIsVector_ = false; 65 70 66 this->defvalueString_ = defvalue.toString();71 this->defvalueString_ = this->value_.getString(); 67 72 this->update(); 68 73 } 69 74 70 75 /** 71 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 72 @param type The type of the corresponding config-file 73 @param identifier The identifier of the class the variable belongs to 74 @param varname The name of the variable 75 @param defvalue The default-value 76 */ 77 ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<MultiTypeMath>& defvalue) 78 { 79 this->type_ = type; 80 this->identifier_ = identifier; 81 this->sectionname_ = identifier->getName(); 82 this->varname_ = varname; 83 84 this->valueVector_ = defvalue; 85 this->bAddedDescription_ = false; 76 @brief Does some special initialization for vector config-values. 77 */ 78 void ConfigValueContainer::initVector() 79 { 86 80 this->bIsVector_ = true; 87 81 88 if (defvalue.size() > 0) 89 { 90 this->value_ = defvalue[0]; 91 92 for (unsigned int i = 0; i < defvalue.size(); i++) 93 { 94 ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString(), this->value_.isA(MT_string)); 95 this->defvalueStringVector_.push_back(defvalue[i].toString()); 96 } 97 98 this->update(); 99 } 82 for (unsigned int i = 0; i < this->valueVector_.size(); i++) 83 { 84 ConfigFileManager::getInstance()->getValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_string)); 85 this->defvalueStringVector_.push_back(this->valueVector_[i]); 86 } 87 88 this->update(); 89 } 90 91 /** 92 @brief Destructor: Deletes the callback object if necessary. 93 */ 94 ConfigValueContainer::~ConfigValueContainer() 95 { 96 if (this->callback_) 97 delete this->callback_; 100 98 } 101 99 … … 105 103 @return True if the new value was successfully assigned 106 104 */ 107 bool ConfigValueContainer::set(const MultiType Math& input)108 { 109 if (this->bIsVector_) 110 { 111 return this->callFunctionWithIndex(&ConfigValueContainer::set, input .toString());105 bool ConfigValueContainer::set(const MultiType& input) 106 { 107 if (this->bIsVector_) 108 { 109 return this->callFunctionWithIndex(&ConfigValueContainer::set, input); 112 110 } 113 111 else … … 115 113 if (this->tset(input)) 116 114 { 117 ConfigFileManager::get Singleton()->setValue(this->type_, this->sectionname_, this->varname_, input.toString(), this->value_.isA(MT_string));115 ConfigFileManager::getInstance()->setValue(this->type_, this->sectionname_, this->varname_, input, this->value_.isType(MT_string)); 118 116 return true; 119 117 } … … 128 126 @return True if the new value was successfully assigned 129 127 */ 130 bool ConfigValueContainer::set(unsigned int index, const MultiType Math& input)128 bool ConfigValueContainer::set(unsigned int index, const MultiType& input) 131 129 { 132 130 if (this->bIsVector_) … … 134 132 if (this->tset(index, input)) 135 133 { 136 ConfigFileManager::get Singleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input.toString(), this->value_.isA(MT_string));134 ConfigFileManager::getInstance()->setValue(this->type_, this->sectionname_, this->varname_, index, input, this->value_.isType(MT_string)); 137 135 return true; 138 136 } … … 150 148 @return True if the new value was successfully assigned 151 149 */ 152 bool ConfigValueContainer::tset(const MultiTypeMath& input) 153 { 154 if (this->bIsVector_) 155 { 156 return this->callFunctionWithIndex(&ConfigValueContainer::tset, input.toString()); 157 } 158 else 159 { 160 MultiTypeMath temp = this->value_; 161 if (temp.assimilate(input)) 162 { 163 this->value_ = temp; 164 if (this->identifier_) 165 this->identifier_->updateConfigValues(); 166 167 return true; 168 } 169 } 170 return false; 150 bool ConfigValueContainer::tset(const MultiType& input) 151 { 152 if (this->bIsVector_) 153 { 154 return this->callFunctionWithIndex(&ConfigValueContainer::tset, input); 155 return false; 156 } 157 else 158 { 159 this->value_ = input; 160 161 if (this->identifier_) 162 this->identifier_->updateConfigValues(); 163 164 return true; 165 } 171 166 } 172 167 … … 177 172 @return True if the new value was successfully assigned 178 173 */ 179 bool ConfigValueContainer::tset(unsigned int index, const MultiType Math& input)174 bool ConfigValueContainer::tset(unsigned int index, const MultiType& input) 180 175 { 181 176 if (this->bIsVector_) … … 191 186 for (unsigned int i = this->valueVector_.size(); i <= index; i++) 192 187 { 193 this->valueVector_.push_back(MultiType Math());188 this->valueVector_.push_back(MultiType()); 194 189 } 195 190 } 196 191 197 MultiTypeMath temp = this->value_; 198 if (temp.assimilate(input)) 199 { 200 this->valueVector_[index] = temp; 201 202 if (this->identifier_) 203 this->identifier_->updateConfigValues(); 204 205 return true; 206 } 192 this->valueVector_[index] = input; 193 194 if (this->identifier_) 195 this->identifier_->updateConfigValues(); 196 197 return true; 207 198 } 208 199 else 209 200 { 210 201 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 211 }212 return false;202 return false; 203 } 213 204 } 214 205 … … 218 209 @return True if the new entry was successfully added 219 210 */ 220 bool ConfigValueContainer::add(const MultiType Math& input)211 bool ConfigValueContainer::add(const MultiType& input) 221 212 { 222 213 if (this->bIsVector_) … … 241 232 this->valueVector_.erase(this->valueVector_.begin() + index); 242 233 for (unsigned int i = index; i < this->valueVector_.size(); i++) 243 ConfigFileManager::get Singleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isA(MT_string));244 ConfigFileManager::get Singleton()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->valueVector_.size());234 ConfigFileManager::getInstance()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_string)); 235 ConfigFileManager::getInstance()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->valueVector_.size()); 245 236 246 237 return true; … … 266 257 if (!this->set(i, this->defvalueStringVector_[i])) 267 258 success = false; 268 ConfigFileManager::get Singleton()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->defvalueStringVector_.size());259 ConfigFileManager::getInstance()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->defvalueStringVector_.size()); 269 260 return success; 270 261 } … … 277 268 { 278 269 if (!this->bIsVector_) 279 this->value_ .fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_, this->value_.isA(MT_string)));270 this->value_ = ConfigFileManager::getInstance()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_, this->value_.isType(MT_string)); 280 271 else 281 272 { 282 273 this->valueVector_.clear(); 283 for (unsigned int i = 0; i < ConfigFileManager::get Singleton()->getVectorSize(this->type_, this->sectionname_, this->varname_); i++)274 for (unsigned int i = 0; i < ConfigFileManager::getInstance()->getVectorSize(this->type_, this->sectionname_, this->varname_); i++) 284 275 { 285 276 if (i < this->defvalueStringVector_.size()) 286 277 { 287 this->value_ .fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isA(MT_string)));278 this->value_ = ConfigFileManager::getInstance()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isType(MT_string)); 288 279 } 289 280 else 290 281 { 291 this->value_ .fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, MultiTypeMath(), this->value_.isA(MT_string)));282 this->value_ = ConfigFileManager::getInstance()->getValue(this->type_, this->sectionname_, this->varname_, i, MultiType(), this->value_.isType(MT_string)); 292 283 } 293 284 … … 303 294 @return The returnvalue of the functioncall 304 295 */ 305 bool ConfigValueContainer::callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiType Math&), const std::string& input)296 bool ConfigValueContainer::callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiType&), const std::string& input) 306 297 { 307 298 SubString token(input, " ", SubString::WhiteSpaces, true, '\\', false, '"', false, '(', ')', false, '\0'); … … 335 326 @param description The description 336 327 */ 337 voidConfigValueContainer::description(const std::string& description)328 ConfigValueContainer& ConfigValueContainer::description(const std::string& description) 338 329 { 339 330 if (!this->bAddedDescription_) … … 343 334 this->bAddedDescription_ = true; 344 335 } 336 return (*this); 345 337 } 346 338
Note: See TracChangeset
for help on using the changeset viewer.