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

@ -69,54 +69,52 @@ typedef int64_t timestamp_t;
typedef struct
{
int32_t seconds; // durations up to 34 yrs
int32_t seconds = 0; // durations up to 34 yrs
} duration_t;
static const duration_t zero_duration = { 0 };
typedef struct
{
int32_t seconds; // offsets up to +/- 34 yrs
int32_t seconds = 0; // offsets up to +/- 34 yrs
} offset_t;
typedef struct
{
int32_t mm;
int32_t mm = 0;
} depth_t; // depth to 2000 km
typedef struct
{
int32_t mbar; // pressure up to 2000 bar
int32_t mbar = 0; // pressure up to 2000 bar
} pressure_t;
typedef struct
{
uint16_t mbar;
uint16_t mbar = 0;
} o2pressure_t; // pressure up to 65 bar
typedef struct
{
int16_t degrees;
int16_t degrees = 0;
} bearing_t; // compass bearing
typedef struct
{
uint32_t mkelvin; // up to 4 MK (temperatures in K are always positive)
uint32_t mkelvin = 0; // up to 4 MK (temperatures in K are always positive)
} temperature_t;
typedef struct
{
uint64_t mkelvin; // up to 18446744073 MK (temperatures in K are always positive)
uint64_t mkelvin = 0; // up to 18446744073 MK (temperatures in K are always positive)
} temperature_sum_t;
typedef struct
{
int mliter;
int mliter = 0;
} volume_t;
typedef struct
{
int permille;
int permille = 0;
} fraction_t;
typedef struct
@ -126,15 +124,13 @@ typedef struct
typedef struct
{
int udeg;
int udeg = 0;
} degrees_t;
typedef struct pos {
degrees_t lat, lon;
} location_t;
static const location_t zero_location = { { 0 }, { 0 }};
extern void parse_location(const char *, location_t *);
static inline bool has_location(const location_t *loc)