Changeset 1446 for code/branches/network/src/core/ConfigValueContainer.cc
- Timestamp:
- May 28, 2008, 5:30:11 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/core/ConfigValueContainer.cc
r1444 r1446 87 87 88 88 if (defvalue.size() > 0) 89 this->value_ = defvalue[0]; 90 91 for (unsigned int i = 0; i < defvalue.size(); i++) 92 ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString(), this->value_.isA(MT_string)); 93 94 for (unsigned int i = 0; i < defvalue.size(); i++) 95 this->defvalueStringVector_.push_back(defvalue[i].toString()); 96 97 this->update(); 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 } 100 } 101 102 /** 103 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file. 104 @param input The new value 105 @return True if the new value was successfully assigned 106 */ 107 bool ConfigValueContainer::set(const MultiTypeMath& input) 108 { 109 if (this->bIsVector_) 110 { 111 return this->callFunctionWithIndex(&ConfigValueContainer::set, input.toString()); 112 } 113 else 114 { 115 if (this->tset(input)) 116 { 117 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input.toString(), this->value_.isA(MT_string)); 118 return true; 119 } 120 } 121 return false; 122 } 123 124 /** 125 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file. 126 @param index The index in the vector 127 @param input The new value 128 @return True if the new value was successfully assigned 129 */ 130 bool ConfigValueContainer::set(unsigned int index, const MultiTypeMath& input) 131 { 132 if (this->bIsVector_) 133 { 134 if (this->tset(index, input)) 135 { 136 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input.toString(), this->value_.isA(MT_string)); 137 return true; 138 } 139 } 140 else 141 { 142 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 143 } 144 return false; 145 } 146 147 /** 148 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary). 149 @param input The new value. If bIsVector_ then write "index value" 150 @return True if the new value was successfully assigned 151 */ 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; 171 } 172 173 /** 174 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary). 175 @param index The index in the vector 176 @param input The new value 177 @return True if the new value was successfully assigned 178 */ 179 bool ConfigValueContainer::tset(unsigned int index, const MultiTypeMath& input) 180 { 181 if (this->bIsVector_) 182 { 183 if (index > MAX_VECTOR_INDEX) 184 { 185 COUT(1) << "Error: Index " << index << " is too large." << std::endl; 186 return false; 187 } 188 189 if (index >= this->valueVector_.size()) 190 { 191 for (unsigned int i = this->valueVector_.size(); i <= index; i++) 192 { 193 this->valueVector_.push_back(MultiTypeMath()); 194 } 195 } 196 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 } 207 } 208 else 209 { 210 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 211 } 212 return false; 98 213 } 99 214 … … 103 218 @return True if the new entry was successfully added 104 219 */ 105 bool ConfigValueContainer::add(const std::string& input)220 bool ConfigValueContainer::add(const MultiTypeMath& input) 106 221 { 107 222 if (this->bIsVector_) … … 123 238 if (index < this->valueVector_.size()) 124 239 { 240 // Erase the entry from the vector, change (shift) all entries beginning with index in the config file, remove the last entry from the file 125 241 this->valueVector_.erase(this->valueVector_.begin() + index); 126 242 for (unsigned int i = index; i < this->valueVector_.size(); i++) … … 131 247 } 132 248 COUT(1) << "Error: Invalid vector-index." << std::endl; 133 }134 135 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;136 return false;137 }138 139 /**140 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file.141 @param input The new value. If bIsVector_ then write "index value"142 @return True if the new value was successfully assigned143 */144 bool ConfigValueContainer::set(const std::string& input)145 {146 if (this->bIsVector_)147 {148 SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0');149 int index = -1;150 bool success = false;151 152 if (token.size() > 0)153 success = ConvertValue(&index, token[0]);154 155 if (!success || index < 0 || index > MAX_VECTOR_INDEX)156 {157 if (!success)158 {159 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl;160 }161 else162 {163 COUT(1) << "Error: Invalid vector-index." << std::endl;164 }165 return false;166 }167 168 if (token.size() >= 2)169 return this->set(index, token.subSet(1).join());170 else171 return this->set(index, "");172 }173 174 bool success = this->tset(input);175 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input, this->value_.isA(MT_string));176 return success;177 }178 179 /**180 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file.181 @param index The index in the vector182 @param input The new value183 @return True if the new value was successfully assigned184 */185 bool ConfigValueContainer::set(unsigned int index, const std::string& input)186 {187 if (this->bIsVector_)188 {189 bool success = this->tset(index, input);190 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input, this->value_.isA(MT_string));191 return success;192 }193 194 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;195 return false;196 }197 198 /**199 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).200 @param input The new value201 @return True if the new value was successfully assigned202 */203 bool ConfigValueContainer::tset(const std::string& input)204 {205 bool success = this->parse(input);206 if (this->identifier_)207 this->identifier_->updateConfigValues();208 return success;209 }210 211 /**212 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).213 @param index The index in the vector214 @param input The new value215 @return True if the new value was successfully assigned216 */217 bool ConfigValueContainer::tset(unsigned int index, const std::string& input)218 {219 if (this->bIsVector_)220 {221 bool success = this->parse(index, input);222 if (this->identifier_)223 this->identifier_->updateConfigValues();224 return success;225 249 } 226 250 … … 259 283 for (unsigned int i = 0; i < ConfigFileManager::getSingleton()->getVectorSize(this->type_, this->sectionname_, this->varname_); i++) 260 284 { 261 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isA(MT_string))); 262 this->valueVector_.push_back(this->value_); 263 } 264 } 265 } 266 267 /** 268 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 269 @param input The string to convert 270 @return True if the string was successfully parsed 271 */ 272 bool ConfigValueContainer::parse(const std::string& input) 273 { 274 if (this->bIsVector_) 275 { 276 SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0'); 277 int index = -1; 278 bool success = false; 279 280 if (token.size() > 0) 281 success = ConvertValue(&index, token[0]); 282 283 if (!success || index < 0 || index > MAX_VECTOR_INDEX) 284 { 285 if (!success) 285 if (i < this->defvalueStringVector_.size()) 286 286 { 287 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl;287 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isA(MT_string))); 288 288 } 289 289 else 290 290 { 291 COUT(1) << "Error: Invalid vector-index." << std::endl;291 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, MultiTypeMath(), this->value_.isA(MT_string))); 292 292 } 293 return false; 294 } 295 296 if (token.size() >= 2) 297 return this->parse(index, token.subSet(1).join()); 293 294 this->valueVector_.push_back(this->value_); 295 } 296 } 297 } 298 299 /** 300 @brief Calls the given function with parsed index and the parsed argument from the input string. 301 @param function The function to call 302 @param input The input string 303 @return The returnvalue of the functioncall 304 */ 305 bool ConfigValueContainer::callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiTypeMath&), const std::string& input) 306 { 307 SubString token(input, " ", SubString::WhiteSpaces, true, '\\', false, '"', false, '(', ')', false, '\0'); 308 int index = -1; 309 bool success = false; 310 311 if (token.size() > 0) 312 success = ConvertValue(&index, token[0]); 313 314 if (!success || index < 0 || index > MAX_VECTOR_INDEX) 315 { 316 if (!success) 317 { 318 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl; 319 } 298 320 else 299 return this->parse(index, ""); 300 } 301 302 MultiTypeMath temp = this->value_; 303 if (temp.fromString(input)) 304 { 305 this->value_ = temp; 306 return true; 307 } 308 return false; 309 } 310 311 /** 312 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 313 @param index The index in the vector 314 @param input The string to convert 315 @return True if the string was successfully parsed 316 */ 317 bool ConfigValueContainer::parse(unsigned int index, const std::string& input) 318 { 319 if (this->bIsVector_) 320 { 321 if (index >= this->valueVector_.size()) 322 { 323 for (unsigned int i = this->valueVector_.size(); i <= index; i++) 324 { 325 this->valueVector_.push_back(MultiTypeMath()); 326 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isA(MT_string)); 327 } 328 } 329 330 MultiTypeMath temp = this->value_; 331 if (temp.fromString(input)) 332 { 333 this->valueVector_[index] = temp; 334 return true; 321 { 322 COUT(1) << "Error: Invalid vector-index." << std::endl; 335 323 } 336 324 return false; 337 325 } 338 326 339 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 340 return false; 341 } 342 343 /** 344 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 345 @param input The string to convert 346 @param defvalue The default value to assign if the parsing fails 347 @return True if the string was successfully parsed 348 */ 349 bool ConfigValueContainer::parse(const std::string& input, const MultiTypeMath& defvalue) 350 { 351 if (this->parse(input)) 352 return true; 353 354 this->value_ = defvalue; 355 return false; 356 } 357 358 /** 359 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 360 @param index The index in the vector 361 @param input The string to convert 362 @param defvalue The default value to assign if the parsing fails 363 @return True if the string was successfully parsed 364 */ 365 bool ConfigValueContainer::parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue) 366 { 367 if (this->bIsVector_) 368 { 369 if (this->parse(index, input)) 370 return true; 371 372 this->valueVector_[index] = defvalue; 373 return false; 374 } 375 376 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 377 return false; 327 if (token.size() >= 2) 328 return (this->*function)(index, token.subSet(1).join()); 329 else 330 return (this->*function)(index, ""); 378 331 } 379 332
Note: See TracChangeset
for help on using the changeset viewer.