libSBML C++ API  5.18.0
List.h File Reference

Simple, generic list utility class. More...

Include dependency graph for List.h:
This graph shows which files directly or indirectly include this file:

Classes

class  List
  Simple, plain, generic lists. More...
 

Macros

#define List_freeItems(list, free_item, type)
 Frees the items in the given List. More...
 

Typedefs

typedef int(* ListItemComparator) (const void *item1, const void *item2)
 A ListItemComparator is a typedef for a pointer to a function that compares two list items. More...
 
typedef int(* ListItemPredicate) (const void *item)
 A ListItemPredicate is a typedef for a pointer to a function that takes a List item and returns 1 (true) or 0 (false). More...
 

Detailed Description

Simple, generic list utility class.

Author
Ben Bornstein

Macro Definition Documentation

#define List_freeItems (   list,
  free_item,
  type 
)
Value:
{ \
unsigned int size = List_size(list); \
while (size--) free_item( (type *) List_remove(list, 0) ); \
}
unsigned int List_size(const List_t *lst)
Definition: List.cpp:562
void * List_remove(List_t *lst, unsigned int n)
Definition: List.cpp:548

Frees the items in the given List.

Iterates over the items in this List and frees each one in turn by calling the passed-in 'void free_item(type *)' function.

The List itself will not be freed and so may be re-used. To free the List, use the destructor.

While the function prototype cannot be expressed precisely in C syntax, it is roughly:

1 List_freeItems(List_t *lst, void (*free_item)(type *), type)

where type is a C type resolved at compile time.

Believe it or not, defining List_freeItems() as a macro is actually more type safe than can be acheived with straight C. That is, in C, the free_item() function would need to take a void pointer argument, requiring any type safe XXX_free() functions to be re-written to be less safe.

As with all line-continuation macros, compile-time errors will still report the correct line number.

Typedef Documentation

typedef int(* ListItemComparator) (const void *item1, const void *item2)

A ListItemComparator is a typedef for a pointer to a function that compares two list items.

The return value semantics are the same as for the C library function strcmp:

  • -1: item1 < item2
  • 0: item1 == item2
  • 1: item1 > item2
See also
List_find()
typedef int(* ListItemPredicate) (const void *item)

A ListItemPredicate is a typedef for a pointer to a function that takes a List item and returns 1 (true) or 0 (false).

See also
List_countIf()