core: turn C dive-table into an owning table

This is a humongous commit, because it touches all parts of the
code. It removes the last user of our horrible TABLE macros, which
simulate std::vector<> in a very clumsy way.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-07 10:25:09 +02:00 committed by bstoeger
parent f00c30ad4a
commit b95ac3f79c
73 changed files with 1030 additions and 1230 deletions

View file

@ -3,9 +3,8 @@
#define TRIP_H
#include "divelist.h"
#include "owning_table.h"
#include <string>
struct divelog;
struct dive_trip
{
@ -26,10 +25,6 @@ struct dive_trip
int comp_trips(const dive_trip &t1, const dive_trip &t2);
struct trip_table : public sorted_owning_table<dive_trip, &comp_trips> {
dive_trip *get_by_uniq_id(int tripId) const;
};
extern void add_dive_to_trip(struct dive *, dive_trip *);
extern struct dive_trip *unregister_dive_from_trip(struct dive *dive);
@ -40,18 +35,17 @@ extern dive_trip *create_and_hookup_trip_from_dive(const struct dive *dive, stru
// Result item of get_dives_to_autogroup()
struct dives_to_autogroup_result {
int from, to; // Group dives in the range [from, to)
size_t from, to; // Group dives in the range [from, to)
dive_trip *trip; // Pointer to trip
std::unique_ptr<dive_trip> created_trip;
// Is set if the trip was newly created - caller has to store it.
};
extern std::vector<dives_to_autogroup_result> get_dives_to_autogroup(struct dive_table *table);
extern std::pair<dive_trip *, std::unique_ptr<dive_trip>> get_trip_for_new_dive(const struct dive *new_dive);
extern std::vector<dives_to_autogroup_result> get_dives_to_autogroup(const struct dive_table &table);
extern std::pair<dive_trip *, std::unique_ptr<dive_trip>> get_trip_for_new_dive(const struct divelog &log, const struct dive *new_dive);
extern bool trips_overlap(const struct dive_trip &t1, const struct dive_trip &t2);
extern std::unique_ptr<dive_trip> combine_trips(struct dive_trip *trip_a, struct dive_trip *trip_b);
extern bool is_trip_before_after(const struct dive *dive, bool before);
extern bool trip_is_single_day(const struct dive_trip &trip);
extern int trip_shown_dives(const struct dive_trip *trip);
@ -59,10 +53,9 @@ extern int trip_shown_dives(const struct dive_trip *trip);
extern void dump_trip_list();
#endif
/* Make pointers to dive_trip and trip_table "Qt metatypes" so that they can be
/* Make pointers to dive_trip "Qt metatypes" so that they can be
* passed through QVariants and through QML. See comment in dive.h. */
#include <QObject>
Q_DECLARE_METATYPE(struct dive_trip *);
Q_DECLARE_METATYPE(trip_table *);
#endif