From ec48e05dc6c3130f12d2edfd62018a80287bb323 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 13 May 2024 06:17:07 +0200 Subject: [PATCH] core: move freestanding functions into divelog class There were only two of them, from the time C-code had to access the divelog: clear_divelog() and delete_single_dive(). Signed-off-by: Berthold Stoeger --- core/divelist.cpp | 4 ++-- core/divelog.cpp | 17 ++++++----------- core/divelog.h | 5 ++--- core/downloadfromdcthread.cpp | 2 +- qt-models/diveimportedmodel.cpp | 2 +- subsurface-desktop-main.cpp | 2 +- subsurface-downloader-main.cpp | 2 +- subsurface-mobile-main.cpp | 2 +- tests/testgitstorage.cpp | 2 +- 9 files changed, 16 insertions(+), 22 deletions(-) diff --git a/core/divelist.cpp b/core/divelist.cpp index 002d34b68..3f48d33b7 100644 --- a/core/divelist.cpp +++ b/core/divelist.cpp @@ -976,7 +976,7 @@ void add_imported_dives(struct divelog *import_log, int flags) /* Remove old dives */ for (i = 0; i < dives_to_remove.nr; i++) { idx = get_divenr(dives_to_remove.dives[i]); - delete_single_dive(&divelog, idx); + divelog.delete_single_dive(idx); } dives_to_remove.nr = 0; @@ -1298,7 +1298,7 @@ void clear_dive_file_data() select_single_dive(NULL); // This is propagated up to the UI and clears all the information. current_dive = NULL; - clear_divelog(&divelog); + divelog.clear(); clear_event_types(); diff --git a/core/divelog.cpp b/core/divelog.cpp index 63be52081..2cc2a06f1 100644 --- a/core/divelog.cpp +++ b/core/divelog.cpp @@ -62,22 +62,22 @@ struct divelog &divelog::operator=(divelog &&log) /* this implements the mechanics of removing the dive from the * dive log and the trip, but doesn't deal with updating dive trips, etc */ -void delete_single_dive(struct divelog *log, int idx) +void divelog::delete_single_dive(int idx) { - if (idx < 0 || idx > log->dives->nr) { + if (idx < 0 || idx > dives->nr) { report_info("Warning: deleting unexisting dive with index %d", idx); return; } - struct dive *dive = log->dives->dives[idx]; - remove_dive_from_trip(dive, log->trips); + struct dive *dive = dives->dives[idx]; + remove_dive_from_trip(dive, trips); unregister_dive_from_dive_site(dive); - delete_dive_from_table(log->dives, idx); + delete_dive_from_table(dives, idx); } void divelog::clear() { while (dives->nr > 0) - delete_single_dive(this, dives->nr - 1); + delete_single_dive(dives->nr - 1); sites->clear(); if (trips->nr != 0) { report_info("Warning: trip table not empty in divelog::clear()!"); @@ -86,8 +86,3 @@ void divelog::clear() clear_device_table(devices); filter_presets->clear(); } - -void clear_divelog(struct divelog *log) -{ - log->clear(); -} diff --git a/core/divelog.h b/core/divelog.h index d153a863b..04f292f74 100644 --- a/core/divelog.h +++ b/core/divelog.h @@ -18,16 +18,15 @@ struct divelog { struct device_table *devices; struct filter_preset_table *filter_presets; bool autogroup; - void clear(); divelog(); ~divelog(); divelog(divelog &&log); // move constructor (argument is consumed). divelog &operator=(divelog &&log); // move assignment (argument is consumed). + void delete_single_dive(int idx); + void clear(); }; extern struct divelog divelog; -void clear_divelog(struct divelog *); -extern void delete_single_dive(struct divelog *, int idx); #endif diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp index 3e6929e15..79a95ccb7 100644 --- a/core/downloadfromdcthread.cpp +++ b/core/downloadfromdcthread.cpp @@ -97,7 +97,7 @@ void DownloadThread::run() report_info("Starting download from %s", qPrintable(getTransportString(transports))); report_info("downloading %s dives", internalData->force_download ? "all" : "only new"); - clear_divelog(&log); + log.clear(); Q_ASSERT(internalData->log != nullptr); std::string errorText; diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp index d869e925d..27c2335dc 100644 --- a/qt-models/diveimportedmodel.cpp +++ b/qt-models/diveimportedmodel.cpp @@ -116,7 +116,7 @@ Qt::ItemFlags DiveImportedModel::flags(const QModelIndex &index) const void DiveImportedModel::clearTable() { beginResetModel(); - clear_divelog(&log); + log.clear(); endResetModel(); } diff --git a/subsurface-desktop-main.cpp b/subsurface-desktop-main.cpp index 924667c41..9750a5588 100644 --- a/subsurface-desktop-main.cpp +++ b/subsurface-desktop-main.cpp @@ -106,7 +106,7 @@ int main(int argc, char **argv) if (!quit) run_ui(); exit_ui(); - clear_divelog(&divelog); + divelog.clear(); parse_xml_exit(); subsurface_console_exit(); diff --git a/subsurface-downloader-main.cpp b/subsurface-downloader-main.cpp index d655c3c59..f526e8631 100644 --- a/subsurface-downloader-main.cpp +++ b/subsurface-downloader-main.cpp @@ -109,7 +109,7 @@ int main(int argc, char **argv) printf("No log files given, not saving dive data.\n"); printf("Give a log file name as argument, or configure a cloud URL.\n"); } - clear_divelog(&divelog); + divelog.clear(); parse_xml_exit(); // Sync struct preferences to disk diff --git a/subsurface-mobile-main.cpp b/subsurface-mobile-main.cpp index 975186478..da2b87bf2 100644 --- a/subsurface-mobile-main.cpp +++ b/subsurface-mobile-main.cpp @@ -92,7 +92,7 @@ int main(int argc, char **argv) if (!quit) run_mobile_ui(initial_font_size); exit_ui(); - clear_divelog(&divelog); + divelog.clear(); parse_xml_exit(); subsurface_console_exit(); diff --git a/tests/testgitstorage.cpp b/tests/testgitstorage.cpp index 7b1aafdfb..5a03015ce 100644 --- a/tests/testgitstorage.cpp +++ b/tests/testgitstorage.cpp @@ -363,7 +363,7 @@ void TestGitStorage::testGitStorageCloudMerge2() QCOMPARE(parse_file(cloudTestRepo.c_str(), &divelog), 0); process_loaded_dives(); struct dive *dive = get_dive(1); - delete_single_dive(&divelog, 1); + divelog.delete_single_dive(1); QCOMPARE(save_dives("./SampleDivesMinus1.ssrf"), 0); git_local_only = true; QCOMPARE(save_dives(localCacheRepo.c_str()), 0);