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>
This commit is contained in:
Berthold Stoeger 2024-05-04 19:15:47 +02:00 committed by bstoeger
parent b82fdd1d20
commit 408b31b6ce
34 changed files with 128 additions and 148 deletions

View file

@ -2,8 +2,6 @@
#ifndef PARSE_H
#define PARSE_H
#define MAX_EVENT_NAME 128
#include "event.h"
#include "equipment.h" // for cylinder_t
#include "extradata.h"
@ -18,11 +16,6 @@
struct xml_params;
struct divelog;
typedef union {
struct event event;
char allocation[sizeof(struct event) + MAX_EVENT_NAME];
} event_allocation_t;
/*
* Dive info as it is being built up..
*/
@ -63,7 +56,7 @@ struct parser_state {
struct divecomputer *cur_dc = nullptr; /* non-owning */
struct dive *cur_dive = nullptr; /* owning */
std::unique_ptr<dive_site> cur_dive_site; /* owning */
location_t cur_location { 0 };
location_t cur_location;
struct dive_trip *cur_trip = nullptr; /* owning */
struct sample *cur_sample = nullptr; /* non-owning */
struct picture cur_picture { 0 }; /* owning */
@ -93,13 +86,11 @@ struct parser_state {
sqlite3 *sql_handle = nullptr; /* for SQL based parsers */
bool event_active = false;
event_allocation_t event_allocation;
event cur_event;
parser_state();
~parser_state();
};
#define cur_event event_allocation.event
void event_start(struct parser_state *state);
void event_end(struct parser_state *state);
struct divecomputer *get_dc(struct parser_state *state);