Use more C++ style memory management for plot_info: Use std::vector
for array data. Return the plot_info instead of filling an output
parameter. Add a constructor/destructor pair so that the caller
isn't bothered with memory management.
The bulk of the commit is replacement of pointers with references,
which is kind of gratuitous. But I started and then went on...
Default initializiation of gas_pressures made it necessary to convert
gas.c to c++, though with minimal changes to the code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Convert both files simultanously, because the SI_UNITS define works
either under C or under C++.
This was painful, because initialization of struct-members has to
be done in order of definition in C++. And it was completely out
of order. However, as long as not all is C++, we can't use
default initialization directly in the struct definition. :(
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The old code was wild: For the yearly statistics it would allocate
one entry per dive in the log. Of course, it would also leak
C-style strings.
Convert the whole thing to somewhat idiomatic C++.
Somewhat wasted work, because I'd like to convert the whole thing
to the new statistics code. But let's finish the conversion to C++
first.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The uemis code is wild. It simply doesn't deallocate memory
and uses global variables. To get this under control, create
a "struct uemis" and make the functions exported by "uemis.h"
members of "struct uemis". Thus, we don't have to carry around
a parameter for the state of the importing process.
Turn a linked list of "helper" structures (one per imported dive)
into a std::unordered_map, to fix leaking of the helper structures.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Allows us to remove the strndup.h header. This code will be
even more simple, once core is fully converted away from C-strings.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Use the C++-version of membuffer.
This fixes two memory leaks: report_info() on every(!) invocation
and report_error() before the error callback is set.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This avoid memory-management troubles. Had to convert a few
of the parsers (cochran, datatrak, liquivision) to C++.
Also had to convert libdivecomputer.c. This was less
painful than expected.
std::string is used because parts of the code assumes
that the data is null terminated after the last character
of the data. std::string does precisely that.
One disadvantage is that std::string clears its memory
when resizing / initializing. Thus we read the file onto
freshly cleared data, which some might thing is a
performance regression. Until someone shows me that this
matters, I don't care.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Return an std::string to avoid memory management headaches.
While doing that, convert time.c to C++ so that
format_datetime directly returns an std::string.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was very annoying, because the old code was not const-clean
at all and trampled all over buffers. This makes the new code
pretty messy for now.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This includes using the C++ version of membuffer. There appears
to not have been a leak, because the buffer is freed in
flush_buffer(), but usage was somewhat inconsistent and hard to
follow.
Also, convert some string handling to std::string to avoid free()
madness.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This changes default behavior when creating a sample struct
in C++ code: it is now initialized to default values. If this
ever turns out to be a performance problem, we can either add
additional constructors or use special functions that do
not initialize memory, such as make_unique_for_overwrite.
This removes non-standard (respectively >C++20) constructs,
namely designated initializers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Long term project: convert core to C++ so that we can
use higer-level constructs, notably std::vector<>.
This does not change any code - only fixes compile issues.
Mostly casting of (void *) to the proper type. Also designated
initialization of the sample struct had to be rearranged.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This structure is used to hide events of a certain type.
The type was inferred from its name, but now includes flags.
So event_type is more appropriate.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The current XCode and Qt 5.15.2 (the newest version that we can use due to Kirigami
and the lack of binaries for the later open source releases of Qt 5.15) have some
issues. Work around those.
Also, don't create fat armv7/arm64 binaries anymore for iOS - there are no supported
armv7 devices anymore.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The undo-code uses owning pointers based on std::unique_ptr to
manage lifetime of C-objects. Since these are generally useful,
move them from the undo-code to the core-code. In fact, this
eliminates one instance of code duplication.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
The eventname handling code was splattered all over the place.
Collect it in a single source file and use C++ idioms to avoid
nasty memory management. Provide a C-only interface, however.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The moveInVector() function was defined in qthelper.h, even
though it has nothing to do with Qt. Therefore, move it into
its own header.
Morover, since it is a very low-level function, use snake_case.
And rename it to move_in_range(), because it does not only
work on vectors, but any range with random-access iterators.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We have a prevailing problem with global QObjects defined as
static global variables. These get destructed after main()
exits, which means that the QApplication object does not
exist anymore. This more often than not leads to crashes.
In a quick search I didn't find a mechanism to register
objects for deletion with QApplication. Therefore, let's
do our own list of global objects that get destructed
before destroying the QApplication.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The only things in display.h were profile related, so the
split between these two files is not comprehensible.
In fact profile.h includes display.h, because it needs the
struct defined therein. Let's just merge these two files.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This way they are available in both mobile and desktop version.
Without this, the icons weren't shown on iOS and Android.
Fixes#3214
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>