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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-13 06:17:07 +02:00 committed by bstoeger
parent 90d5bab4e9
commit 6e352d5281
9 changed files with 16 additions and 22 deletions

View file

@ -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;
@ -1272,7 +1272,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();

View file

@ -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();
}

View file

@ -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

View file

@ -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;

View file

@ -116,7 +116,7 @@ Qt::ItemFlags DiveImportedModel::flags(const QModelIndex &index) const
void DiveImportedModel::clearTable()
{
beginResetModel();
clear_divelog(&log);
log.clear();
endResetModel();
}

View file

@ -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();

View file

@ -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

View file

@ -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();

View file

@ -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);