core: include trip table directly in divelog

Having this as a pointer is an artifact from the C/C++ split.
The triptable header is small enough so that we can
include it directly

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-08 16:53:55 +02:00 committed by bstoeger
parent 5af9d28291
commit 2bdcdab391
13 changed files with 39 additions and 39 deletions

View file

@ -727,10 +727,10 @@ struct dive *register_dive(std::unique_ptr<dive> d)
void process_loaded_dives()
{
divelog.dives.sort();
divelog.trips->sort();
divelog.trips.sort();
/* Autogroup dives if desired by user. */
autogroup_dives(divelog.dives, *divelog.trips);
autogroup_dives(divelog.dives, divelog.trips);
fulltext_populate();
@ -926,7 +926,7 @@ void add_imported_dives(struct divelog &import_log, int flags)
/* Add new trips */
for (auto &trip: trips_to_add)
divelog.trips->put(std::move(trip));
divelog.trips.put(std::move(trip));
trips_to_add.clear();
/* Add new dive sites */
@ -960,7 +960,7 @@ static bool try_to_merge_trip(dive_trip &trip_import, struct dive_table &import_
struct dive_table &dives_to_add, std::vector<dive *> &dives_to_remove,
bool &sequence_changed, int &start_renumbering_at)
{
for (auto &trip_old: *divelog.trips) {
for (auto &trip_old: divelog.trips) {
if (trips_overlap(trip_import, *trip_old)) {
sequence_changed |= merge_dive_tables(trip_import.dives, import_table, trip_old->dives,
prefer_imported, trip_old.get(),
@ -1044,7 +1044,7 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log,
/* Autogroup tripless dives if desired by user. But don't autogroup
* if tripless dives should be added to a new trip. */
if (!(flags & IMPORT_ADD_TO_NEW_TRIP))
autogroup_dives(import_log.dives, *import_log.trips);
autogroup_dives(import_log.dives, import_log.trips);
/* If dive sites already exist, use the existing versions. */
for (auto &new_ds: import_log.sites) {
@ -1072,7 +1072,7 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log,
* could be smarter here, but realistically not a whole lot of trips
* will be imported so do a simple n*m loop until someone complains.
*/
for (auto &trip_import: *import_log.trips) {
for (auto &trip_import: import_log.trips) {
if ((flags & IMPORT_MERGE_ALL_TRIPS) || trip_import->autogen) {
if (try_to_merge_trip(*trip_import, import_log.dives, flags & IMPORT_PREFER_IMPORTED,
res.dives_to_add, res.dives_to_remove,
@ -1096,7 +1096,7 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log,
/* Finally, add trip to list of trips to add */
res.trips_to_add.put(std::move(trip_import));
}
import_log.trips->clear(); /* All trips were consumed */
import_log.trips.clear(); /* All trips were consumed */
if ((flags & IMPORT_ADD_TO_NEW_TRIP) && !import_log.dives.empty()) {
/* Create a new trip for unassigned dives, if desired. */

View file

@ -11,7 +11,6 @@
struct divelog divelog;
divelog::divelog() :
trips(std::make_unique<trip_table>()),
filter_presets(std::make_unique<filter_preset_table>()),
autogroup(false)
{
@ -34,10 +33,10 @@ void divelog::delete_single_dive(int idx)
// Deleting a dive may change the order of trips!
if (trip)
trips->sort();
trips.sort();
if (trip && trip->dives.empty())
trips->pull(trip);
trips.pull(trip);
unregister_dive_from_dive_site(dive);
dives.erase(dives.begin() + idx);
}
@ -51,7 +50,7 @@ void divelog::delete_multiple_dives(const std::vector<dive *> &dives_to_delete)
struct dive_trip *trip = unregister_dive_from_trip(d);
if (trip && trip->dives.empty()) {
trips_changed = true;
trips->pull(trip);
trips.pull(trip);
}
unregister_dive_from_dive_site(d);
@ -60,14 +59,14 @@ void divelog::delete_multiple_dives(const std::vector<dive *> &dives_to_delete)
// Deleting a dive may change the order of trips!
if (trips_changed)
trips->sort();
trips.sort();
}
void divelog::clear()
{
dives.clear();
sites.clear();
trips->clear();
trips.clear();
devices.clear();
filter_presets->clear();
}

View file

@ -5,6 +5,7 @@
#include "divelist.h"
#include "divesitetable.h"
#include "triptable.h"
#include <memory>
#include <vector>
@ -15,7 +16,7 @@ struct filter_preset_table;
struct divelog {
dive_table dives;
std::unique_ptr<trip_table> trips;
trip_table trips;
dive_site_table sites;
std::vector<device> devices;
std::unique_ptr<filter_preset_table> filter_presets;

View file

@ -1384,7 +1384,7 @@ static void finish_active_trip(struct git_parser_state *state)
auto &trip = state->active_trip;
if (trip)
state->log->trips->put(std::move(trip));
state->log->trips.put(std::move(trip));
}
static void finish_active_dive(struct git_parser_state *state)

View file

@ -288,7 +288,7 @@ void trip_end(struct parser_state *state)
{
if (!state->cur_trip)
return;
state->log->trips->put(std::move(state->cur_trip));
state->log->trips.put(std::move(state->cur_trip));
}
void picture_start(struct parser_state *state)

View file

@ -985,7 +985,7 @@ static int create_git_tree(git_repository *repo, struct dir *root, bool select_o
save_divesites(repo, root);
save_filter_presets(repo, root);
for (auto &trip: *divelog.trips)
for (auto &trip: divelog.trips)
trip->saved = false;
/* save the dives */

View file

@ -436,7 +436,7 @@ static void write_trips(struct membuffer *b, const char *photos_dir, bool select
char sep_ = ' ';
char *sep = &sep_;
for (auto &trip: *divelog.trips)
for (auto &trip: divelog.trips)
trip->saved = 0;
for (auto &dive: divelog.dives) {

View file

@ -678,7 +678,7 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym
put_format(b, "</site>\n");
}
put_format(b, "</divesites>\n<dives>\n");
for (auto &trip: *divelog.trips)
for (auto &trip: divelog.trips)
trip->saved = 0;
/* save the filter presets */

View file

@ -156,7 +156,7 @@ QVector<dive *> setSelectionCore(const std::vector<dive *> &selection, dive *cur
static void clear_trip_selection()
{
amount_trips_selected = 0;
for (auto &trip: *divelog.trips)
for (auto &trip: divelog.trips)
trip->selected = false;
}
@ -202,7 +202,7 @@ void setTripSelection(dive_trip *trip, dive *currentDive)
current_dive = currentDive;
for (auto &d: divelog.dives)
d->selected = d->divetrip == trip;
for (auto &t: *divelog.trips)
for (auto &t: divelog.trips)
t->selected = t.get() == trip;
amount_selected = static_cast<int>(trip->dives.size());
@ -291,7 +291,7 @@ struct dive_trip *single_selected_trip()
{
if (amount_trips_selected != 1)
return NULL;
for (auto &trip: *divelog.trips) {
for (auto &trip: divelog.trips) {
if (trip->selected)
return trip.get();
}