c->min = min;
c->max = max;
+ c->user_data = NULL;
+ c->free_func = NULL;
return (c);
} /* sn_comparator_t *sn_comparator_create */
void sn_comparator_destroy (sn_comparator_t *c)
{
+ if (c->free_func != NULL)
+ c->free_func (c->user_data);
+
if (c != NULL)
free (c);
} /* void sn_comparator_destroy */
{
int min; /**< Index of the line onto which the smaller element will be put. */
int max; /**< Index of the line onto which the larger element will be put. */
+ void *user_data; /**< Pointer to user data. */
+ void (*free_func) (void *); /**< Pointer to a function used to free the user data pointer. */
};
typedef struct sn_comparator_s sn_comparator_t;
/** Returns the index of the line onto which the larger element will be put. */
#define SN_COMP_MAX(c) (c)->max
+/** Expands to the user data pointer. */
+#define SN_COMP_USER_DATA(c) (c)->user_data
+/** Expands to the free-function pointer. */
+#define SN_COMP_FREE_FUNC(c) (c)->free_func
+
/**
* Allocates, initializes and returns a new comparator object. The returned
* pointer must be freed by sn_comparator_destroy().
return (NULL);
}
- memcpy (s_copy->comparators, s->comparators,
- s->comparators_num * sizeof (sn_comparator_t));
+ for (i = 0; i < s->comparators_num; i++)
+ {
+ SN_COMP_MIN (s_copy->comparators + i) = SN_COMP_MIN (s->comparators + i);
+ SN_COMP_MAX (s_copy->comparators + i) = SN_COMP_MAX (s->comparators + i);
+ SN_COMP_USER_DATA (s_copy->comparators + i) = NULL;
+ SN_COMP_FREE_FUNC (s_copy->comparators + i) = NULL;
+ }
s_copy->comparators_num = s->comparators_num;
return (s_copy);