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>
This commit is contained in:
Berthold Stoeger 2024-05-27 17:09:48 +02:00 committed by bstoeger
parent e237f29fb2
commit 284582d2e8
54 changed files with 738 additions and 893 deletions

View file

@ -52,19 +52,18 @@ static void save_photos(struct membuffer *b, const char *photos_dir, const struc
static void write_divecomputers(struct membuffer *b, const struct dive *dive)
{
put_string(b, "\"divecomputers\":[");
const struct divecomputer *dc;
const char *separator = "";
for_each_dc (dive, dc) {
for (auto &dc: dive->dcs) {
put_string(b, separator);
separator = ", ";
put_format(b, "{");
write_attribute(b, "model", dc->model.c_str(), ", ");
if (dc->deviceid)
put_format(b, "\"deviceid\":\"%08x\", ", dc->deviceid);
write_attribute(b, "model", dc.model.c_str(), ", ");
if (dc.deviceid)
put_format(b, "\"deviceid\":\"%08x\", ", dc.deviceid);
else
put_string(b, "\"deviceid\":\"--\", ");
if (dc->diveid)
put_format(b, "\"diveid\":\"%08x\" ", dc->diveid);
if (dc.diveid)
put_format(b, "\"diveid\":\"%08x\" ", dc.diveid);
else
put_string(b, "\"diveid\":\"--\" ");
put_format(b, "}");
@ -82,7 +81,7 @@ static void write_dive_status(struct membuffer *b, const struct dive *dive)
static void put_HTML_bookmarks(struct membuffer *b, const struct dive *dive)
{
const char *separator = "\"events\":[";
for (const auto &ev: dive->dc.events) {
for (const auto &ev: dive->dcs[0].events) {
put_string(b, separator);
separator = ", ";
put_string(b, "{\"name\":\"");
@ -172,14 +171,14 @@ static void put_cylinder_HTML(struct membuffer *b, const struct dive *dive)
static void put_HTML_samples(struct membuffer *b, const struct dive *dive)
{
put_format(b, "\"maxdepth\":%d,", dive->dc.maxdepth.mm);
put_format(b, "\"duration\":%d,", dive->dc.duration.seconds);
put_format(b, "\"maxdepth\":%d,", dive->dcs[0].maxdepth.mm);
put_format(b, "\"duration\":%d,", dive->dcs[0].duration.seconds);
if (dive->dc.samples.empty())
if (dive->dcs[0].samples.empty())
return;
const char *separator = "\"samples\":[";
for (auto &s: dive->dc.samples) {
for (auto &s: dive->dcs[0].samples) {
put_format(b, "%s[%d,%d,%d,%d]", separator, s.time.seconds, s.depth.mm, s.pressure[0].mbar, s.temperature.mkelvin);
separator = ", ";
}