Changeset 20009
- Timestamp:
- 04/27/07 14:13:55 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
juggler/trunk/modules/jackal/config/jccl/Config/Configuration.cpp
r19811 r20009 45 45 { 46 46 47 48 /** 49 * This is a helper for use with std::find_if() for comparing element names. 50 */ 51 struct ElementNamePred 52 { 53 ElementNamePred(const std::string& name) 54 : mName(name) 55 {} 56 57 bool operator()(jccl::ConfigElementPtr element) 58 { 59 return (element->getName() == mName); 60 } 61 62 std::string mName; 63 }; 64 47 65 Configuration::Configuration() 48 66 {} … … 108 126 } 109 127 return false; 128 } 129 130 void Configuration::add(ConfigElementPtr newElement) 131 { 132 // Before we can add newElement to the database, we have to determine 133 // if there is already a element with the same name. 134 std::vector<ConfigElementPtr>::iterator iter = 135 std::find_if(mElements.begin(), mElements.end(), 136 ElementNamePred(newElement->getName())); 137 138 // If no existing element has the same name as newElement, then we 139 // can just add it to the end. 140 if ( iter == mElements.end() ) 141 { 142 mElements.push_back(newElement); 143 } 144 // Otherwise, overwrite the old version. 145 else 146 { 147 *iter = newElement; 148 } 110 149 } 111 150 … … 323 362 } 324 363 325 /**326 * This is a helper for use with std::find_if() for comparing element names.327 */328 struct ElementNamePred329 {330 ElementNamePred(const std::string& name)331 : mName(name)332 {}333 334 bool operator()(jccl::ConfigElementPtr element)335 {336 return (element->getName() == mName);337 }338 339 std::string mName;340 };341 342 364 /** Load the elements from a given 'elements' tree into this configuration. */ 343 365 bool Configuration::loadFromElementNode(cppdom::NodePtr elementsNode, … … 370 392 else 371 393 { 372 // Before we can add new_element to the database, we have to determine 373 // if there is already a element with the same name. 374 std::vector<ConfigElementPtr>::iterator iter = 375 std::find_if(mElements.begin(), mElements.end(), 376 ElementNamePred(new_element->getName())); 377 378 // If no existing element has the same name as new_element, then we 379 // can just add it to the end. 380 if ( iter == mElements.end() ) 381 { 382 mElements.push_back(new_element); 383 } 384 // Otherwise, overwrite the old version. 385 else 386 { 387 *iter = new_element; 388 } 394 add(new_element); 389 395 } 390 396 } juggler/trunk/modules/jackal/config/jccl/Config/Configuration.h
r19729 r20009 96 96 bool remove(const std::string& name); 97 97 98 /** 99 * Adds the given element to our list of elements. 100 * 101 * @param new_element ConfigElement to add 102 * @note If we already have a ConfigElement with the same name, replace it. 103 */ 104 void add(ConfigElementPtr newElement); 105 98 106 /* IO functions: */ 99 107
