updates existing attribute, return true if attribute been updated
| 332 | |
| 333 | // updates existing attribute, return true if attribute been updated |
| 334 | bool AttributeSet_Update |
| 335 | ( |
| 336 | AttributeSet *set, // set to update |
| 337 | Attribute_ID attr_id, // attribute identifier |
| 338 | SIValue value // new value |
| 339 | ) { |
| 340 | ASSERT(set != NULL); |
| 341 | ASSERT(attr_id != ATTRIBUTE_ID_NONE); |
| 342 | |
| 343 | AttributeSet _set = *set; |
| 344 | |
| 345 | // return if set is read-only |
| 346 | if(unlikely(ATTRIBUTE_SET_IS_READONLY(_set))) { |
| 347 | return false; |
| 348 | } |
| 349 | |
| 350 | ASSERT(_set != NULL); |
| 351 | |
| 352 | // setting an attribute value to NULL removes that attribute |
| 353 | if(unlikely(SIValue_IsNull(value))) { |
| 354 | return _AttributeSet_Remove(set, attr_id); |
| 355 | } |
| 356 | |
| 357 | SIValue *current = AttributeSet_Get(_set, attr_id); |
| 358 | ASSERT(current != ATTRIBUTE_NOTFOUND); |
| 359 | |
| 360 | // compare current value to new value, only update if current != new |
| 361 | if(unlikely(SIValue_Compare(*current, value, NULL) == 0)) { |
| 362 | return false; |
| 363 | } |
| 364 | |
| 365 | // value != current, update entity |
| 366 | SIValue_Free(*current); // free previous value |
| 367 | *current = SI_CloneValue(value); |
| 368 | |
| 369 | return true; |
| 370 | } |
| 371 | |
| 372 | // clones attribute-set without SI values |
| 373 | AttributeSet AttributeSet_ShallowClone |
no test coverage detected