Commit graph

20282 commits

Author SHA1 Message Date
Berthold Stoeger
f1f082d86a core: move get_dive_dc() to struct dive
Feels natural in a C++ code base.

This removes a nullptr-check so some care has to be taken.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
731052c776 core: remove accessor get_dive_site_for_dive()
This function does nothing at all, callers may just access
dive::dive_site directly.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
718523e01d core: move get_dive_salinity() to struct dive
Feels natural in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
0aa4efb3d9 core: move divesite_has_gps_information() to struct dive_site
Seems logical in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
c812dd140b core: move get_surface_pressure() to struct dive
Feel natural in a C++ code base.

Remove the second parameter, because all callers where passing
`true` anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
6e29c00f35 core: move number_of_divecomputers to struct dive
Feels natural in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
e90251b0cf core: move dive_[has|get]_gps_location() to struct dive
Feel natural in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
286d8fe21c core: move get_max_mod() and get_max_mnd() to struct dive
Feels natural in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
d36fd79527 core: move total_weight() into struct dive
Feels natural in a C++ code base.

Change the function to return a weight_t. Sadly, use of the
units.h types is very inconsistent and many parts of the code
use int or double instead. So let's try to make this consistent.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
df1affc25b core: move clear_dive() to struct dive
Feels natural in a C++ code base.

Moreover, remove the fulltext-unregistration, as this is a
layering violation.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
79bf79ad7f core: move clone_delete_divecomputer() to struct dive_table
Since this calls force_fixup_dive() it needs access to other dives
in the dive_table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
576d3a3bc6 core: move has_dive() function into struct divelist
Seems natural in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
60c7b503cf core: move data file version functions into version.cpp/h
It is unclear why these were located in divelist.cpp/h.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
72bb38601d core: move invalidate_dive_cache() to struct dive
Seems natural in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
1b593dc56c core: move cylinder related functions to struct dive
Seems natural in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
3aab33ba4c core: move get_dive_gas() to struct dive
It is unclear why this was declared in divelist.h.

Moreover, rename it to get_maximal_gas() to better reflect
what it does.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
4d7291d4a1 core: move merge_dives() functios to struct dive_table
These functions have to access other dives in the list to
calculate CNS, etc, so let's call them from there.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
8ec1f008ab core: move split_dive*() functions to struct dive_table
These functions have to access other dives in the list to
calculate CNS, etc, so let's call them from there.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
a2903b31a7 core: move fixup_dive() to struct dive_table
This accesses the global dive_table, so make this explicit.

Since force_fixup_dive() and default_dive() use fixup_dive(),
also move them to struct dive_table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
d81ca005ab core: move *_surface_pressure() functions into struct dive
Seems natural in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
4a165980e7 undo: pass dive as unique_ptr to addDive()
Before, a non-owning pointer was passed and the dive moved
away from the dive. Instead, let the caller decide if they
still want to keep a copy of the dive, or give up ownership:

In MainWindow and QMLManager new dives are generated, so
one might just as well give up ownership. In contrast,
the planner works on a copy (originally the infamous
"displayed_dive") and now moves the data manually.

This commit also removes duplicate code, by moving the
"create default dive" code from MainWindow and QMLManager
to struct dive.

Finally, determination of the "time zone offset" is not done
in POSIX, since we want to avoid calls form the core into
Qt.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
bdd5527005 core: move *_to_depth() functions into struct dive
Seems logical in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
bf84d66df2 core: move depth_to_* functions into struct dive
Seems logical in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
3660241993 core: remove get_dive() function
This implicitly accessed the global divelog. Most of the users were
in the test/ folder anyway. Replace by explicit accesses to the
global divelog.dives.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
176f544106 core: move process_import_dives() and related functions to divelog
These functions accessed the global divelog make this explicit.

I'm still not happy about the situation, because these functions
access global state, such as the selection. I think these
should be moved up the call-chain.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
b34116e2e2 core: make calculate_cns() member of dive_table
This function implicitely accessed the global divelog. To make
that explicit make it a member of dive_table, such that the
caller must access it via the global variable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
f3b8e3c4aa core: make register_dive() member of dive_table
This one is for symmetry with unregister_dive(). However, it
makes me unhappy, because it modifies global state, namely the
selection machinery and the fulltext. I think these should be
moved up in the call chain.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
271df8962b core: make get_dive_nr_at_idx() member of dive_table
This function implicitely accessed the global divelog. To make
that explicit make it a member of dive_table, such that the
caller must access it via the global variable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
cce5f5950c core: make get_surface_interval() member of dive_table
This function implicitely accessed the global divelog. To make
that explicit make it a member of dive_table, such that the
caller must access it via the global variable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
e9a57ac5f5 core: make find_next_visible_dive() member of dive_table
This function implicitely accessed the global divelog. To make
that explicit make it a member of dive_table, such that the
caller must access it via the global variable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
4afefb1b9b parser: keep divelist sorted
The parser used to append each parsed dive at the end of the log.
At the end the list was sorted. However, the divelist code depends
on the list being sorted. To avoid inconsistent states, add the
dives at the proper position.

Note that the reference data of TestDiveSeabearNewFormat had to
be adapted, because the CNS calculation now gives a different
value. This shouls be investigated.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
124362caa5 parser: move atoi_n to import-divinglog.cpp
That was the only user of this helper function, so move it there.
Moreover, impelement it with the standard function std::from_chars
instead of copying the string.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
541abf7ae4 core: use std::unique_ptr<> to make ownership transfer more clear
The decostate was generated in the main thread and passed down to
a worker thread. To make that explicit, use an std::unique_ptr<>
and std::move().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
d594cc72f0 core: remove copy_qstring() function
No more users of that (yippie!).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
ccdd92aeb7 preferences: use std::string in struct preferences
This is a messy commit, because the "qPref" system relies
heavily on QString, which means lots of conversions between
the two worlds. Ultimately, I plan to base the preferences
system on std::string and only convert to QString when
pushing through Qt's property system or when writing into
Qt's settings.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
82fc9de40b core: remove structured_list.h
No more users of this, since we switched to C++ containers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
5805b14734 core: use std::string for hashfile_name
One more free() removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
ec92cff92c import: use std::string for location in cobalt-import
One more strdup()/free() pair removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
6c7942ac1c core: remove add_to_string() function
Last user removed in 160f06db8d.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
6252d22adf desktop: use std::string to format subtitles
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
d05e289507 core: use std::string in error_callback
No naked free().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
71f3189a31 core: remove C-versions of (v)format_string()
Only users of the std::string versions are left.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
0c7c96402c core: remove get_first_converted_string_c() in load-git.cpp
No more users of C-strings.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
7452aa22c2 download: replace progress_bar_text by std::string
No fixed buffers. Sadly, the thing is still a global variable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
91968ac579 core: remove filterconstraint C boilerplate code
Since all code can now directly access C++ structures these
accessor functions were not necessary.

Split out the table from the filterconstraint source file
and include it directly into the divelog.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
2bdcdab391 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>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
5af9d28291 core: include divesite table directly in divelog
Having this as a pointer is an artifact from the C/C++ split.
The divesitetable header is small enough so that we can
include it directly.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
7792f54a73 core: move functions into trip-structure
Not strictly necessary, but a "natural" thing to do in a classical
C++ code base.

Move the tiny trip-table into its own source file, since it also
has its own header.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
67d0f69516 core: remove table.h
No more users of this.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
b95ac3f79c 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>
2024-08-13 19:28:30 +02:00