Commit graph

14 commits

Author SHA1 Message Date
Michael Keller
8a64d1f4b9 Cleanup: Fix Warnings in MacOS build.
Signed-off-by: Michael Keller <github@ike.ch>
2024-09-28 23:50:55 +12:00
Berthold Stoeger
ae81b42fe2 core: introduce a few user-defined literals for unit types
Thise makes initialization of unit types more palatable.

For example:

    surface.time = sample.time - duration_t { .seconds = 20 };
=>  surface.time = sample.time - 20_sec;

    delta_depth.mm = feet_to_mm(1.0); // 1ft
=>  delta_depth = 1_ft;

    get_cylinderid_at_time(..., { .seconds = 20 * 60 + 1 }));
=>  get_cylinderid_at_time(..., 20_min + 1_sec));

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 10:23:07 +02:00
Berthold Stoeger
80b5f6bfcd core: move add_cylinder() to struct cylinder_table
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
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
Berthold Stoeger
28520da655 core: convert cylinder_t and cylinder_table to C++
This had to be done simultaneously, because the table macros
do not work properly with C++ objects.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
284582d2e8 core: turn divecomputer list into std::vector<>
Since struct divecomputer is now fully C++ (i.e. cleans up
after itself), we can simply turn the list of divecomputers
into an std::vector<>. This makes the code quite a bit simpler,
because the first divecomputer was actually a subobject.

Yes, this makes the common case of a single divecomputer a
little bit less efficient, but it really shouldn't matter.
If it does, we can still write a special std::vector<>-
like container that keeps the first element inline.

This change makes pointers-to-divecomputers not stable.
So always access the divecomputer via its index. As
far as I can tell, most of the code already does this.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
f120fecccb core: use std::vector<> to store divecomputer samples
This is a hairy one, because the sample code is rather tricky.

There was a pattern of looping through pairs of adjacent samples,
for interpolation purposes. Add an range adapter to generalize
such loops.

Removes the finish_sample() function: The code would call
prepare_sample() to start parsing of samples and then
finish_sample() to actuall add it. I.e. a kind of commit().

Since, with one exception, all users of prepare_sample()
called finish_sample() in all code paths, we might just add
the sample in the first place. The exception was sample_end()
in parse.cpp. This brings a small change: samples are now
added, even if they could only be parsed partially. I doubt
that this makes any difference, since it will only happen
for broken divelogs anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
cc39f709ce core: add constructor/destructor pairs to dive and divecomputer
This allows us to use non-C member variables. Convert a number
of pointers to unique_ptr<>s.

Code in uemis-downloader.cpp had to be refactored, because
it mixed owning and non-owning pointers. Mad.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
d242198c99 divelog: turn owning-pointers into unique_ptr<>s
Since everything is C++ now, we can use unique_ptr<>s. This makes
the code significantly shorter, because we can now use the default
move constructor and assignment operators.

This has a semantic change when std::move()-ing the divelog:
now not the contents of the tables are moved, but the pointers.
That is, the moved-from object now has no more tables and
must not be used anymore. This made it necessary to replace
std::move()s by std::swap()s. In that regard, the old code was
in principle broken: it used moved-from objects, which may work
but usually doesn't.

This commit adds a myriad of .get() function calls where the code
expects a C-style pointer. The plan is to remove virtually all of
them, when we move free-standing functions into the class it acts
on. Or, replace C-style pointers by references where we don't support
NULL.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
2df30a4144 core: remove ssrf.h include file
It didn't contain anything.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
408b31b6ce core: default initialize units-type objects to 0
Makes the code much nicer to read.

Default initialize cylinder_t to the empty cylinder.

This produces lots of warnings, because most structure are now
not PODs anymore and shouldn't be erased using memset().

These memset()s will be removed one-by-one and replaced by
proper constructors.

The whole ordeal made it necessary to add a constructor to
struct event. To simplify things the whole optimization of
the variable-size event names was removed. In upcoming commits
this will be replaced by std::string anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
b24f37fb4f core: replace SHA1() function by SHA1_uint32()
The SHA1() helper function was only used when calculating a
SHA1 hash and taking the first four bytes of it as uint32.

Make that explicit by renaming the function into SHA1_uint32()
and directly returning an uint32_t.

Note that the usage in cochran.cpp is sketchy: it generates
a four-byte hash out of two-byte data. Why!?

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Michael Keller
e6ff3f7537 Cleanup: Fix Problems Raised by Coverity Scan.
Opportunistically fix some problems newly raised by a recent Coverity
scan.

Not touching any of the string memory allocation issues as this is being
handled by the move towards C++ strings.

Signed-off-by: Michael Keller <mikeller@042.ch>
2024-03-14 11:42:09 +13:00
Berthold Stoeger
cf7c54bd56 core: turn a memblock in the parser to std::string
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>
2024-03-10 11:01:42 +13:00
Renamed from core/cochran.c (Browse further)