diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-04-11 17:41:56 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-05-06 13:58:09 -0700 |
commit | 989d6a3f96b818e5eacc5a2ccb1cc82e6dd8354c (patch) | |
tree | 006daeb578ac4d3e68044ecfc36e7e12b1604ee8 /core/picture.h | |
parent | 282041e228d4a60ff7108fbfd1fc23caffd59ba4 (diff) | |
download | subsurface-989d6a3f96b818e5eacc5a2ccb1cc82e6dd8354c.tar.gz |
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>
Diffstat (limited to 'core/picture.h')
-rw-r--r-- | core/picture.h | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/core/picture.h b/core/picture.h index 6dd6650dd..da1a42acd 100644 --- a/core/picture.h +++ b/core/picture.h @@ -4,6 +4,7 @@ // picture (more precisely media) related strutures and functions #include "units.h" +#include <stddef.h> // For NULL #ifdef __cplusplus extern "C" { @@ -13,11 +14,26 @@ struct picture { char *filename; offset_t offset; location_t location; - struct picture *next; }; +static const struct picture empty_picture = { NULL, { 0 }, { { 0 }, { 0 } } }; -extern struct picture *alloc_picture(); -extern void free_picture(struct picture *picture); +/* Table of pictures. Attention: this stores pictures, + * *not* pointers to pictures. This has two crucial consequences: + * 1) Pointers to pictures are not stable. They may be + * invalidated if the table is reallocated. + * 2) add_to_picture_table(), etc. take ownership of the + * picture. Notably of the filename. */ +struct picture_table { + int nr, allocated; + struct picture *pictures; +}; + +/* picture table functions */ +extern void clear_picture_table(struct picture_table *); +extern void add_to_picture_table(struct picture_table *, int idx, struct picture pic); +extern void copy_pictures(const struct picture_table *s, struct picture_table *d); +extern void add_picture(struct picture_table *, struct picture newpic); +extern bool remove_picture(struct picture_table *, const char *filename); #ifdef __cplusplus } |