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
|
|
|
|
#include "divelog.h"
|
|
|
|
#include "divelist.h"
|
|
|
|
#include "divesite.h"
|
|
|
|
#include "device.h"
|
2024-03-24 20:03:08 +00:00
|
|
|
#include "errorhelper.h"
|
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
|
|
|
#include "filterpreset.h"
|
|
|
|
#include "trip.h"
|
|
|
|
|
|
|
|
struct divelog divelog;
|
|
|
|
|
|
|
|
// We can't use smart pointers, since this is used from C
|
|
|
|
// and it would be bold to presume that std::unique_ptr<>
|
|
|
|
// and a plain pointer have the same memory layout.
|
|
|
|
divelog::divelog() :
|
|
|
|
dives(new dive_table),
|
|
|
|
trips(new trip_table),
|
|
|
|
sites(new dive_site_table),
|
|
|
|
devices(new device_table),
|
|
|
|
filter_presets(new filter_preset_table),
|
|
|
|
autogroup(false)
|
|
|
|
{
|
|
|
|
*dives = empty_dive_table;
|
|
|
|
*trips = empty_trip_table;
|
|
|
|
*sites = empty_dive_site_table;
|
|
|
|
}
|
|
|
|
|
|
|
|
divelog::~divelog()
|
|
|
|
{
|
|
|
|
clear_dive_table(dives);
|
|
|
|
clear_trip_table(trips);
|
|
|
|
clear_dive_site_table(sites);
|
|
|
|
delete dives;
|
|
|
|
delete trips;
|
|
|
|
delete sites;
|
|
|
|
delete devices;
|
|
|
|
delete filter_presets;
|
|
|
|
}
|
|
|
|
|
2022-11-12 07:40:04 +00:00
|
|
|
divelog::divelog(divelog &&log) :
|
|
|
|
dives(new dive_table),
|
|
|
|
trips(new trip_table),
|
|
|
|
sites(new dive_site_table),
|
2023-04-18 07:31:42 +00:00
|
|
|
devices(new device_table),
|
|
|
|
filter_presets(new filter_preset_table)
|
2022-11-12 07:40:04 +00:00
|
|
|
{
|
|
|
|
*dives = empty_dive_table;
|
|
|
|
*trips = empty_trip_table;
|
|
|
|
*sites = empty_dive_site_table;
|
|
|
|
move_dive_table(log.dives, dives);
|
|
|
|
move_trip_table(log.trips, trips);
|
|
|
|
move_dive_site_table(log.sites, sites);
|
2023-04-18 07:31:42 +00:00
|
|
|
*devices = std::move(*log.devices);
|
|
|
|
*filter_presets = std::move(*log.filter_presets);
|
2022-11-12 07:40:04 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 11:44:29 +00:00
|
|
|
struct divelog &divelog::operator=(divelog &&log)
|
|
|
|
{
|
|
|
|
move_dive_table(log.dives, dives);
|
|
|
|
move_trip_table(log.trips, trips);
|
|
|
|
move_dive_site_table(log.sites, sites);
|
2023-04-18 07:31:42 +00:00
|
|
|
*devices = std::move(*log.devices);
|
|
|
|
*filter_presets = std::move(*log.filter_presets);
|
2022-11-12 11:44:29 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
void divelog::clear()
|
|
|
|
{
|
|
|
|
while (dives->nr)
|
|
|
|
delete_single_dive(0);
|
|
|
|
while (sites->nr)
|
|
|
|
delete_dive_site(get_dive_site(0, sites), sites);
|
|
|
|
if (trips->nr != 0) {
|
2024-03-24 20:03:08 +00:00
|
|
|
report_info("Warning: trip table not empty in divelog::clear()!");
|
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
|
|
|
trips->nr = 0;
|
|
|
|
}
|
|
|
|
clear_device_table(devices);
|
|
|
|
filter_presets->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void clear_divelog(struct divelog *log)
|
|
|
|
{
|
|
|
|
log->clear();
|
|
|
|
}
|