subsurface/core/structured_list.h
Berthold Stoeger 989d6a3f96 media: use table instead of linked list for media
For consistency with equipment, use our table macros for pictures.
Generally tables (arrays) are preferred over linked lists, because
they allow random access.

This is mostly copy & paste of the equipment code.

Sadly, our table macros are quite messy and need some revamping.
Therefore, the resulting code is likewise somewhat messy.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00

29 lines
970 B
C

// SPDX-License-Identifier: GPL-2.0
#ifndef STRUCTURED_LIST_H
#define STRUCTURED_LIST_H
/* Clear whole list; this works for taglist and dive computers */
#define STRUCTURED_LIST_FREE(_type, _start, _free) \
{ \
_type *_ptr = _start; \
while (_ptr) { \
_type *_next = _ptr->next; \
_free(_ptr); \
_ptr = _next; \
} \
}
#define STRUCTURED_LIST_COPY(_type, _first, _dest, _cpy) \
{ \
_type *_sptr = _first; \
_type **_dptr = &_dest; \
while (_sptr) { \
*_dptr = malloc(sizeof(_type)); \
_cpy(_sptr, *_dptr); \
_sptr = _sptr->next; \
_dptr = &(*_dptr)->next; \
} \
*_dptr = 0; \
}
#endif