add, remove or update an attribute this function allows NULL value to be added to the set returns the type of change performed
| 249 | // this function allows NULL value to be added to the set |
| 250 | // returns the type of change performed |
| 251 | AttributeSetChangeType AttributeSet_Set_Allow_Null |
| 252 | ( |
| 253 | AttributeSet *set, // set to update |
| 254 | Attribute_ID attr_id, // attribute identifier |
| 255 | SIValue value // attribute value |
| 256 | ) { |
| 257 | ASSERT(set != NULL); |
| 258 | ASSERT(attr_id != ATTRIBUTE_ID_NONE); |
| 259 | |
| 260 | AttributeSet _set = *set; |
| 261 | |
| 262 | // return if set is read-only |
| 263 | if(unlikely(ATTRIBUTE_SET_IS_READONLY(_set))) { |
| 264 | return CT_NONE; |
| 265 | } |
| 266 | |
| 267 | // validate value type |
| 268 | ASSERT(SI_TYPE(value) & (SI_VALID_PROPERTY_VALUE | T_NULL)); |
| 269 | |
| 270 | // update the attribute if it is already presented in the set |
| 271 | if(AttributeSet_Get(_set, attr_id) != ATTRIBUTE_NOTFOUND) { |
| 272 | if(AttributeSet_Update(&_set, attr_id, value)) { |
| 273 | // update pointer |
| 274 | *set = _set; |
| 275 | // if value is NULL, indicate attribute removal |
| 276 | // otherwise indicate attribute update |
| 277 | return SIValue_IsNull(value) ? CT_DEL : CT_UPDATE; |
| 278 | } |
| 279 | |
| 280 | // value did not change, indicate no modification |
| 281 | return CT_NONE; |
| 282 | } |
| 283 | |
| 284 | // can't remove a none existing attribute, indicate no modification |
| 285 | if(SIValue_IsNull(value)) return CT_NONE; |
| 286 | |
| 287 | // allocate room for new attribute |
| 288 | _set = AttributeSet_AddPrepare(set, 1); |
| 289 | |
| 290 | // set attribute |
| 291 | Attribute *attr = _set->attributes + _set->attr_count - 1; |
| 292 | attr->id = attr_id; |
| 293 | attr->value = SI_CloneValue(value); |
| 294 | |
| 295 | // update pointer |
| 296 | *set = _set; |
| 297 | |
| 298 | // new attribute added, indicate attribute addition |
| 299 | return CT_ADD; |
| 300 | } |
| 301 | |
| 302 | // updates existing attribute, return true if attribute been updated |
| 303 | bool AttributeSet_UpdateNoClone |
no test coverage detected