core: make event name an std::string

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-04 22:17:07 +02:00 committed by bstoeger
parent 408b31b6ce
commit b8c7b173c6
20 changed files with 149 additions and 152 deletions

View file

@ -123,7 +123,7 @@ RemoveEvent::RemoveEvent(struct dive *d, int dcNr, struct event *ev) : EventBase
cylinder(ev->type == SAMPLE_EVENT_GASCHANGE2 || ev->type == SAMPLE_EVENT_GASCHANGE ? cylinder(ev->type == SAMPLE_EVENT_GASCHANGE2 || ev->type == SAMPLE_EVENT_GASCHANGE ?
ev->gas.index : -1) ev->gas.index : -1)
{ {
setText(Command::Base::tr("Remove %1 event").arg(ev->name)); setText(Command::Base::tr("Remove %1 event").arg(ev->name.c_str()));
} }
bool RemoveEvent::workToBeDone() bool RemoveEvent::workToBeDone()

View file

@ -750,11 +750,11 @@ static void sanitize_cylinder_info(struct dive *dive)
/* some events should never be thrown away */ /* some events should never be thrown away */
static bool is_potentially_redundant(const struct event *event) static bool is_potentially_redundant(const struct event *event)
{ {
if (!strcmp(event->name, "gaschange")) if (event->name == "gaschange")
return false; return false;
if (!strcmp(event->name, "bookmark")) if (event->name == "bookmark")
return false; return false;
if (!strcmp(event->name, "heading")) if (event->name == "heading")
return false; return false;
return true; return true;
} }
@ -765,10 +765,10 @@ static struct event *find_previous_event(struct divecomputer *dc, struct event *
struct event *ev = dc->events; struct event *ev = dc->events;
struct event *previous = NULL; struct event *previous = NULL;
if (empty_string(event->name)) if (event->name.empty())
return NULL; return NULL;
while (ev && ev != event) { while (ev && ev != event) {
if (same_string(ev->name, event->name)) if (ev->name == event->name)
previous = ev; previous = ev;
ev = ev->next; ev = ev->next;
} }
@ -1546,12 +1546,12 @@ static int sort_event(const struct event *a, const struct event *b, int time_a,
SORT_FIELD(a, b, type); SORT_FIELD(a, b, type);
SORT_FIELD(a, b, flags); SORT_FIELD(a, b, flags);
SORT_FIELD(a, b, value); SORT_FIELD(a, b, value);
return strcmp(a->name, b->name); return a->name.compare(b->name);
} }
static int same_gas(const struct event *a, const struct event *b) static int same_gas(const struct event *a, const struct event *b)
{ {
if (a->type == b->type && a->flags == b->flags && a->value == b->value && !strcmp(a->name, b->name) && if (a->type == b->type && a->flags == b->flags && a->value == b->value && a->name == b->name &&
same_gasmix(a->gas.mix, b->gas.mix)) { same_gasmix(a->gas.mix, b->gas.mix)) {
return true; return true;
} }

View file

@ -433,7 +433,7 @@ void add_event_to_dc(struct divecomputer *dc, struct event *ev)
*p = ev; *p = ev;
} }
struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name) struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const std::string &name)
{ {
struct event *ev = create_event(time, type, flags, value, name); struct event *ev = create_event(time, type, flags, value, name);

View file

@ -4,6 +4,7 @@
#include "divemode.h" #include "divemode.h"
#include "units.h" #include "units.h"
#include <string>
struct extra_data; struct extra_data;
struct sample; struct sample;
@ -60,7 +61,7 @@ extern void copy_events(const struct divecomputer *s, struct divecomputer *d);
extern void swap_event(struct divecomputer *dc, struct event *from, struct event *to); extern void swap_event(struct divecomputer *dc, struct event *from, struct event *to);
extern void copy_samples(const struct divecomputer *s, struct divecomputer *d); extern void copy_samples(const struct divecomputer *s, struct divecomputer *d);
extern void add_event_to_dc(struct divecomputer *dc, struct event *ev); extern void add_event_to_dc(struct divecomputer *dc, struct event *ev);
extern struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name); extern struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const std::string &name);
extern void remove_event_from_dc(struct divecomputer *dc, struct event *event); extern void remove_event_from_dc(struct divecomputer *dc, struct event *event);
extern void add_extra_data(struct divecomputer *dc, const char *key, const char *value); extern void add_extra_data(struct divecomputer *dc, const char *key, const char *value);
extern uint32_t calculate_string_hash(const char *str); extern uint32_t calculate_string_hash(const char *str);

View file

@ -9,7 +9,6 @@
event::event() : next(nullptr), type(SAMPLE_EVENT_NONE), flags(0), value(0), event::event() : next(nullptr), type(SAMPLE_EVENT_NONE), flags(0), value(0),
divemode(OC), deleted(false), hidden(false) divemode(OC), deleted(false), hidden(false)
{ {
memset(name, 0, MAX_EVENT_NAME);
/* That overwrites divemode. Is this a smart thing to do? */ /* That overwrites divemode. Is this a smart thing to do? */
gas.index = -1; gas.index = -1;
gas.mix = gasmix_air; gas.mix = gasmix_air;
@ -27,7 +26,7 @@ int event_is_gaschange(const struct event *ev)
bool event_is_divemodechange(const struct event *ev) bool event_is_divemodechange(const struct event *ev)
{ {
return same_string(ev->name, "modechange"); return ev->name == "modechange";
} }
struct event *clone_event(const struct event *src_ev) struct event *clone_event(const struct event *src_ev)
@ -52,13 +51,13 @@ void free_events(struct event *ev)
} }
} }
struct event *create_event(unsigned int time, int type, int flags, int value, const char *name) struct event *create_event(unsigned int time, int type, int flags, int value, const std::string &name)
{ {
int gas_index = -1; int gas_index = -1;
struct event *ev; struct event *ev;
ev = new event; ev = new event;
strncpy(ev->name, name, MAX_EVENT_NAME - 1); ev->name = name;
ev->time.seconds = time; ev->time.seconds = time;
ev->type = type; ev->type = type;
ev->flags = flags; ev->flags = flags;
@ -90,7 +89,7 @@ struct event *create_event(unsigned int time, int type, int flags, int value, co
return ev; return ev;
} }
struct event *clone_event_rename(const struct event *ev, const char *name) struct event *clone_event_rename(const struct event *ev, const std::string &name)
{ {
return create_event(ev->time.seconds, ev->type, ev->flags, ev->value, name); return create_event(ev->time.seconds, ev->type, ev->flags, ev->value, name);
} }
@ -105,7 +104,7 @@ bool same_event(const struct event *a, const struct event *b)
return 0; return 0;
if (a->value != b->value) if (a->value != b->value)
return 0; return 0;
return !strcmp(a->name, b->name); return a->name == b->name;
} }
extern enum event_severity get_event_severity(const struct event *ev) extern enum event_severity get_event_severity(const struct event *ev)

View file

@ -6,6 +6,7 @@
#include "gas.h" #include "gas.h"
#include "units.h" #include "units.h"
#include <string>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
enum event_severity { enum event_severity {
@ -19,7 +20,6 @@ enum event_severity {
* Events are currently based straight on what libdivecomputer gives us. * Events are currently based straight on what libdivecomputer gives us.
* We need to wrap these into our own events at some point to remove some of the limitations. * We need to wrap these into our own events at some point to remove some of the limitations.
*/ */
#define MAX_EVENT_NAME 128
struct event { struct event {
struct event *next; struct event *next;
@ -42,7 +42,7 @@ struct event {
}; };
bool deleted; // used internally in the parser and in fixup_dive(). bool deleted; // used internally in the parser and in fixup_dive().
bool hidden; bool hidden;
char name[MAX_EVENT_NAME]; std::string name;
event(); event();
~event(); ~event();
}; };
@ -51,13 +51,13 @@ extern int event_is_gaschange(const struct event *ev);
extern bool event_is_divemodechange(const struct event *ev); extern bool event_is_divemodechange(const struct event *ev);
extern struct event *clone_event(const struct event *src_ev); extern struct event *clone_event(const struct event *src_ev);
extern void free_events(struct event *ev); extern void free_events(struct event *ev);
extern struct event *create_event(unsigned int time, int type, int flags, int value, const char *name); extern struct event *create_event(unsigned int time, int type, int flags, int value, const std::string &name);
extern struct event *clone_event_rename(const struct event *ev, const char *name); extern struct event *clone_event_rename(const struct event *ev, const std::string &name);
extern bool same_event(const struct event *a, const struct event *b); extern bool same_event(const struct event *a, const struct event *b);
extern enum event_severity get_event_severity(const struct event *ev); extern enum event_severity get_event_severity(const struct event *ev);
/* Since C doesn't have parameter-based overloading, two versions of get_next_event. */ /* Since C doesn't have parameter-based overloading, two versions of get_next_event. */
extern const struct event *get_next_event(const struct event *event, const char *name); extern const struct event *get_next_event(const struct event *event, const std::string &name);
extern struct event *get_next_event_mutable(struct event *event, const char *name); extern struct event *get_next_event_mutable(struct event *event, const std::string &name);
#endif #endif

View file

@ -34,7 +34,7 @@ void clear_event_types()
void remember_event_type(const struct event *ev) void remember_event_type(const struct event *ev)
{ {
if (empty_string(ev->name)) if (ev->name.empty())
return; return;
event_type type(ev); event_type type(ev);
if (std::find(event_types.begin(), event_types.end(), type) != event_types.end()) if (std::find(event_types.begin(), event_types.end(), type) != event_types.end())
@ -104,10 +104,10 @@ static QString event_type_name(QString name, event_severity severity)
QString event_type_name(const event *ev) QString event_type_name(const event *ev)
{ {
if (!ev || empty_string(ev->name)) if (!ev || ev->name.empty())
return QString(); return QString();
QString name = QString::fromUtf8(ev->name); QString name = QString::fromStdString(ev->name);
return event_type_name(std::move(name), get_event_severity(ev)); return event_type_name(std::move(name), get_event_severity(ev));
} }

View file

@ -56,6 +56,8 @@ static int divinglog_cylinder(void *param, int, char **data, char **)
static int divinglog_profile(void *param, int, char **data, char **) static int divinglog_profile(void *param, int, char **data, char **)
{ {
using namespace std::string_literals;
struct parser_state *state = (struct parser_state *)param; struct parser_state *state = (struct parser_state *)param;
int sinterval = 0; int sinterval = 0;
@ -136,7 +138,7 @@ static int divinglog_profile(void *param, int, char **data, char **)
event_start(state); event_start(state);
state->cur_event.time.seconds = time; state->cur_event.time.seconds = time;
strcpy(state->cur_event.name, "gaschange"); state->cur_event.name = "gaschange"s;
o2 = (o2 + 5) / 10; o2 = (o2 + 5) / 10;
he = (he + 5) / 10; he = (he + 5) / 10;
@ -223,7 +225,7 @@ static int divinglog_profile(void *param, int, char **data, char **)
if (ptr1[6] - '0') { if (ptr1[6] - '0') {
event_start(state); event_start(state);
state->cur_event.time.seconds = time; state->cur_event.time.seconds = time;
strcpy(state->cur_event.name, "rbt"); state->cur_event.name = "rbt"s;
event_end(state); event_end(state);
} }
@ -231,7 +233,7 @@ static int divinglog_profile(void *param, int, char **data, char **)
if (ptr1[7] - '0') { if (ptr1[7] - '0') {
event_start(state); event_start(state);
state->cur_event.time.seconds = time; state->cur_event.time.seconds = time;
strcpy(state->cur_event.name, "ascent"); state->cur_event.name = "ascent"s;
event_end(state); event_end(state);
} }
@ -239,7 +241,7 @@ static int divinglog_profile(void *param, int, char **data, char **)
if (ptr1[8] - '0') { if (ptr1[8] - '0') {
event_start(state); event_start(state);
state->cur_event.time.seconds = time; state->cur_event.time.seconds = time;
strcpy(state->cur_event.name, "violation"); state->cur_event.name = "violation"s;
event_end(state); event_end(state);
} }
@ -247,7 +249,7 @@ static int divinglog_profile(void *param, int, char **data, char **)
if (ptr1[9] - '0') { if (ptr1[9] - '0') {
event_start(state); event_start(state);
state->cur_event.time.seconds = time; state->cur_event.time.seconds = time;
strcpy(state->cur_event.name, "workload"); state->cur_event.name = "workload"s;
event_end(state); event_end(state);
} }

View file

@ -27,11 +27,12 @@
*/ */
static int seac_gaschange(void *param, sqlite3_stmt *sqlstmt) static int seac_gaschange(void *param, sqlite3_stmt *sqlstmt)
{ {
using namespace std::string_literals;
struct parser_state *state = (struct parser_state *)param; struct parser_state *state = (struct parser_state *)param;
event_start(state); event_start(state);
state->cur_event.time.seconds = sqlite3_column_int(sqlstmt, 1); state->cur_event.time.seconds = sqlite3_column_int(sqlstmt, 1);
strcpy(state->cur_event.name, "gaschange"); state->cur_event.name = "gaschange"s;
state->cur_event.gas.mix.o2.permille = 10 * sqlite3_column_int(sqlstmt, 4); state->cur_event.gas.mix.o2.permille = 10 * sqlite3_column_int(sqlstmt, 4);
event_end(state); event_end(state);

View file

@ -21,6 +21,7 @@
static int dm4_events(void *param, int, char **data, char **) static int dm4_events(void *param, int, char **data, char **)
{ {
using namespace std::string_literals;
struct parser_state *state = (struct parser_state *)param; struct parser_state *state = (struct parser_state *)param;
event_start(state); event_start(state);
@ -31,108 +32,108 @@ static int dm4_events(void *param, int, char **data, char **)
switch (atoi(data[2])) { switch (atoi(data[2])) {
case 1: case 1:
/* 1 Mandatory Safety Stop */ /* 1 Mandatory Safety Stop */
strcpy(state->cur_event.name, "safety stop (mandatory)"); state->cur_event.name = "safety stop (mandatory)"s;
break; break;
case 3: case 3:
/* 3 Deco */ /* 3 Deco */
/* What is Subsurface's term for going to /* What is Subsurface's term for going to
* deco? */ * deco? */
strcpy(state->cur_event.name, "deco"); state->cur_event.name = "deco"s;
break; break;
case 4: case 4:
/* 4 Ascent warning */ /* 4 Ascent warning */
strcpy(state->cur_event.name, "ascent"); state->cur_event.name = "ascent"s;
break; break;
case 5: case 5:
/* 5 Ceiling broken */ /* 5 Ceiling broken */
strcpy(state->cur_event.name, "violation"); state->cur_event.name = "violation"s;
break; break;
case 6: case 6:
/* 6 Mandatory safety stop ceiling error */ /* 6 Mandatory safety stop ceiling error */
strcpy(state->cur_event.name, "violation"); state->cur_event.name = "violation"s;
break; break;
case 7: case 7:
/* 7 Below deco floor */ /* 7 Below deco floor */
strcpy(state->cur_event.name, "below floor"); state->cur_event.name = "below floor"s;
break; break;
case 8: case 8:
/* 8 Dive time alarm */ /* 8 Dive time alarm */
strcpy(state->cur_event.name, "divetime"); state->cur_event.name = "divetime"s;
break; break;
case 9: case 9:
/* 9 Depth alarm */ /* 9 Depth alarm */
strcpy(state->cur_event.name, "maxdepth"); state->cur_event.name = "maxdepth"s;
break; break;
case 10: case 10:
/* 10 OLF 80% */ /* 10 OLF 80% */
case 11: case 11:
/* 11 OLF 100% */ /* 11 OLF 100% */
strcpy(state->cur_event.name, "OLF"); state->cur_event.name = "OLF"s;
break; break;
case 12: case 12:
/* 12 High pO₂ */ /* 12 High pO₂ */
strcpy(state->cur_event.name, "PO2"); state->cur_event.name = "PO2"s;
break; break;
case 13: case 13:
/* 13 Air time */ /* 13 Air time */
strcpy(state->cur_event.name, "airtime"); state->cur_event.name = "airtime"s;
break; break;
case 17: case 17:
/* 17 Ascent warning */ /* 17 Ascent warning */
strcpy(state->cur_event.name, "ascent"); state->cur_event.name = "ascent"s;
break; break;
case 18: case 18:
/* 18 Ceiling error */ /* 18 Ceiling error */
strcpy(state->cur_event.name, "ceiling"); state->cur_event.name = "ceiling"s;
break; break;
case 19: case 19:
/* 19 Surfaced */ /* 19 Surfaced */
strcpy(state->cur_event.name, "surface"); state->cur_event.name = "surface"s;
break; break;
case 20: case 20:
/* 20 Deco */ /* 20 Deco */
strcpy(state->cur_event.name, "deco"); state->cur_event.name = "deco"s;
break; break;
case 22: case 22:
case 32: case 32:
/* 22 Mandatory safety stop violation */ /* 22 Mandatory safety stop violation */
/* 32 Deep stop violation */ /* 32 Deep stop violation */
strcpy(state->cur_event.name, "violation"); state->cur_event.name = "violation"s;
break; break;
case 30: case 30:
/* Tissue level warning */ /* Tissue level warning */
strcpy(state->cur_event.name, "tissue warning"); state->cur_event.name = "tissue warning"s;
break; break;
case 37: case 37:
/* Tank pressure alarm */ /* Tank pressure alarm */
strcpy(state->cur_event.name, "tank pressure"); state->cur_event.name = "tank pressure"s;
break; break;
case 257: case 257:
/* 257 Dive active */ /* 257 Dive active */
/* This seems to be given after surface when /* This seems to be given after surface when
* descending again. */ * descending again. */
strcpy(state->cur_event.name, "surface"); state->cur_event.name = "surface"s;
break; break;
case 258: case 258:
/* 258 Bookmark */ /* 258 Bookmark */
if (data[3]) { if (data[3]) {
strcpy(state->cur_event.name, "heading"); state->cur_event.name = "heading"s;
state->cur_event.value = atoi(data[3]); state->cur_event.value = atoi(data[3]);
} else { } else {
strcpy(state->cur_event.name, "bookmark"); state->cur_event.name = "bookmark"s;
} }
break; break;
case 259: case 259:
/* Deep stop */ /* Deep stop */
strcpy(state->cur_event.name, "Deep stop"); state->cur_event.name = "Deep stop"s;
break; break;
case 260: case 260:
/* Deep stop */ /* Deep stop */
strcpy(state->cur_event.name, "Deep stop cleared"); state->cur_event.name = "Deep stop cleared"s;
break; break;
case 266: case 266:
/* Mandatory safety stop activated */ /* Mandatory safety stop activated */
strcpy(state->cur_event.name, "safety stop (mandatory)"); state->cur_event.name = "safety stop (mandatory)"s;
break; break;
case 267: case 267:
/* Mandatory safety stop deactivated */ /* Mandatory safety stop deactivated */
@ -140,7 +141,7 @@ static int dm4_events(void *param, int, char **data, char **)
* profile so skipping as well for now */ * profile so skipping as well for now */
break; break;
default: default:
strcpy(state->cur_event.name, "unknown"); state->cur_event.name = "unknown"s;
state->cur_event.value = atoi(data[2]); state->cur_event.value = atoi(data[2]);
break; break;
} }
@ -329,13 +330,14 @@ static int dm5_cylinders(void *param, int, char **data, char **)
static int dm5_gaschange(void *param, int, char **data, char **) static int dm5_gaschange(void *param, int, char **data, char **)
{ {
using namespace std::string_literals;
struct parser_state *state = (struct parser_state *)param; struct parser_state *state = (struct parser_state *)param;
event_start(state); event_start(state);
if (data[0]) if (data[0])
state->cur_event.time.seconds = atoi(data[0]); state->cur_event.time.seconds = atoi(data[0]);
if (data[1]) { if (data[1]) {
strcpy(state->cur_event.name, "gaschange"); state->cur_event.name = "gaschange"s;
state->cur_event.value = lrint(permissive_strtod(data[1], NULL)); state->cur_event.value = lrint(permissive_strtod(data[1], NULL));
} }

View file

@ -439,14 +439,6 @@ static void cylindersize(const char *buffer, volume_t *volume)
} }
} }
static void event_name(const char *buffer, char *name)
{
std::string trimmed = trimspace(buffer);
size_t size = std::min(trimmed.size(), (size_t)MAX_EVENT_NAME);
memcpy(name, trimmed.data(), size);
name[size] = 0;
}
// We don't use gauge as a mode, and pscr doesn't exist as a libdc divemode // We don't use gauge as a mode, and pscr doesn't exist as a libdc divemode
static const char *libdc_divemode_text[] = { "oc", "cc", "pscr", "freedive", "gauge"}; static const char *libdc_divemode_text[] = { "oc", "cc", "pscr", "freedive", "gauge"};
@ -764,9 +756,9 @@ static void try_to_fill_fingerprint(const char *name, char *buf, struct parser_s
static void try_to_fill_event(const char *name, char *buf, struct parser_state *state) static void try_to_fill_event(const char *name, char *buf, struct parser_state *state)
{ {
start_match("event", name, buf); start_match("event", name, buf);
if (MATCH("event", event_name, state->cur_event.name)) if (MATCH("event", utf8_string_std, &state->cur_event.name))
return; return;
if (MATCH("name", event_name, state->cur_event.name)) if (MATCH("name", utf8_string_std, &state->cur_event.name))
return; return;
if (MATCH_STATE("time", eventtime, &state->cur_event.time)) if (MATCH_STATE("time", eventtime, &state->cur_event.time))
return; return;
@ -1931,39 +1923,39 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
state.cur_event.time.seconds = time; state.cur_event.time.seconds = time;
switch (ptr[4]) { switch (ptr[4]) {
case 1: case 1:
strcpy(state.cur_event.name, "Setpoint Manual"); state.cur_event.name = "Setpoint Manual"s;
state.cur_event.value = ptr[6]; state.cur_event.value = ptr[6];
sample_start(&state); sample_start(&state);
state.cur_sample->setpoint.mbar = ptr[6] * 10; state.cur_sample->setpoint.mbar = ptr[6] * 10;
sample_end(&state); sample_end(&state);
break; break;
case 2: case 2:
strcpy(state.cur_event.name, "Setpoint Auto"); state.cur_event.name = "Setpoint Auto"s;
state.cur_event.value = ptr[6]; state.cur_event.value = ptr[6];
sample_start(&state); sample_start(&state);
state.cur_sample->setpoint.mbar = ptr[6] * 10; state.cur_sample->setpoint.mbar = ptr[6] * 10;
sample_end(&state); sample_end(&state);
switch (ptr[7]) { switch (ptr[7]) {
case 0: case 0:
strcat(state.cur_event.name, " Manual"); state.cur_event.name += " Manual"s;
break; break;
case 1: case 1:
strcat(state.cur_event.name, " Auto Start"); state.cur_event.name += " Auto Start"s;
break; break;
case 2: case 2:
strcat(state.cur_event.name, " Auto Hypox"); state.cur_event.name += " Auto Hypox"s;
break; break;
case 3: case 3:
strcat(state.cur_event.name, " Auto Timeout"); state.cur_event.name += " Auto Timeout"s;
break; break;
case 4: case 4:
strcat(state.cur_event.name, " Auto Ascent"); state.cur_event.name += " Auto Ascent"s;
break; break;
case 5: case 5:
strcat(state.cur_event.name, " Auto Stall"); state.cur_event.name += " Auto Stall"s;
break; break;
case 6: case 6:
strcat(state.cur_event.name, " Auto SP Low"); state.cur_event.name += " Auto SP Low"s;
break; break;
default: default:
break; break;
@ -1971,14 +1963,14 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
break; break;
case 3: case 3:
// obsolete // obsolete
strcpy(state.cur_event.name, "OC"); state.cur_event.name = "OC"s;
break; break;
case 4: case 4:
// obsolete // obsolete
strcpy(state.cur_event.name, "CCR"); state.cur_event.name = "CCR"s;
break; break;
case 5: case 5:
strcpy(state.cur_event.name, "gaschange"); state.cur_event.name = "gaschange"s;
state.cur_event.type = SAMPLE_EVENT_GASCHANGE2; state.cur_event.type = SAMPLE_EVENT_GASCHANGE2;
state.cur_event.value = ptr[7] << 8 ^ ptr[6]; state.cur_event.value = ptr[7] << 8 ^ ptr[6];
@ -2001,40 +1993,40 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
} }
break; break;
case 6: case 6:
strcpy(state.cur_event.name, "Start"); state.cur_event.name = "Start"s;
break; break;
case 7: case 7:
strcpy(state.cur_event.name, "Too Fast"); state.cur_event.name = "Too Fast"s;
break; break;
case 8: case 8:
strcpy(state.cur_event.name, "Above Ceiling"); state.cur_event.name = "Above Ceiling"s;
break; break;
case 9: case 9:
strcpy(state.cur_event.name, "Toxic"); state.cur_event.name = "Toxic"s;
break; break;
case 10: case 10:
strcpy(state.cur_event.name, "Hypox"); state.cur_event.name = "Hypox"s;
break; break;
case 11: case 11:
strcpy(state.cur_event.name, "Critical"); state.cur_event.name = "Critical"s;
break; break;
case 12: case 12:
strcpy(state.cur_event.name, "Sensor Disabled"); state.cur_event.name = "Sensor Disabled"s;
break; break;
case 13: case 13:
strcpy(state.cur_event.name, "Sensor Enabled"); state.cur_event.name = "Sensor Enabled"s;
break; break;
case 14: case 14:
strcpy(state.cur_event.name, "O2 Backup"); state.cur_event.name = "O2 Backup"s;
break; break;
case 15: case 15:
strcpy(state.cur_event.name, "Peer Down"); state.cur_event.name = "Peer Down"s;
break; break;
case 16: case 16:
strcpy(state.cur_event.name, "HS Down"); state.cur_event.name = "HS Down"s;
break; break;
case 17: case 17:
strcpy(state.cur_event.name, "Inconsistent"); state.cur_event.name = "Inconsistent"s;
break; break;
case 18: case 18:
// key pressed - It should never get in here // key pressed - It should never get in here
@ -2042,53 +2034,53 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
break; break;
case 19: case 19:
// obsolete // obsolete
strcpy(state.cur_event.name, "SCR"); state.cur_event.name = "SCR"s;
break; break;
case 20: case 20:
strcpy(state.cur_event.name, "Above Stop"); state.cur_event.name = "Above Stop"s;
break; break;
case 21: case 21:
strcpy(state.cur_event.name, "Safety Miss"); state.cur_event.name = "Safety Miss"s;
break; break;
case 22: case 22:
strcpy(state.cur_event.name, "Fatal"); state.cur_event.name = "Fatal"s;
break; break;
case 23: case 23:
strcpy(state.cur_event.name, "gaschange"); state.cur_event.name = "gaschange"s;
state.cur_event.type = SAMPLE_EVENT_GASCHANGE2; state.cur_event.type = SAMPLE_EVENT_GASCHANGE2;
state.cur_event.value = ptr[7] << 8 ^ ptr[6]; state.cur_event.value = ptr[7] << 8 ^ ptr[6];
event_end(&state); event_end(&state);
break; break;
case 24: case 24:
strcpy(state.cur_event.name, "gaschange"); state.cur_event.name = "gaschange"s;
state.cur_event.type = SAMPLE_EVENT_GASCHANGE2; state.cur_event.type = SAMPLE_EVENT_GASCHANGE2;
state.cur_event.value = ptr[7] << 8 ^ ptr[6]; state.cur_event.value = ptr[7] << 8 ^ ptr[6];
event_end(&state); event_end(&state);
// This is both a mode change and a gas change event // This is both a mode change and a gas change event
// so we encode it as two separate events. // so we encode it as two separate events.
event_start(&state); event_start(&state);
strcpy(state.cur_event.name, "Change Mode"); state.cur_event.name = "Change Mode"s;
switch (ptr[8]) { switch (ptr[8]) {
case 1: case 1:
strcat(state.cur_event.name, ": OC"); state.cur_event.name += ": OC"s;
break; break;
case 2: case 2:
strcat(state.cur_event.name, ": CCR"); state.cur_event.name += ": CCR"s;
break; break;
case 3: case 3:
strcat(state.cur_event.name, ": mCCR"); state.cur_event.name += ": mCCR"s;
break; break;
case 4: case 4:
strcat(state.cur_event.name, ": Free"); state.cur_event.name += ": Free"s;
break; break;
case 5: case 5:
strcat(state.cur_event.name, ": Gauge"); state.cur_event.name += ": Gauge"s;
break; break;
case 6: case 6:
strcat(state.cur_event.name, ": ASCR"); state.cur_event.name += ": ASCR"s;
break; break;
case 7: case 7:
strcat(state.cur_event.name, ": PSCR"); state.cur_event.name += ": PSCR"s;
break; break;
default: default:
break; break;
@ -2098,22 +2090,22 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
case 25: case 25:
// uint16_t solenoid_bitmap = (ptr[7] << 8) + (ptr[6] << 0); // uint16_t solenoid_bitmap = (ptr[7] << 8) + (ptr[6] << 0);
// uint32_t time = (ptr[11] << 24) + (ptr[10] << 16) + (ptr[9] << 8) + (ptr[8] << 0); // uint32_t time = (ptr[11] << 24) + (ptr[10] << 16) + (ptr[9] << 8) + (ptr[8] << 0);
snprintf(state.cur_event.name, MAX_EVENT_NAME, "CCR O2 solenoid %s", ptr[12] ? "opened": "closed"); state.cur_event.name = format_string_std("CCR O2 solenoid %s", ptr[12] ? "opened": "closed");
break; break;
case 26: case 26:
strcpy(state.cur_event.name, "User mark"); state.cur_event.name = "User mark"s;
break; break;
case 27: case 27:
snprintf(state.cur_event.name, MAX_EVENT_NAME, "%sGF Switch (%d/%d)", ptr[6] ? "Bailout, ": "", ptr[7], ptr[8]); state.cur_event.name = format_string_std("%sGF Switch (%d/%d)", ptr[6] ? "Bailout, ": "", ptr[7], ptr[8]);
break; break;
case 28: case 28:
strcpy(state.cur_event.name, "Peer Up"); state.cur_event.name = "Peer Up"s;
break; break;
case 29: case 29:
strcpy(state.cur_event.name, "HS Up"); state.cur_event.name = "HS Up"s;
break; break;
case 30: case 30:
snprintf(state.cur_event.name, MAX_EVENT_NAME, "CNS %d%%", ptr[6]); state.cur_event.name = format_string_std("CNS %d%%", ptr[6]);
break; break;
default: default:
// No values above 30 had any description // No values above 30 had any description

View file

@ -72,7 +72,7 @@ void event_end(struct parser_state *state)
struct divecomputer *dc = get_dc(state); struct divecomputer *dc = get_dc(state);
if (state->cur_event.type == 123) { if (state->cur_event.type == 123) {
struct picture pic; struct picture pic;
pic.filename = strdup(state->cur_event.name); pic.filename = strdup(state->cur_event.name.c_str());
/* theoretically this could fail - but we didn't support multi year offsets */ /* theoretically this could fail - but we didn't support multi year offsets */
pic.offset.seconds = state->cur_event.time.seconds; pic.offset.seconds = state->cur_event.time.seconds;
add_picture(&state->cur_dive->pictures, pic); /* Takes ownership. */ add_picture(&state->cur_dive->pictures, pic); /* Takes ownership. */
@ -81,7 +81,7 @@ void event_end(struct parser_state *state)
/* At some point gas change events did not have any type. Thus we need to add /* At some point gas change events did not have any type. Thus we need to add
* one on import, if we encounter the type one missing. * one on import, if we encounter the type one missing.
*/ */
if (state->cur_event.type == 0 && strcmp(state->cur_event.name, "gaschange") == 0) if (state->cur_event.type == 0 && state->cur_event.name == "gaschange")
state->cur_event.type = state->cur_event.value >> 16 > 0 ? SAMPLE_EVENT_GASCHANGE2 : SAMPLE_EVENT_GASCHANGE; state->cur_event.type = state->cur_event.value >> 16 > 0 ? SAMPLE_EVENT_GASCHANGE2 : SAMPLE_EVENT_GASCHANGE;
ev = add_event(dc, state->cur_event.time.seconds, ev = add_event(dc, state->cur_event.time.seconds,
state->cur_event.type, state->cur_event.flags, state->cur_event.type, state->cur_event.flags,

View file

@ -86,7 +86,7 @@ int get_cylinderid_at_time(struct dive *dive, struct divecomputer *dc, duration_
int cylinder_idx = 0; int cylinder_idx = 0;
struct event *event = dc->events; struct event *event = dc->events;
while (event && event->time.seconds <= time.seconds) { while (event && event->time.seconds <= time.seconds) {
if (!strcmp(event->name, "gaschange")) if (event->name == "gaschange")
cylinder_idx = get_cylinder_index(dive, event); cylinder_idx = get_cylinder_index(dive, event);
event = event->next; event = event->next;
} }

View file

@ -221,19 +221,19 @@ int get_cylinder_index(const struct dive *dive, const struct event *ev)
return best < 0 ? 0 : best; return best < 0 ? 0 : best;
} }
struct event *get_next_event_mutable(struct event *event, const char *name) struct event *get_next_event_mutable(struct event *event, const std::string &name)
{ {
if (!name || !*name) if (name.empty())
return NULL; return NULL;
while (event) { while (event) {
if (same_string(event->name, name)) if (event->name == name)
return event; return event;
event = event->next; event = event->next;
} }
return event; return event;
} }
const struct event *get_next_event(const struct event *event, const char *name) const struct event *get_next_event(const struct event *event, const std::string &name)
{ {
return get_next_event_mutable((struct event *)event, name); return get_next_event_mutable((struct event *)event, name);
} }

View file

@ -397,11 +397,11 @@ static void save_one_event(struct membuffer *b, struct dive *dive, struct event
show_index(b, ev->type, "type=", ""); show_index(b, ev->type, "type=", "");
show_index(b, ev->flags, "flags=", ""); show_index(b, ev->flags, "flags=", "");
if (!strcmp(ev->name,"modechange")) if (ev->name == "modechange")
show_utf8(b, " divemode=", divemode_text[ev->value], ""); show_utf8(b, " divemode=", divemode_text[ev->value], "");
else else
show_index(b, ev->value, "value=", ""); show_index(b, ev->value, "value=", "");
show_utf8(b, " name=", ev->name, ""); show_utf8(b, " name=", ev->name.c_str(), "");
if (event_is_gaschange(ev)) { if (event_is_gaschange(ev)) {
struct gasmix mix = get_gasmix_from_event(dive, ev); struct gasmix mix = get_gasmix_from_event(dive, ev);
if (ev->gas.index >= 0) if (ev->gas.index >= 0)

View file

@ -91,7 +91,7 @@ static void put_HTML_bookmarks(struct membuffer *b, struct dive *dive)
put_string(b, separator); put_string(b, separator);
separator = ", "; separator = ", ";
put_string(b, "{\"name\":\""); put_string(b, "{\"name\":\"");
put_quoted(b, ev->name, 1, 0); put_quoted(b, ev->name.c_str(), 1, 0);
put_string(b, "\","); put_string(b, "\",");
put_format(b, "\"value\":\"%d\",", ev->value); put_format(b, "\"value\":\"%d\",", ev->value);
put_format(b, "\"type\":\"%d\",", ev->type); put_format(b, "\"type\":\"%d\",", ev->type);

View file

@ -358,11 +358,11 @@ static void save_one_event(struct membuffer *b, struct dive *dive, struct event
put_format(b, " <event time='%d:%02d min'", FRACTION_TUPLE(ev->time.seconds, 60)); put_format(b, " <event time='%d:%02d min'", FRACTION_TUPLE(ev->time.seconds, 60));
show_index(b, ev->type, "type='", "'"); show_index(b, ev->type, "type='", "'");
show_index(b, ev->flags, "flags='", "'"); show_index(b, ev->flags, "flags='", "'");
if (!strcmp(ev->name,"modechange")) if (ev->name == "modechange")
show_utf8(b, divemode_text[ev->value], " divemode='", "'",1); show_utf8(b, divemode_text[ev->value], " divemode='", "'",1);
else else
show_index(b, ev->value, "value='", "'"); show_index(b, ev->value, "value='", "'");
show_utf8(b, ev->name, " name='", "'", 1); show_utf8(b, ev->name.c_str(), " name='", "'", 1);
if (event_is_gaschange(ev)) { if (event_is_gaschange(ev)) {
struct gasmix mix = get_gasmix_from_event(dive, ev); struct gasmix mix = get_gasmix_from_event(dive, ev);
if (ev->gas.index >= 0) if (ev->gas.index >= 0)

View file

@ -49,9 +49,9 @@ struct event *DiveEventItem::getEventMutable()
void DiveEventItem::setupPixmap(struct gasmix lastgasmix, const DivePixmaps &pixmaps) void DiveEventItem::setupPixmap(struct gasmix lastgasmix, const DivePixmaps &pixmaps)
{ {
event_severity severity = get_event_severity(ev); event_severity severity = get_event_severity(ev);
if (empty_string(ev->name)) { if (ev->name.empty()) {
setPixmap(pixmaps.warning); setPixmap(pixmaps.warning);
} else if (same_string_caseinsensitive(ev->name, "modechange")) { } else if (same_string_caseinsensitive(ev->name.c_str(), "modechange")) {
if (ev->value == 0) if (ev->value == 0)
setPixmap(pixmaps.bailout); setPixmap(pixmaps.bailout);
else else
@ -86,8 +86,8 @@ void DiveEventItem::setupPixmap(struct gasmix lastgasmix, const DivePixmaps &pix
} }
} else if ((((ev->flags & SAMPLE_FLAGS_SEVERITY_MASK) >> SAMPLE_FLAGS_SEVERITY_SHIFT) == 1) || } else if ((((ev->flags & SAMPLE_FLAGS_SEVERITY_MASK) >> SAMPLE_FLAGS_SEVERITY_SHIFT) == 1) ||
// those are useless internals of the dive computer // those are useless internals of the dive computer
same_string_caseinsensitive(ev->name, "heading") || same_string_caseinsensitive(ev->name.c_str(), "heading") ||
(same_string_caseinsensitive(ev->name, "SP change") && ev->time.seconds == 0)) { (same_string_caseinsensitive(ev->name.c_str(), "SP change") && ev->time.seconds == 0)) {
// 2 cases: // 2 cases:
// a) some dive computers have heading in every sample // a) some dive computers have heading in every sample
// b) at t=0 we might have an "SP change" to indicate dive type // b) at t=0 we might have an "SP change" to indicate dive type
@ -102,19 +102,19 @@ void DiveEventItem::setupPixmap(struct gasmix lastgasmix, const DivePixmaps &pix
setPixmap(pixmaps.warning); setPixmap(pixmaps.warning);
} else if (severity == EVENT_SEVERITY_ALARM) { } else if (severity == EVENT_SEVERITY_ALARM) {
setPixmap(pixmaps.violation); setPixmap(pixmaps.violation);
} else if (same_string_caseinsensitive(ev->name, "violation") || // generic libdivecomputer } else if (same_string_caseinsensitive(ev->name.c_str(), "violation") || // generic libdivecomputer
same_string_caseinsensitive(ev->name, "Safety stop violation") || // the rest are from the Uemis downloader same_string_caseinsensitive(ev->name.c_str(), "Safety stop violation") || // the rest are from the Uemis downloader
same_string_caseinsensitive(ev->name, "pO₂ ascend alarm") || same_string_caseinsensitive(ev->name.c_str(), "pO₂ ascend alarm") ||
same_string_caseinsensitive(ev->name, "RGT alert") || same_string_caseinsensitive(ev->name.c_str(), "RGT alert") ||
same_string_caseinsensitive(ev->name, "Dive time alert") || same_string_caseinsensitive(ev->name.c_str(), "Dive time alert") ||
same_string_caseinsensitive(ev->name, "Low battery alert") || same_string_caseinsensitive(ev->name.c_str(), "Low battery alert") ||
same_string_caseinsensitive(ev->name, "Speed alarm")) { same_string_caseinsensitive(ev->name.c_str(), "Speed alarm")) {
setPixmap(pixmaps.violation); setPixmap(pixmaps.violation);
} else if (same_string_caseinsensitive(ev->name, "non stop time") || // generic libdivecomputer } else if (same_string_caseinsensitive(ev->name.c_str(), "non stop time") || // generic libdivecomputer
same_string_caseinsensitive(ev->name, "safety stop") || same_string_caseinsensitive(ev->name.c_str(), "safety stop") ||
same_string_caseinsensitive(ev->name, "safety stop (voluntary)") || same_string_caseinsensitive(ev->name.c_str(), "safety stop (voluntary)") ||
same_string_caseinsensitive(ev->name, "Tank change suggested") || // Uemis downloader same_string_caseinsensitive(ev->name.c_str(), "Tank change suggested") || // Uemis downloader
same_string_caseinsensitive(ev->name, "Marker")) { same_string_caseinsensitive(ev->name.c_str(), "Marker")) {
setPixmap(pixmaps.info); setPixmap(pixmaps.info);
} else { } else {
// we should do some guessing based on the type / name of the event; // we should do some guessing based on the type / name of the event;
@ -126,7 +126,7 @@ void DiveEventItem::setupPixmap(struct gasmix lastgasmix, const DivePixmaps &pix
void DiveEventItem::setupToolTipString(struct gasmix lastgasmix) void DiveEventItem::setupToolTipString(struct gasmix lastgasmix)
{ {
// we display the event on screen - so translate // we display the event on screen - so translate
QString name = gettextFromC::tr(ev->name); QString name = gettextFromC::tr(ev->name.c_str());
int value = ev->value; int value = ev->value;
int type = ev->type; int type = ev->type;
@ -147,19 +147,19 @@ void DiveEventItem::setupToolTipString(struct gasmix lastgasmix)
qPrintable(tr("ΔN₂")), icd_data.dN2 / 10.0, qPrintable(tr("ΔN₂")), icd_data.dN2 / 10.0,
icd ? ">" : "<", lrint(-icd_data.dHe / 5.0) / 10.0); icd ? ">" : "<", lrint(-icd_data.dHe / 5.0) / 10.0);
} }
} else if (same_string(ev->name, "modechange")) { } else if (ev->name == "modechange") {
name += QString(": %1").arg(gettextFromC::tr(divemode_text_ui[ev->value])); name += QString(": %1").arg(gettextFromC::tr(divemode_text_ui[ev->value]));
} else if (value) { } else if (value) {
if (type == SAMPLE_EVENT_PO2 && same_string(ev->name, "SP change")) { if (type == SAMPLE_EVENT_PO2 && ev->name == "SP change") {
name += QString(": %1bar").arg((double)value / 1000, 0, 'f', 1); name += QString(": %1bar").arg((double)value / 1000, 0, 'f', 1);
} else if (type == SAMPLE_EVENT_CEILING && same_string(ev->name, "planned waypoint above ceiling")) { } else if (type == SAMPLE_EVENT_CEILING && ev->name == "planned waypoint above ceiling") {
const char *depth_unit; const char *depth_unit;
double depth_value = get_depth_units(value*1000, NULL, &depth_unit); double depth_value = get_depth_units(value*1000, NULL, &depth_unit);
name += QString(": %1%2").arg((int) round(depth_value)).arg(depth_unit); name += QString(": %1%2").arg((int) round(depth_value)).arg(depth_unit);
} else { } else {
name += QString(": %1").arg(value); name += QString(": %1").arg(value);
} }
} else if (type == SAMPLE_EVENT_PO2 && same_string(ev->name, "SP change")) { } else if (type == SAMPLE_EVENT_PO2 && ev->name == "SP change") {
// this is a bad idea - we are abusing an existing event type that is supposed to // this is a bad idea - we are abusing an existing event type that is supposed to
// warn of high or low pO₂ and are turning it into a setpoint change event // warn of high or low pO₂ and are turning it into a setpoint change event
name += ":\n" + tr("Manual switch to OC"); name += ":\n" + tr("Manual switch to OC");
@ -202,7 +202,7 @@ bool DiveEventItem::isInteresting(const struct dive *d, const struct divecompute
* Don't bother showing those * Don't bother showing those
*/ */
const struct sample *first_sample = &dc->sample[0]; const struct sample *first_sample = &dc->sample[0];
if (!strcmp(ev->name, "gaschange") && if (ev->name == "gaschange" &&
(ev->time.seconds == 0 || (ev->time.seconds == 0 ||
(first_sample && ev->time.seconds == first_sample->time.seconds) || (first_sample && ev->time.seconds == first_sample->time.seconds) ||
depthAtTime(pi, ev->time) < SURFACE_THRESHOLD)) depthAtTime(pi, ev->time) < SURFACE_THRESHOLD))
@ -212,7 +212,7 @@ bool DiveEventItem::isInteresting(const struct dive *d, const struct divecompute
* Some divecomputers give "surface" events that just aren't interesting. * Some divecomputers give "surface" events that just aren't interesting.
* Like at the beginning or very end of a dive. Well, duh. * Like at the beginning or very end of a dive. Well, duh.
*/ */
if (!strcmp(ev->name, "surface")) { if (ev->name == "surface") {
int time = ev->time.seconds; int time = ev->time.seconds;
if (time <= 30 || time + 30 >= (int)dc->duration.seconds) if (time <= 30 || time + 30 >= (int)dc->duration.seconds)
return false; return false;

View file

@ -556,9 +556,9 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM
while (event) { while (event) {
// if print mode is selected only draw headings, SP change, gas events or bookmark event // if print mode is selected only draw headings, SP change, gas events or bookmark event
if (printMode) { if (printMode) {
if (empty_string(event->name) || if (event->name.empty() ||
!(strcmp(event->name, "heading") == 0 || !(event->name == "heading" ||
(same_string(event->name, "SP change") && event->time.seconds == 0) || (event->name == "SP change" && event->time.seconds == 0) ||
event_is_gaschange(event) || event_is_gaschange(event) ||
event->type == SAMPLE_EVENT_BOOKMARK)) { event->type == SAMPLE_EVENT_BOOKMARK)) {
event = event->next; event = event->next;

View file

@ -697,7 +697,7 @@ void ProfileWidget2::hideEventType(DiveEventItem *item)
{ {
const struct event *event = item->getEvent(); const struct event *event = item->getEvent();
if (!empty_string(event->name)) { if (!event->name.empty()) {
hide_event_type(event); hide_event_type(event);
replot(); replot();
@ -727,7 +727,7 @@ void ProfileWidget2::removeEvent(DiveEventItem *item)
if (QMessageBox::question(this, TITLE_OR_TEXT( if (QMessageBox::question(this, TITLE_OR_TEXT(
tr("Remove the selected event?"), tr("Remove the selected event?"),
tr("%1 @ %2:%3").arg(event->name).arg(event->time.seconds / 60).arg(event->time.seconds % 60, 2, 10, QChar('0'))), tr("%1 @ %2:%3").arg(QString::fromStdString(event->name)).arg(event->time.seconds / 60).arg(event->time.seconds % 60, 2, 10, QChar('0'))),
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok)
Command::removeEvent(mutable_dive(), dc, event); Command::removeEvent(mutable_dive(), dc, event);
} }
@ -786,7 +786,7 @@ void ProfileWidget2::editName(DiveEventItem *item)
bool ok; bool ok;
QString newName = QInputDialog::getText(this, tr("Edit name of bookmark"), QString newName = QInputDialog::getText(this, tr("Edit name of bookmark"),
tr("Custom name:"), QLineEdit::Normal, tr("Custom name:"), QLineEdit::Normal,
event->name, &ok); event->name.c_str(), &ok);
if (ok && !newName.isEmpty()) { if (ok && !newName.isEmpty()) {
if (newName.length() > 22) { //longer names will display as garbage. if (newName.length() > 22) { //longer names will display as garbage.
QMessageBox lengthWarning; QMessageBox lengthWarning;