mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
code cleanup: introduce empty_cylinder constant
This deals with the issue of initializing structs in C++. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
4e419f7445
commit
cef30619d0
12 changed files with 18 additions and 16 deletions
|
@ -675,7 +675,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
|
|||
case TYPE_GEMINI:
|
||||
case TYPE_COMMANDER:
|
||||
if (config.type == TYPE_GEMINI) {
|
||||
cylinder_t cyl = { 0 };
|
||||
cylinder_t cyl = empty_cylinder;
|
||||
dc->model = "Gemini";
|
||||
dc->deviceid = buf[0x18c] * 256 + buf[0x18d]; // serial no
|
||||
fill_default_cylinder(dive, &cyl);
|
||||
|
@ -687,7 +687,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
|
|||
dc->model = "Commander";
|
||||
dc->deviceid = array_uint32_le(buf + 0x31e); // serial no
|
||||
for (g = 0; g < 2; g++) {
|
||||
cylinder_t cyl = { 0 };
|
||||
cylinder_t cyl = empty_cylinder;
|
||||
fill_default_cylinder(dive, &cyl);
|
||||
cyl.gasmix.o2.permille = (log[CMD_O2_PERCENT + g * 2] / 256
|
||||
+ log[CMD_O2_PERCENT + g * 2 + 1]) * 10;
|
||||
|
@ -731,7 +731,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
|
|||
dc->model = "EMC";
|
||||
dc->deviceid = array_uint32_le(buf + 0x31e); // serial no
|
||||
for (g = 0; g < 4; g++) {
|
||||
cylinder_t cyl = { 0 };
|
||||
cylinder_t cyl = empty_cylinder;
|
||||
fill_default_cylinder(dive, &cyl);
|
||||
cyl.gasmix.o2.permille =
|
||||
(log[EMC_O2_PERCENT + g * 2] / 256
|
||||
|
|
|
@ -317,7 +317,7 @@ static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive
|
|||
*/
|
||||
read_bytes(2);
|
||||
if (tmp_2bytes != 0x7FFF) {
|
||||
cylinder_t cyl = { 0 };
|
||||
cylinder_t cyl = empty_cylinder;
|
||||
cyl.type.size.mliter = tmp_2bytes * 10;
|
||||
cyl.type.description = "";
|
||||
cyl.start.mbar = 200000;
|
||||
|
|
|
@ -343,7 +343,7 @@ void copy_cylinder_types(const struct dive *s, struct dive *d)
|
|||
|
||||
cylinder_t *add_empty_cylinder(struct cylinder_table *t)
|
||||
{
|
||||
cylinder_t cyl = { 0 };
|
||||
cylinder_t cyl = empty_cylinder;
|
||||
cyl.type.description = strdup("");
|
||||
add_to_cylinder_table(t, t->nr, cyl);
|
||||
return &t->cylinders[t->nr - 1];
|
||||
|
|
|
@ -33,6 +33,8 @@ typedef struct
|
|||
bool bestmix_he;
|
||||
} cylinder_t;
|
||||
|
||||
static const cylinder_t empty_cylinder = { { { 0 }, { 0 }, (const char *)0}, { { 0 }, { 0 } } , { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, false, { 0 }, { 0 }, OC_GAS, false, false };
|
||||
|
||||
/* Table of cylinders. Attention: this stores cylinders,
|
||||
* *not* pointers to cylinders. This has two crucial consequences:
|
||||
* 1) Pointers to cylinders are not stable. They may be
|
||||
|
|
|
@ -114,7 +114,7 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
|
|||
|
||||
clear_cylinder_table(&dive->cylinders);
|
||||
for (i = 0; i < ngases || i < ntanks; i++) {
|
||||
cylinder_t cyl = { 0 };
|
||||
cylinder_t cyl = empty_cylinder;
|
||||
if (i < ngases) {
|
||||
dc_gasmix_t gasmix = { 0 };
|
||||
int o2, he;
|
||||
|
|
|
@ -149,7 +149,7 @@ static void parse_dives(int log_version, const unsigned char *buf, unsigned int
|
|||
|
||||
/* Just the main cylinder until we can handle the buddy cylinder porperly */
|
||||
for (i = 0; i < 1; i++) {
|
||||
cylinder_t cyl = { 0 };
|
||||
cylinder_t cyl = empty_cylinder;
|
||||
fill_default_cylinder(dive, &cyl);
|
||||
add_to_cylinder_table(&dive->cylinders, i, cyl);
|
||||
}
|
||||
|
|
|
@ -405,7 +405,7 @@ static void parse_cylinder_keyvalue(void *_cylinder, const char *key, const char
|
|||
|
||||
static void parse_dive_cylinder(char *line, struct membuffer *str, struct git_parser_state *state)
|
||||
{
|
||||
cylinder_t cylinder = { 0 };
|
||||
cylinder_t cylinder = empty_cylinder;
|
||||
|
||||
cylinder.type.description = get_utf8(str);
|
||||
for (;;) {
|
||||
|
@ -437,7 +437,7 @@ static void parse_weightsystem_keyvalue(void *_ws, const char *key, const char *
|
|||
|
||||
static void parse_dive_weightsystem(char *line, struct membuffer *str, struct git_parser_state *state)
|
||||
{
|
||||
weightsystem_t ws = { 0 };
|
||||
weightsystem_t ws = empty_weightsystem;
|
||||
|
||||
ws.description = get_utf8(str);
|
||||
for (;;) {
|
||||
|
|
|
@ -1003,7 +1003,7 @@ static void divinglog_place(char *place, struct dive *d, struct parser_state *st
|
|||
static int divinglog_dive_match(struct dive *dive, const char *name, char *buf, struct parser_state *state)
|
||||
{
|
||||
/* For cylinder related fields, we might have to create a cylinder first. */
|
||||
cylinder_t cyl = { 0 };
|
||||
cylinder_t cyl = empty_cylinder;
|
||||
if (MATCH("tanktype", utf8_string, &cyl.type.description)) {
|
||||
cylinder_t *cyl0 = get_or_create_cylinder(dive, 0);
|
||||
free((void *)cyl0->type.description);
|
||||
|
|
|
@ -1103,7 +1103,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
|
|||
if (prefs.surface_segment != 0) {
|
||||
// Switch to an empty air cylinder for breathing air at the surface
|
||||
// If no empty cylinder is found, keep using last deco gas
|
||||
cylinder_t cyl = { 0 };
|
||||
cylinder_t cyl = empty_cylinder;
|
||||
cyl.cylinder_use = NOT_USED;
|
||||
add_to_cylinder_table(&dive->cylinders, dive->cylinders.nr, cyl);
|
||||
current_cylinder = dive->cylinders.nr - 1;
|
||||
|
|
|
@ -421,7 +421,7 @@ int CylindersModel::rowCount(const QModelIndex&) const
|
|||
void CylindersModel::add()
|
||||
{
|
||||
int row = rows;
|
||||
cylinder_t cyl = { 0 };
|
||||
cylinder_t cyl = empty_cylinder;
|
||||
fill_default_cylinder(&displayed_dive, &cyl);
|
||||
cyl.start = cyl.type.workingpressure;
|
||||
cyl.manually_added = true;
|
||||
|
|
|
@ -166,12 +166,12 @@ void DivePlannerPointsModel::setupCylinders()
|
|||
}
|
||||
}
|
||||
if (!empty_string(prefs.default_cylinder)) {
|
||||
cylinder_t cyl = { 0 };
|
||||
cylinder_t cyl = empty_cylinder;
|
||||
fill_default_cylinder(&displayed_dive, &cyl);
|
||||
cyl.start = cyl.type.workingpressure;
|
||||
add_to_cylinder_table(&displayed_dive.cylinders, 0, cyl);
|
||||
} else {
|
||||
cylinder_t cyl = { 0 };
|
||||
cylinder_t cyl = empty_cylinder;
|
||||
// roughly an AL80
|
||||
cyl.type.description = copy_qstring(tr("unknown"));
|
||||
cyl.type.size.mliter = 11100;
|
||||
|
|
|
@ -515,7 +515,7 @@ void processRangesZip(Vector1 &items1, Vector2 &items2, Predicate cond, Action a
|
|||
return 1;
|
||||
},
|
||||
[&](Vector1 &v1, int from, int to) { // Action
|
||||
return action(v1, items2, from, to, actItem);
|
||||
return action(v1, items2, from, to, actItem);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -653,7 +653,7 @@ QModelIndex DiveTripModelTree::parent(const QModelIndex &index) const
|
|||
}
|
||||
|
||||
DiveTripModelTree::Item::Item(dive_trip *t, const QVector<dive *> &divesIn) : d_or_t{nullptr, t},
|
||||
dives(divesIn.toStdVector()),
|
||||
dives(std::vector<dive *>(divesIn.begin(), divesIn.end())),
|
||||
shown(std::any_of(dives.begin(), dives.end(), [](dive *d){ return !d->hidden_by_filter; }))
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue