summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-03-10 20:28:50 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 18:19:07 +0300
commitefb770c979a5367a6f9616cc15ed5575eb7cd51f (patch)
treedaa724a675a588d0f284d5b84aa2ca5b7e4c06af /core
parentdc9427d16ad5cf9c3129295b49b601cbfbe5f078 (diff)
downloadsubsurface-efb770c979a5367a6f9616cc15ed5575eb7cd51f.tar.gz
Cleanup: autogenerate remove_dive() and remove_trip()
The other dive- and trip-table functions were already autogenerated. Let's do the same for these two. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/dive.h2
-rw-r--r--core/divelist.c26
2 files changed, 11 insertions, 17 deletions
diff --git a/core/dive.h b/core/dive.h
index 169b02e57..2a66130b1 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -407,7 +407,7 @@ struct dive *unregister_dive(int idx);
extern void delete_single_dive(int idx);
extern void insert_trip(dive_trip_t *trip, struct trip_table *trip_table_arg);
-extern void remove_trip(dive_trip_t *trip, struct trip_table *trip_table_arg);
+extern void remove_trip(const dive_trip_t *trip, struct trip_table *trip_table_arg);
extern void free_trip(dive_trip_t *trip);
extern timestamp_t trip_date(const struct dive_trip *trip);
diff --git a/core/divelist.c b/core/divelist.c
index 9f99f0a8e..37433536a 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -915,12 +915,16 @@ static MAKE_GET_IDX(trip_table, struct dive_trip *, trips)
MAKE_SORT(dive_table, struct dive *, dives, comp_dives)
MAKE_SORT(trip_table, struct dive_trip *, trips, comp_trips)
-void remove_dive(const struct dive *dive, struct dive_table *table)
-{
- int idx = get_idx_in_dive_table(table, dive);
- if (idx >= 0)
- remove_from_dive_table(table, idx);
-}
+#define MAKE_REMOVE(table_type, item_type, item_name) \
+ void remove_##item_name(const item_type item, struct table_type *table) \
+ { \
+ int idx = get_idx_in_##table_type(table, item); \
+ if (idx >= 0) \
+ remove_from_##table_type(table, idx); \
+ }
+
+MAKE_REMOVE(dive_table, struct dive *, dive)
+MAKE_REMOVE(trip_table, struct dive_trip *, trip)
/* remove a dive from the trip it's associated to, but don't delete the
* trip if this was the last dive in the trip. the caller is responsible
@@ -1001,16 +1005,6 @@ dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive, struct trip_tab
return dive_trip;
}
-/* remove trip from the trip-list, but don't free its memory.
- * caller takes ownership of the trip. */
-void remove_trip(dive_trip_t *trip, struct trip_table *trip_table_arg)
-{
- int idx = get_idx_in_trip_table(trip_table_arg, trip);
- assert(!trip->dives.nr);
- if (idx >= 0)
- remove_from_trip_table(trip_table_arg, idx);
-}
-
/*
* Find a trip a new dive should be autogrouped with. If no such trips
* exist, allocate a new trip. The bool "*allocated" is set to true