core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2024-06-08 16:54:23 +00:00
|
|
|
// A structure that contains all the data we store in divelog files
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
#ifndef DIVELOG_H
|
|
|
|
#define DIVELOG_H
|
|
|
|
|
2024-06-07 08:25:09 +00:00
|
|
|
#include "divelist.h"
|
2024-06-08 14:30:24 +00:00
|
|
|
#include "divesitetable.h"
|
2024-06-08 16:54:23 +00:00
|
|
|
#include "filterpresettable.h"
|
2024-06-08 14:53:55 +00:00
|
|
|
#include "triptable.h"
|
2024-06-07 08:25:09 +00:00
|
|
|
|
2024-05-31 05:08:54 +00:00
|
|
|
#include <vector>
|
2024-05-13 17:34:43 +00:00
|
|
|
|
2024-05-31 05:08:54 +00:00
|
|
|
struct device;
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
|
2024-06-19 20:45:25 +00:00
|
|
|
/* flags for process_imported_dives() */
|
|
|
|
struct import_flags {
|
|
|
|
static constexpr int prefer_imported = 1 << 0;
|
|
|
|
static constexpr int is_downloaded = 1 << 1;
|
|
|
|
static constexpr int merge_all_trips = 1 << 2;
|
|
|
|
static constexpr int add_to_new_trip = 1 << 3;
|
|
|
|
};
|
|
|
|
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
struct divelog {
|
2024-06-07 08:25:09 +00:00
|
|
|
dive_table dives;
|
2024-06-08 14:53:55 +00:00
|
|
|
trip_table trips;
|
2024-06-08 14:30:24 +00:00
|
|
|
dive_site_table sites;
|
2024-05-31 05:08:54 +00:00
|
|
|
std::vector<device> devices;
|
2024-06-08 16:54:23 +00:00
|
|
|
filter_preset_table filter_presets;
|
|
|
|
bool autogroup = false;
|
2024-05-13 17:34:43 +00:00
|
|
|
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
divelog();
|
|
|
|
~divelog();
|
2024-05-13 17:34:43 +00:00
|
|
|
divelog(divelog &&); // move constructor (argument is consumed).
|
|
|
|
divelog &operator=(divelog &&); // move assignment (argument is consumed).
|
|
|
|
|
2024-05-13 04:17:07 +00:00
|
|
|
void delete_single_dive(int idx);
|
2024-06-07 08:25:09 +00:00
|
|
|
void delete_multiple_dives(const std::vector<dive *> &dives);
|
2024-05-13 04:17:07 +00:00
|
|
|
void clear();
|
2024-06-07 08:25:09 +00:00
|
|
|
bool is_trip_before_after(const struct dive *dive, bool before) const;
|
2024-06-19 20:45:25 +00:00
|
|
|
|
|
|
|
struct process_imported_dives_result {
|
|
|
|
dive_table dives_to_add;
|
|
|
|
std::vector<dive *> dives_to_remove;
|
|
|
|
trip_table trips_to_add;
|
|
|
|
dive_site_table sites_to_add;
|
|
|
|
std::vector<device> devices_to_add;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* divelist core logic functions */
|
|
|
|
process_imported_dives_result process_imported_dives(struct divelog &import_log, int flags); // import_log will be consumed
|
|
|
|
void process_loaded_dives();
|
|
|
|
void add_imported_dives(struct divelog &log, int flags); // log will be consumed
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct divelog divelog;
|
|
|
|
|
|
|
|
#endif
|