mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Core: dynamically resize weight table
Replace the fixed-size weightsystem table by a dynamically relocated table. Reuse the table-macros used in other parts of the code. The table stores weightsystem entries, not pointers to weightsystems. Thus, ownership of the description string is taken when adding a weightsystem. An extra function adds a cloned weightsystem at the end of the table. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
efdb3503ea
commit
a5e7f4253a
25 changed files with 182 additions and 154 deletions
61
core/dive.c
61
core/dive.c
|
|
@ -355,8 +355,8 @@ static void free_dive_structures(struct dive *d)
|
|||
STRUCTURED_LIST_FREE(struct picture, d->picture_list, free_picture);
|
||||
for (int i = 0; i < MAX_CYLINDERS; i++)
|
||||
free((void *)d->cylinder[i].type.description);
|
||||
for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++)
|
||||
free((void *)d->weightsystem[i].description);
|
||||
clear_weightsystem_table(&d->weightsystems);
|
||||
free(d->weightsystems.weightsystems);
|
||||
}
|
||||
|
||||
void free_dive(struct dive *d)
|
||||
|
|
@ -387,6 +387,7 @@ static void copy_dive_nodc(const struct dive *s, struct dive *d)
|
|||
* relevant components that are referenced through pointers,
|
||||
* so all the strings and the structured lists */
|
||||
*d = *s;
|
||||
memset(&d->weightsystems, 0, sizeof(d->weightsystems));
|
||||
invalidate_dive_cache(d);
|
||||
d->buddy = copy_string(s->buddy);
|
||||
d->divemaster = copy_string(s->divemaster);
|
||||
|
|
@ -394,8 +395,7 @@ static void copy_dive_nodc(const struct dive *s, struct dive *d)
|
|||
d->suit = copy_string(s->suit);
|
||||
for (int i = 0; i < MAX_CYLINDERS; i++)
|
||||
d->cylinder[i].type.description = copy_string(s->cylinder[i].type.description);
|
||||
for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++)
|
||||
d->weightsystem[i].description = copy_string(s->weightsystem[i].description);
|
||||
copy_weights(&s->weightsystems, &d->weightsystems);
|
||||
STRUCTURED_LIST_COPY(struct picture, s->picture_list, d->picture_list, copy_pl);
|
||||
d->tag_list = taglist_copy(s->tag_list);
|
||||
}
|
||||
|
|
@ -432,15 +432,6 @@ struct dive *move_dive(struct dive *s)
|
|||
if (what._component) \
|
||||
d->_component = copy_string(s->_component)
|
||||
|
||||
void copy_weights(const struct dive *s, struct dive *d)
|
||||
{
|
||||
for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
|
||||
free((void *)d->weightsystem[i].description);
|
||||
d->weightsystem[i] = s->weightsystem[i];
|
||||
d->weightsystem[i].description = copy_string(s->weightsystem[i].description);
|
||||
}
|
||||
}
|
||||
|
||||
// copy elements, depending on bits in what that are set
|
||||
void selective_copy_dive(const struct dive *s, struct dive *d, struct dive_components what, bool clear)
|
||||
{
|
||||
|
|
@ -463,7 +454,7 @@ void selective_copy_dive(const struct dive *s, struct dive *d, struct dive_compo
|
|||
if (what.cylinders)
|
||||
copy_cylinders(s, d, false);
|
||||
if (what.weights)
|
||||
copy_weights(s, d);
|
||||
copy_weights(&s->weightsystems, &d->weightsystems);
|
||||
}
|
||||
#undef CONDITIONAL_COPY_STRING
|
||||
|
||||
|
|
@ -515,14 +506,7 @@ int nr_cylinders(const struct dive *dive)
|
|||
|
||||
int nr_weightsystems(const struct dive *dive)
|
||||
{
|
||||
int nr;
|
||||
|
||||
for (nr = MAX_WEIGHTSYSTEMS; nr; --nr) {
|
||||
const weightsystem_t *ws = dive->weightsystem + nr - 1;
|
||||
if (!weightsystem_none(ws))
|
||||
break;
|
||||
}
|
||||
return nr;
|
||||
return dive->weightsystems.nr;
|
||||
}
|
||||
|
||||
/* copy the equipment data part of the cylinders */
|
||||
|
|
@ -1557,8 +1541,8 @@ struct dive *fixup_dive(struct dive *dive)
|
|||
cyl->end.mbar = 0;
|
||||
}
|
||||
update_cylinder_related_info(dive);
|
||||
for (i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
|
||||
weightsystem_t *ws = dive->weightsystem + i;
|
||||
for (i = 0; i < dive->weightsystems.nr; i++) {
|
||||
weightsystem_t *ws = &dive->weightsystems.weightsystems[i];
|
||||
add_weightsystem_description(ws);
|
||||
}
|
||||
/* we should always have a uniq ID as that gets assigned during alloc_dive(),
|
||||
|
|
@ -1922,14 +1906,6 @@ static void merge_events(struct dive *d, struct divecomputer *res,
|
|||
add_initial_gaschange(d, res, offset, cylinders_map2[0]);
|
||||
}
|
||||
|
||||
static void merge_weightsystem_info(weightsystem_t *res, const weightsystem_t *a, const weightsystem_t *b)
|
||||
{
|
||||
if (!a->weight.grams)
|
||||
a = b;
|
||||
res->weight = a->weight;
|
||||
res->description = copy_string(a->description);
|
||||
}
|
||||
|
||||
/* get_cylinder_idx_by_use(): Find the index of the first cylinder with a particular CCR use type.
|
||||
* The index returned corresponds to that of the first cylinder with a cylinder_use that
|
||||
* equals the appropriate enum value [oxygen, diluent, bailout] given by cylinder_use_type.
|
||||
|
|
@ -2307,11 +2283,28 @@ static void merge_cylinders(struct dive *res, const struct dive *a, const struct
|
|||
}
|
||||
}
|
||||
|
||||
/* Check whether a weightsystem table contains a given weightsystem */
|
||||
static bool has_weightsystem(const struct weightsystem_table *t, const weightsystem_t w)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < t->nr; i++) {
|
||||
if (same_weightsystem(w, t->weightsystems[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void merge_equipment(struct dive *res, const struct dive *a, const struct dive *b)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < MAX_WEIGHTSYSTEMS; i++)
|
||||
merge_weightsystem_info(res->weightsystem + i, a->weightsystem + i, b->weightsystem + i);
|
||||
for (i = 0; i < a->weightsystems.nr; i++) {
|
||||
if (!has_weightsystem(&res->weightsystems, a->weightsystems.weightsystems[i]))
|
||||
add_cloned_weightsystem(&res->weightsystems, a->weightsystems.weightsystems[i]);
|
||||
}
|
||||
for (i = 0; i < b->weightsystems.nr; i++) {
|
||||
if (!has_weightsystem(&res->weightsystems, b->weightsystems.weightsystems[i]))
|
||||
add_cloned_weightsystem(&res->weightsystems, b->weightsystems.weightsystems[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void merge_temperatures(struct dive *res, const struct dive *a, const struct dive *b)
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ struct dive {
|
|||
int rating;
|
||||
int visibility; /* 0 - 5 star rating */
|
||||
cylinder_t cylinder[MAX_CYLINDERS];
|
||||
weightsystem_t weightsystem[MAX_WEIGHTSYSTEMS];
|
||||
struct weightsystem_table weightsystems;
|
||||
char *suit;
|
||||
int sac, otu, cns, maxcns;
|
||||
|
||||
|
|
@ -374,7 +374,6 @@ extern void copy_events(const struct divecomputer *s, struct divecomputer *d);
|
|||
extern void free_events(struct event *ev);
|
||||
extern void copy_cylinders(const struct dive *s, struct dive *d, bool used_only);
|
||||
extern void copy_samples(const struct divecomputer *s, struct divecomputer *d);
|
||||
extern void copy_weights(const struct dive *s, struct dive *d);
|
||||
extern bool is_cylinder_used(const struct dive *dive, int idx);
|
||||
extern bool is_cylinder_prot(const struct dive *dive, int idx);
|
||||
extern void fill_default_cylinder(cylinder_t *cyl);
|
||||
|
|
|
|||
|
|
@ -100,8 +100,8 @@ int total_weight(const struct dive *dive)
|
|||
int i, total_grams = 0;
|
||||
|
||||
if (dive)
|
||||
for (i = 0; i < MAX_WEIGHTSYSTEMS; i++)
|
||||
total_grams += dive->weightsystem[i].weight.grams;
|
||||
for (i = 0; i < dive->weightsystems.nr; i++)
|
||||
total_grams += dive->weightsystems.weightsystems[i].weight.grams;
|
||||
return total_grams;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,29 @@
|
|||
#include "display.h"
|
||||
#include "divelist.h"
|
||||
#include "subsurface-string.h"
|
||||
#include "table.h"
|
||||
|
||||
static void free_weightsystem(weightsystem_t w)
|
||||
{
|
||||
free((void *)w.description);
|
||||
}
|
||||
|
||||
void copy_weights(const struct weightsystem_table *s, struct weightsystem_table *d)
|
||||
{
|
||||
clear_weightsystem_table(d);
|
||||
for (int i = 0; i < s->nr; i++)
|
||||
add_cloned_weightsystem(d, s->weightsystems[i]);
|
||||
}
|
||||
|
||||
/* weightsystem table functions */
|
||||
//static MAKE_GET_IDX(weightsystem_table, weightsystem_t, weightsystems)
|
||||
static MAKE_GROW_TABLE(weightsystem_table, weightsystem_t, weightsystems)
|
||||
//static MAKE_GET_INSERTION_INDEX(weightsystem_table, weightsystem_t, weightsystems, weightsystem_less_than)
|
||||
MAKE_ADD_TO(weightsystem_table, weightsystem_t, weightsystems)
|
||||
MAKE_REMOVE_FROM(weightsystem_table, weightsystems)
|
||||
//MAKE_SORT(weightsystem_table, weightsystem_t, weightsystems, comp_weightsystems)
|
||||
//MAKE_REMOVE(weightsystem_table, weightsystem_t, weightsystem)
|
||||
MAKE_CLEAR_TABLE(weightsystem_table, weightsystems, weightsystem)
|
||||
|
||||
const char *cylinderuse_text[NUM_GAS_USE] = {
|
||||
QT_TRANSLATE_NOOP("gettextFromC", "OC-gas"), QT_TRANSLATE_NOOP("gettextFromC", "diluent"), QT_TRANSLATE_NOOP("gettextFromC", "oxygen"), QT_TRANSLATE_NOOP("gettextFromC", "not used")
|
||||
|
|
@ -51,6 +74,7 @@ void add_cylinder_description(const cylinder_type_t *type)
|
|||
tank_info[i].bar = type->workingpressure.mbar / 1000;
|
||||
}
|
||||
}
|
||||
|
||||
void add_weightsystem_description(const weightsystem_t *weightsystem)
|
||||
{
|
||||
const char *desc;
|
||||
|
|
@ -72,10 +96,18 @@ void add_weightsystem_description(const weightsystem_t *weightsystem)
|
|||
}
|
||||
}
|
||||
|
||||
/* Add a clone of a weightsystem to the end of a weightsystem table.
|
||||
* Cloned in means that the description-string is copied. */
|
||||
void add_cloned_weightsystem(struct weightsystem_table *t, weightsystem_t ws)
|
||||
{
|
||||
weightsystem_t w_clone = { ws.weight, copy_string(ws.description) };
|
||||
add_to_weightsystem_table(t, t->nr, w_clone);
|
||||
}
|
||||
|
||||
bool same_weightsystem(weightsystem_t w1, weightsystem_t w2)
|
||||
{
|
||||
return w1->weight.grams == w2->weight.grams &&
|
||||
same_string(w1->description, w2->description);
|
||||
return w1.weight.grams == w2.weight.grams &&
|
||||
same_string(w1.description, w2.description);
|
||||
}
|
||||
|
||||
bool cylinder_nodata(const cylinder_t *cyl)
|
||||
|
|
@ -239,10 +271,7 @@ void remove_cylinder(struct dive *dive, int idx)
|
|||
|
||||
void remove_weightsystem(struct dive *dive, int idx)
|
||||
{
|
||||
weightsystem_t *ws = dive->weightsystem + idx;
|
||||
int nr = MAX_WEIGHTSYSTEMS - idx - 1;
|
||||
memmove(ws, ws + 1, nr * sizeof(*ws));
|
||||
memset(ws + nr, 0, sizeof(*ws));
|
||||
remove_from_weightsystem_table(&dive->weightsystems, idx);
|
||||
}
|
||||
|
||||
/* when planning a dive we need to make sure that all cylinders have a sane depth assigned
|
||||
|
|
|
|||
|
|
@ -39,12 +39,25 @@ typedef struct
|
|||
const char *description; /* "integrated", "belt", "ankle" */
|
||||
} weightsystem_t;
|
||||
|
||||
/* Table of weightsystems. Attention: this stores weightsystems,
|
||||
* *not* pointers * to weightsystems. This has two crucial
|
||||
* consequences:
|
||||
* 1) Pointers to weightsystems are not stable. They may be
|
||||
* invalidated if the table is reallocated.
|
||||
* 2) add_to_weightsystem_table(), etc. takes ownership of the
|
||||
* weightsystem. Notably of the description string */
|
||||
struct weightsystem_table {
|
||||
int nr, allocated;
|
||||
weightsystem_t *weightsystems;
|
||||
};
|
||||
|
||||
#define MAX_CYLINDERS (20)
|
||||
#define MAX_WEIGHTSYSTEMS (6)
|
||||
#define MAX_TANK_INFO (100)
|
||||
#define MAX_WS_INFO (100)
|
||||
|
||||
extern int cylinderuse_from_text(const char *text);
|
||||
extern void copy_weights(const struct weightsystem_table *s, struct weightsystem_table *d);
|
||||
extern void add_cloned_weightsystem(struct weightsystem_table *t, weightsystem_t ws);
|
||||
extern void add_cylinder_description(const cylinder_type_t *);
|
||||
extern void add_weightsystem_description(const weightsystem_t *);
|
||||
extern bool same_weightsystem(weightsystem_t w1, weightsystem_t w2);
|
||||
|
|
@ -60,6 +73,10 @@ extern int find_best_gasmix_match(struct gasmix mix, const cylinder_t array[]);
|
|||
extern void dump_cylinders(struct dive *dive, bool verbose);
|
||||
#endif
|
||||
|
||||
/* Weightsystem table functions */
|
||||
extern void clear_weightsystem_table(struct weightsystem_table *);
|
||||
extern void add_to_weightsystem_table(struct weightsystem_table *, int idx, weightsystem_t ws);
|
||||
|
||||
void get_gas_string(struct gasmix gasmix, char *text, int len);
|
||||
const char *gasname(struct gasmix gasmix);
|
||||
|
||||
|
|
|
|||
|
|
@ -311,8 +311,8 @@ static int divinglog_dive(void *param, int columns, char **data, char **column)
|
|||
state->cur_dive->watertemp.mkelvin = C_to_mkelvin(atol(data[9]));
|
||||
|
||||
if (data[10]) {
|
||||
state->cur_dive->weightsystem[0].weight.grams = atol(data[10]) * 1000;
|
||||
state->cur_dive->weightsystem[0].description = strdup(translate("gettextFromC", "unknown"));
|
||||
weightsystem_t ws = { { atol(data[10]) * 1000 }, translate("gettextFromC", "unknown") };
|
||||
add_cloned_weightsystem(&state->cur_dive->weightsystems, ws);
|
||||
}
|
||||
|
||||
if (data[11])
|
||||
|
|
|
|||
|
|
@ -330,7 +330,7 @@ static char *parse_keyvalue_entry(void (*fn)(void *, const char *, const char *)
|
|||
return line;
|
||||
}
|
||||
|
||||
static int cylinder_index, weightsystem_index;
|
||||
static int cylinder_index;
|
||||
static int o2pressure_sensor;
|
||||
|
||||
static void parse_cylinder_keyvalue(void *_cylinder, const char *key, const char *value)
|
||||
|
|
@ -424,21 +424,19 @@ static void parse_weightsystem_keyvalue(void *_ws, const char *key, const char *
|
|||
static void parse_dive_weightsystem(char *line, struct membuffer *str, void *_dive)
|
||||
{
|
||||
struct dive *dive = _dive;
|
||||
weightsystem_t *ws = dive->weightsystem + weightsystem_index;
|
||||
weightsystem_t ws = { 0 };
|
||||
|
||||
if (weightsystem_index >= MAX_WEIGHTSYSTEMS)
|
||||
return;
|
||||
|
||||
weightsystem_index++;
|
||||
ws->description = get_utf8(str);
|
||||
ws.description = get_utf8(str);
|
||||
for (;;) {
|
||||
char c;
|
||||
while (isspace(c = *line))
|
||||
line++;
|
||||
if (!c)
|
||||
break;
|
||||
line = parse_keyvalue_entry(parse_weightsystem_keyvalue, ws, line);
|
||||
line = parse_keyvalue_entry(parse_weightsystem_keyvalue, &ws, line);
|
||||
}
|
||||
|
||||
add_to_weightsystem_table(&dive->weightsystems, dive->weightsystems.nr, ws);
|
||||
}
|
||||
|
||||
static int match_action(char *line, struct membuffer *str, void *data,
|
||||
|
|
@ -1506,7 +1504,8 @@ static int parse_dive_entry(git_repository *repo, const git_tree_entry *entry, c
|
|||
return report_error("Unable to read dive file");
|
||||
if (*suffix)
|
||||
dive->number = atoi(suffix+1);
|
||||
cylinder_index = weightsystem_index = 0;
|
||||
cylinder_index = 0;
|
||||
clear_weightsystem_table(&dive->weightsystems);
|
||||
o2pressure_sensor = 1;
|
||||
for_each_line(blob, dive_parser, active_dive);
|
||||
git_blob_free(blob);
|
||||
|
|
|
|||
|
|
@ -1309,14 +1309,12 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf, str
|
|||
return;
|
||||
if (MATCH_STATE("airpressure.dive", pressure, &dive->surface_pressure))
|
||||
return;
|
||||
if (state->cur_ws_index < MAX_WEIGHTSYSTEMS) {
|
||||
if (MATCH("description.weightsystem", utf8_string, &dive->weightsystem[state->cur_ws_index].description))
|
||||
return;
|
||||
if (MATCH_STATE("weight.weightsystem", weight, &dive->weightsystem[state->cur_ws_index].weight))
|
||||
return;
|
||||
if (MATCH_STATE("weight", weight, &dive->weightsystem[state->cur_ws_index].weight))
|
||||
return;
|
||||
}
|
||||
if (MATCH("description.weightsystem", utf8_string, &dive->weightsystems.weightsystems[dive->weightsystems.nr - 1].description))
|
||||
return;
|
||||
if (MATCH_STATE("weight.weightsystem", weight, &dive->weightsystems.weightsystems[dive->weightsystems.nr - 1].weight))
|
||||
return;
|
||||
if (MATCH_STATE("weight", weight, &dive->weightsystems.weightsystems[dive->weightsystems.nr - 1].weight))
|
||||
return;
|
||||
if (state->cur_cylinder_index < MAX_CYLINDERS) {
|
||||
if (MATCH("size.cylinder", cylindersize, &dive->cylinder[state->cur_cylinder_index].type.size))
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -257,7 +257,6 @@ void dive_end(struct parser_state *state)
|
|||
state->cur_location.lat.udeg = 0;
|
||||
state->cur_location.lon.udeg = 0;
|
||||
state->cur_cylinder_index = 0;
|
||||
state->cur_ws_index = 0;
|
||||
}
|
||||
|
||||
void trip_start(struct parser_state *state)
|
||||
|
|
@ -299,11 +298,12 @@ void cylinder_end(struct parser_state *state)
|
|||
|
||||
void ws_start(struct parser_state *state)
|
||||
{
|
||||
weightsystem_t w = { {0}, "" };
|
||||
add_cloned_weightsystem(&state->cur_dive->weightsystems, w);
|
||||
}
|
||||
|
||||
void ws_end(struct parser_state *state)
|
||||
{
|
||||
state->cur_ws_index++;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ struct parser_state {
|
|||
bool in_settings;
|
||||
bool in_userid;
|
||||
struct tm cur_tm;
|
||||
int cur_cylinder_index, cur_ws_index;
|
||||
int cur_cylinder_index;
|
||||
int lastcylinderindex, next_o2_sensor;
|
||||
int o2pressure_sensor;
|
||||
int sample_rate;
|
||||
|
|
|
|||
|
|
@ -165,9 +165,9 @@ static void save_weightsystem_info(struct membuffer *b, struct dive *dive)
|
|||
|
||||
nr = nr_weightsystems(dive);
|
||||
for (i = 0; i < nr; i++) {
|
||||
weightsystem_t *ws = dive->weightsystem + i;
|
||||
int grams = ws->weight.grams;
|
||||
const char *description = ws->description;
|
||||
weightsystem_t ws = dive->weightsystems.weightsystems[i];
|
||||
int grams = ws.weight.grams;
|
||||
const char *description = ws.description;
|
||||
|
||||
put_string(b, "weightsystem");
|
||||
put_milli(b, " weight=", grams, "kg");
|
||||
|
|
|
|||
|
|
@ -106,9 +106,9 @@ static void put_weightsystem_HTML(struct membuffer *b, struct dive *dive)
|
|||
char *separator = "";
|
||||
|
||||
for (i = 0; i < nr; i++) {
|
||||
weightsystem_t *ws = dive->weightsystem + i;
|
||||
int grams = ws->weight.grams;
|
||||
const char *description = ws->description;
|
||||
weightsystem_t ws = dive->weightsystems.weightsystems[i];
|
||||
int grams = ws.weight.grams;
|
||||
const char *description = ws.description;
|
||||
|
||||
put_string(b, separator);
|
||||
separator = ", ";
|
||||
|
|
|
|||
|
|
@ -205,9 +205,9 @@ static void save_weightsystem_info(struct membuffer *b, struct dive *dive)
|
|||
nr = nr_weightsystems(dive);
|
||||
|
||||
for (i = 0; i < nr; i++) {
|
||||
weightsystem_t *ws = dive->weightsystem + i;
|
||||
int grams = ws->weight.grams;
|
||||
const char *description = ws->description;
|
||||
weightsystem_t ws = dive->weightsystems.weightsystems[i];
|
||||
int grams = ws.weight.grams;
|
||||
const char *description = ws.description;
|
||||
|
||||
put_format(b, " <weightsystem");
|
||||
put_milli(b, " weight='", grams, " kg'");
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ enum returnPressureSelector {START_PRESSURE, END_PRESSURE};
|
|||
|
||||
static QString getFormattedWeight(struct dive *dive, unsigned int idx)
|
||||
{
|
||||
weightsystem_t *weight = &dive->weightsystem[idx];
|
||||
weightsystem_t *weight = &dive->weightsystems.weightsystems[idx];
|
||||
if (!weight->description)
|
||||
return QString();
|
||||
QString fmt = QString(weight->description);
|
||||
|
|
@ -231,7 +231,7 @@ QString DiveObjectHelper::sac() const
|
|||
QString DiveObjectHelper::weightList() const
|
||||
{
|
||||
QString weights;
|
||||
for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
|
||||
for (int i = 0; i < m_dive->weightsystems.nr; i++) {
|
||||
QString w = getFormattedWeight(m_dive, i);
|
||||
if (w.isEmpty())
|
||||
continue;
|
||||
|
|
@ -243,7 +243,7 @@ QString DiveObjectHelper::weightList() const
|
|||
QStringList DiveObjectHelper::weights() const
|
||||
{
|
||||
QStringList weights;
|
||||
for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
|
||||
for (int i = 0; i < m_dive->weightsystems.nr; i++) {
|
||||
QString w = getFormattedWeight(m_dive, i);
|
||||
if (w.isEmpty())
|
||||
continue;
|
||||
|
|
@ -254,12 +254,12 @@ QStringList DiveObjectHelper::weights() const
|
|||
|
||||
bool DiveObjectHelper::singleWeight() const
|
||||
{
|
||||
return weightsystem_none(&m_dive->weightsystem[1]);
|
||||
return m_dive->weightsystems.nr == 1;
|
||||
}
|
||||
|
||||
QString DiveObjectHelper::weight(int idx) const
|
||||
{
|
||||
if ( (idx < 0) || idx > MAX_WEIGHTSYSTEMS )
|
||||
if ((idx < 0) || idx >= m_dive->weightsystems.nr)
|
||||
return QString();
|
||||
return getFormattedWeight(m_dive, idx);
|
||||
}
|
||||
|
|
|
|||
14
core/table.h
14
core/table.h
|
|
@ -50,13 +50,13 @@
|
|||
} \
|
||||
}
|
||||
|
||||
#define MAKE_REMOVE_FROM(table_type, array_name) \
|
||||
void remove_from_##table_type(struct table_type *table, int idx) \
|
||||
{ \
|
||||
int i; \
|
||||
for (i = idx; i < table->nr - 1; i++) \
|
||||
table->array_name[i] = table->array_name[i + 1]; \
|
||||
table->array_name[--table->nr] = NULL; \
|
||||
#define MAKE_REMOVE_FROM(table_type, array_name) \
|
||||
void remove_from_##table_type(struct table_type *table, int idx) \
|
||||
{ \
|
||||
int i; \
|
||||
for (i = idx; i < table->nr - 1; i++) \
|
||||
table->array_name[i] = table->array_name[i + 1]; \
|
||||
memset(&table->array_name[--table->nr], 0, sizeof(table->array_name[0])); \
|
||||
}
|
||||
|
||||
#define MAKE_GET_IDX(table_type, item_type, array_name) \
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ static void uemis_get_weight(char *buffer, weightsystem_t *weight, int diveid)
|
|||
weight->weight.grams = uemis_get_weight_unit(diveid) ?
|
||||
lbs_to_grams(ascii_strtod(buffer, NULL)) :
|
||||
lrint(ascii_strtod(buffer, NULL) * 1000);
|
||||
weight->description = strdup(translate("gettextFromC", "unknown"));
|
||||
weight->description = translate("gettextFromC", "unknown");
|
||||
}
|
||||
|
||||
static struct dive *uemis_start_dive(uint32_t deviceid)
|
||||
|
|
@ -815,7 +815,9 @@ static void parse_tag(struct dive *dive, char *tag, char *val)
|
|||
} else if (!strcmp(tag, "altitude")) {
|
||||
uemis_get_index(val, &dive->dc.surface_pressure.mbar);
|
||||
} else if (!strcmp(tag, "f32Weight")) {
|
||||
uemis_get_weight(val, &dive->weightsystem[0], dive->dc.diveid);
|
||||
weightsystem_t ws;
|
||||
uemis_get_weight(val, &ws, dive->dc.diveid);
|
||||
add_cloned_weightsystem(&dive->weightsystems, ws);
|
||||
} else if (!strcmp(tag, "notes")) {
|
||||
uemis_add_string(val, &dive->notes, " ");
|
||||
} else if (!strcmp(tag, "u8DiveSuit")) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue