* Transforms Attributes are stored in a linked_list_t
*/
linked_list_t *attributes;
+
+ /**
+ * @brief Computes the length of this substructure.
+ *
+ * @param this calling private_transform_substructure_t object
+ * @return
+ * SUCCESS in any case
+ */
+ status_t (*compute_length) (private_transform_substructure_t *this);
};
*/
static size_t get_length(private_transform_substructure_t *this)
{
- linked_list_iterator_t *iterator;
- status_t status;
- size_t length = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH;
- status = this->attributes->create_iterator(this->attributes,&iterator,TRUE);
- if (status != SUCCESS)
- return length;
- while (iterator->has_next(iterator))
- {
- payload_t * current_attribute;
- iterator->current(iterator,(void **) ¤t_attribute);
- length += current_attribute->get_length(current_attribute);
- }
-
- this->transform_length = length;
+ this->compute_length(this);
return this->transform_length;
}
static status_t add_transform_attribute (private_transform_substructure_t *this,transform_attribute_t *attribute)
{
return (this->attributes->insert_last(this->attributes,(void *) attribute));
- this->transform_length += ((payload_t *)this->attributes)->get_length(((payload_t *)this->attributes));
+ this->compute_length(this);
return SUCCESS;
}
return this->transform_id;
}
+/**
+ * Implements private_transform_substructure_t's compute_length function.
+ * See #private_transform_substructure_s.compute_length for description.
+ */
+static status_t compute_length (private_transform_substructure_t *this)
+{
+ linked_list_iterator_t *iterator;
+ status_t status;
+ size_t length = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH;
+ status = this->attributes->create_iterator(this->attributes,&iterator,TRUE);
+ if (status != SUCCESS)
+ {
+ return length;
+ }
+ while (iterator->has_next(iterator))
+ {
+ payload_t * current_attribute;
+ iterator->current(iterator,(void **) ¤t_attribute);
+ length += current_attribute->get_length(current_attribute);
+ }
+
+ return SUCCESS;
+}
+
/*
* Described in header
*/
this->public.get_transform_id = (u_int16_t (*) (transform_substructure_t *)) get_transform_id;
this->public.destroy = (status_t (*) (transform_substructure_t *)) destroy;
+ /* private functions */
+ this->compute_length = compute_length;
+
/* set default values of the fields */
this->next_payload = NO_PAYLOAD;
this->transform_length = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH;