aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-06-04 20:59:08 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-06-19 13:11:10 -0700
commit3df32044ee46caf518b23cc6359f98501f7ca961 (patch)
tree860615069cf0b5f36627b0815d374c66e265dbde /core
parentf4ef1c4bc8805600e018777f18f3f29682e40c2d (diff)
downloadsubsurface-3df32044ee46caf518b23cc6359f98501f7ca961.tar.gz
Cleanup: generate clear_*_table() functions by macro
In analogy to the other table functions, generate these by a macro as well. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/divelist.c22
-rw-r--r--core/divelist.h2
-rw-r--r--core/divesite.c1
-rw-r--r--core/downloadfromdcthread.cpp2
-rw-r--r--core/table.h8
-rw-r--r--core/trip.c8
6 files changed, 15 insertions, 28 deletions
diff --git a/core/divelist.c b/core/divelist.c
index 71391d505..af253fb4e 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -782,6 +782,7 @@ static MAKE_REMOVE_FROM(dive_table, dives)
static MAKE_GET_IDX(dive_table, struct dive *, dives)
MAKE_SORT(dive_table, struct dive *, dives, comp_dives)
MAKE_REMOVE(dive_table, struct dive *, dive)
+MAKE_CLEAR_TABLE(dive_table, dives, dive)
void insert_dive(struct dive_table *table, struct dive *d)
{
@@ -1009,23 +1010,6 @@ static void merge_imported_dives(struct dive_table *table)
}
/*
- * Clear a dive_table and dive_site_table. Think about generating these with macros.
- */
-void clear_table(struct dive_table *table)
-{
- for (int i = 0; i < table->nr; i++)
- free_dive(table->dives[i]);
- table->nr = 0;
-}
-
-void clear_dive_site_table(struct dive_site_table *ds_table)
-{
- for (int i = 0; i < ds_table->nr; i++)
- free_dive_site(ds_table->dive_sites[i]);
- ds_table->nr = 0;
-}
-
-/*
* Try to merge a new dive into the dive at position idx. Return
* true on success. On success, the old dive will be added to the
* dives_to_remove table and the merged dive to the dives_to_add
@@ -1292,8 +1276,8 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
import_trip_table = &local_trip_table;
/* Make sure that output parameters don't contain garbage */
- clear_table(dives_to_add);
- clear_table(dives_to_remove);
+ clear_dive_table(dives_to_add);
+ clear_dive_table(dives_to_remove);
clear_trip_table(trips_to_add);
clear_dive_site_table(sites_to_add);
diff --git a/core/divelist.h b/core/divelist.h
index 7b57b41ac..f363cc336 100644
--- a/core/divelist.h
+++ b/core/divelist.h
@@ -58,7 +58,7 @@ void reset_min_datafile_version();
void report_datafile_version(int version);
int get_dive_id_closest_to(timestamp_t when);
void clear_dive_file_data();
-void clear_table(struct dive_table *table);
+void clear_dive_table(struct dive_table *table);
#ifdef DEBUG_TRIP
extern void dump_selection(void);
diff --git a/core/divesite.c b/core/divesite.c
index 45601537c..db5d87cdf 100644
--- a/core/divesite.c
+++ b/core/divesite.c
@@ -130,6 +130,7 @@ static MAKE_REMOVE_FROM(dive_site_table, dive_sites)
static MAKE_GET_IDX(dive_site_table, struct dive_site *, dive_sites)
MAKE_SORT(dive_site_table, struct dive_site *, dive_sites, compare_sites)
static MAKE_REMOVE(dive_site_table, struct dive_site *, dive_site)
+MAKE_CLEAR_TABLE(dive_site_table, dive_sites, dive_site)
int add_dive_site_to_table(struct dive_site *ds, struct dive_site_table *ds_table)
{
diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp
index 955431880..1112d6027 100644
--- a/core/downloadfromdcthread.cpp
+++ b/core/downloadfromdcthread.cpp
@@ -82,7 +82,7 @@ void DownloadThread::run()
#endif
qDebug() << "Starting download from " << (internalData->bluetooth_mode ? "BT" : internalData->devname);
qDebug() << "downloading" << (internalData->force_download ? "all" : "only new") << "dives";
- clear_table(&downloadTable);
+ clear_dive_table(&downloadTable);
clear_dive_site_table(&diveSiteTable);
Q_ASSERT(internalData->download_table != nullptr);
diff --git a/core/table.h b/core/table.h
index 1abfa6be3..da0bc96a5 100644
--- a/core/table.h
+++ b/core/table.h
@@ -91,4 +91,12 @@
return idx; \
}
+#define MAKE_CLEAR_TABLE(table_type, array_name, item_name) \
+ void clear_##table_type(struct table_type *table) \
+ { \
+ for (int i = 0; i < table->nr; i++) \
+ free_##item_name(table->array_name[i]); \
+ table->nr = 0; \
+ }
+
#endif
diff --git a/core/trip.c b/core/trip.c
index a864e8dfb..446f153eb 100644
--- a/core/trip.c
+++ b/core/trip.c
@@ -49,6 +49,7 @@ static MAKE_ADD_TO(trip_table, struct dive_trip *, trips)
static MAKE_REMOVE_FROM(trip_table, trips)
MAKE_SORT(trip_table, struct dive_trip *, trips, comp_trips)
MAKE_REMOVE(trip_table, struct dive_trip *, trip)
+MAKE_CLEAR_TABLE(trip_table, trips, trip)
timestamp_t trip_date(const struct dive_trip *trip)
{
@@ -294,13 +295,6 @@ dive_trip_t *combine_trips(struct dive_trip *trip_a, struct dive_trip *trip_b)
return trip;
}
-void clear_trip_table(struct trip_table *table)
-{
- for (int i = 0; i < table->nr; i++)
- free_trip(table->trips[i]);
- table->nr = 0;
-}
-
/* Trips are compared according to the first dive in the trip. */
int comp_trips(const struct dive_trip *a, const struct dive_trip *b)
{