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;
|
|
|
|
|
|
|
|
divelog::divelog() :
|
2024-05-13 17:34:43 +00:00
|
|
|
dives(std::make_unique<dive_table>()),
|
|
|
|
trips(std::make_unique<trip_table>()),
|
|
|
|
sites(std::make_unique<dive_site_table>()),
|
|
|
|
filter_presets(std::make_unique<filter_preset_table>()),
|
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
|
|
|
autogroup(false)
|
|
|
|
{
|
|
|
|
*dives = empty_dive_table;
|
|
|
|
}
|
|
|
|
|
|
|
|
divelog::~divelog()
|
|
|
|
{
|
2024-05-13 17:34:43 +00:00
|
|
|
if (dives)
|
|
|
|
clear_dive_table(dives.get());
|
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-05-13 17:34:43 +00:00
|
|
|
divelog::divelog(divelog &&) = default;
|
|
|
|
struct divelog &divelog::operator=(divelog &&) = default;
|
2022-11-12 11:44:29 +00:00
|
|
|
|
2024-05-12 10:46:57 +00:00
|
|
|
/* this implements the mechanics of removing the dive from the
|
|
|
|
* dive log and the trip, but doesn't deal with updating dive trips, etc */
|
2024-05-13 04:17:07 +00:00
|
|
|
void divelog::delete_single_dive(int idx)
|
2024-05-12 10:46:57 +00:00
|
|
|
{
|
2024-05-13 04:17:07 +00:00
|
|
|
if (idx < 0 || idx > dives->nr) {
|
2024-05-12 10:46:57 +00:00
|
|
|
report_info("Warning: deleting unexisting dive with index %d", idx);
|
|
|
|
return;
|
|
|
|
}
|
2024-05-13 04:17:07 +00:00
|
|
|
struct dive *dive = dives->dives[idx];
|
2024-06-01 20:05:57 +00:00
|
|
|
struct dive_trip *trip = unregister_dive_from_trip(dive);
|
|
|
|
|
|
|
|
// Deleting a dive may change the order of trips!
|
|
|
|
if (trip)
|
|
|
|
trips->sort();
|
|
|
|
|
|
|
|
if (trip && trip->dives.nr == 0)
|
|
|
|
trips->pull(trip);
|
2024-05-12 10:46:57 +00:00
|
|
|
unregister_dive_from_dive_site(dive);
|
2024-05-13 17:34:43 +00:00
|
|
|
delete_dive_from_table(dives.get(), idx);
|
2024-05-12 10:46:57 +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
|
|
|
void divelog::clear()
|
|
|
|
{
|
2024-05-12 10:46:57 +00:00
|
|
|
while (dives->nr > 0)
|
2024-06-01 20:05:57 +00:00
|
|
|
delete_dive_from_table(dives.get(), dives->nr - 1);
|
2024-05-11 09:47:45 +00:00
|
|
|
sites->clear();
|
2024-06-01 20:05:57 +00:00
|
|
|
trips->clear();
|
2024-05-31 05:08:54 +00:00
|
|
|
devices.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
|
|
|
filter_presets->clear();
|
|
|
|
}
|