mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
core: make event name an std::string
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
408b31b6ce
commit
b8c7b173c6
20 changed files with 149 additions and 152 deletions
|
@ -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 ?
|
||||
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()
|
||||
|
|
|
@ -750,11 +750,11 @@ static void sanitize_cylinder_info(struct dive *dive)
|
|||
/* some events should never be thrown away */
|
||||
static bool is_potentially_redundant(const struct event *event)
|
||||
{
|
||||
if (!strcmp(event->name, "gaschange"))
|
||||
if (event->name == "gaschange")
|
||||
return false;
|
||||
if (!strcmp(event->name, "bookmark"))
|
||||
if (event->name == "bookmark")
|
||||
return false;
|
||||
if (!strcmp(event->name, "heading"))
|
||||
if (event->name == "heading")
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
@ -765,10 +765,10 @@ static struct event *find_previous_event(struct divecomputer *dc, struct event *
|
|||
struct event *ev = dc->events;
|
||||
struct event *previous = NULL;
|
||||
|
||||
if (empty_string(event->name))
|
||||
if (event->name.empty())
|
||||
return NULL;
|
||||
while (ev && ev != event) {
|
||||
if (same_string(ev->name, event->name))
|
||||
if (ev->name == event->name)
|
||||
previous = ev;
|
||||
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, flags);
|
||||
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)
|
||||
{
|
||||
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)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -433,7 +433,7 @@ void add_event_to_dc(struct divecomputer *dc, struct event *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);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "divemode.h"
|
||||
#include "units.h"
|
||||
#include <string>
|
||||
|
||||
struct extra_data;
|
||||
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 copy_samples(const struct divecomputer *s, struct divecomputer *d);
|
||||
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 add_extra_data(struct divecomputer *dc, const char *key, const char *value);
|
||||
extern uint32_t calculate_string_hash(const char *str);
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
event::event() : next(nullptr), type(SAMPLE_EVENT_NONE), flags(0), value(0),
|
||||
divemode(OC), deleted(false), hidden(false)
|
||||
{
|
||||
memset(name, 0, MAX_EVENT_NAME);
|
||||
/* That overwrites divemode. Is this a smart thing to do? */
|
||||
gas.index = -1;
|
||||
gas.mix = gasmix_air;
|
||||
|
@ -27,7 +26,7 @@ int event_is_gaschange(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)
|
||||
|
@ -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;
|
||||
struct event *ev;
|
||||
|
||||
ev = new event;
|
||||
strncpy(ev->name, name, MAX_EVENT_NAME - 1);
|
||||
ev->name = name;
|
||||
ev->time.seconds = time;
|
||||
ev->type = type;
|
||||
ev->flags = flags;
|
||||
|
@ -90,7 +89,7 @@ struct event *create_event(unsigned int time, int type, int flags, int value, co
|
|||
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);
|
||||
}
|
||||
|
@ -105,7 +104,7 @@ bool same_event(const struct event *a, const struct event *b)
|
|||
return 0;
|
||||
if (a->value != b->value)
|
||||
return 0;
|
||||
return !strcmp(a->name, b->name);
|
||||
return a->name == b->name;
|
||||
}
|
||||
|
||||
extern enum event_severity get_event_severity(const struct event *ev)
|
||||
|
|
12
core/event.h
12
core/event.h
|
@ -6,6 +6,7 @@
|
|||
#include "gas.h"
|
||||
#include "units.h"
|
||||
|
||||
#include <string>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
enum event_severity {
|
||||
|
@ -19,7 +20,6 @@ enum event_severity {
|
|||
* 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.
|
||||
*/
|
||||
#define MAX_EVENT_NAME 128
|
||||
|
||||
struct event {
|
||||
struct event *next;
|
||||
|
@ -42,7 +42,7 @@ struct event {
|
|||
};
|
||||
bool deleted; // used internally in the parser and in fixup_dive().
|
||||
bool hidden;
|
||||
char name[MAX_EVENT_NAME];
|
||||
std::string name;
|
||||
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 struct event *clone_event(const struct event *src_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 *clone_event_rename(const struct event *ev, 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 std::string &name);
|
||||
extern bool same_event(const struct event *a, const struct event *b);
|
||||
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. */
|
||||
extern const struct event *get_next_event(const struct event *event, const char *name);
|
||||
extern struct event *get_next_event_mutable(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 std::string &name);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -34,7 +34,7 @@ void clear_event_types()
|
|||
|
||||
void remember_event_type(const struct event *ev)
|
||||
{
|
||||
if (empty_string(ev->name))
|
||||
if (ev->name.empty())
|
||||
return;
|
||||
event_type type(ev);
|
||||
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)
|
||||
{
|
||||
if (!ev || empty_string(ev->name))
|
||||
if (!ev || ev->name.empty())
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,8 @@ static int divinglog_cylinder(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;
|
||||
|
||||
int sinterval = 0;
|
||||
|
@ -136,7 +138,7 @@ static int divinglog_profile(void *param, int, char **data, char **)
|
|||
|
||||
event_start(state);
|
||||
state->cur_event.time.seconds = time;
|
||||
strcpy(state->cur_event.name, "gaschange");
|
||||
state->cur_event.name = "gaschange"s;
|
||||
|
||||
o2 = (o2 + 5) / 10;
|
||||
he = (he + 5) / 10;
|
||||
|
@ -223,7 +225,7 @@ static int divinglog_profile(void *param, int, char **data, char **)
|
|||
if (ptr1[6] - '0') {
|
||||
event_start(state);
|
||||
state->cur_event.time.seconds = time;
|
||||
strcpy(state->cur_event.name, "rbt");
|
||||
state->cur_event.name = "rbt"s;
|
||||
event_end(state);
|
||||
}
|
||||
|
||||
|
@ -231,7 +233,7 @@ static int divinglog_profile(void *param, int, char **data, char **)
|
|||
if (ptr1[7] - '0') {
|
||||
event_start(state);
|
||||
state->cur_event.time.seconds = time;
|
||||
strcpy(state->cur_event.name, "ascent");
|
||||
state->cur_event.name = "ascent"s;
|
||||
event_end(state);
|
||||
}
|
||||
|
||||
|
@ -239,7 +241,7 @@ static int divinglog_profile(void *param, int, char **data, char **)
|
|||
if (ptr1[8] - '0') {
|
||||
event_start(state);
|
||||
state->cur_event.time.seconds = time;
|
||||
strcpy(state->cur_event.name, "violation");
|
||||
state->cur_event.name = "violation"s;
|
||||
event_end(state);
|
||||
}
|
||||
|
||||
|
@ -247,7 +249,7 @@ static int divinglog_profile(void *param, int, char **data, char **)
|
|||
if (ptr1[9] - '0') {
|
||||
event_start(state);
|
||||
state->cur_event.time.seconds = time;
|
||||
strcpy(state->cur_event.name, "workload");
|
||||
state->cur_event.name = "workload"s;
|
||||
event_end(state);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,11 +27,12 @@
|
|||
*/
|
||||
static int seac_gaschange(void *param, sqlite3_stmt *sqlstmt)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
struct parser_state *state = (struct parser_state *)param;
|
||||
|
||||
event_start(state);
|
||||
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);
|
||||
event_end(state);
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
static int dm4_events(void *param, int, char **data, char **)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
struct parser_state *state = (struct parser_state *)param;
|
||||
|
||||
event_start(state);
|
||||
|
@ -31,108 +32,108 @@ static int dm4_events(void *param, int, char **data, char **)
|
|||
switch (atoi(data[2])) {
|
||||
case 1:
|
||||
/* 1 Mandatory Safety Stop */
|
||||
strcpy(state->cur_event.name, "safety stop (mandatory)");
|
||||
state->cur_event.name = "safety stop (mandatory)"s;
|
||||
break;
|
||||
case 3:
|
||||
/* 3 Deco */
|
||||
/* What is Subsurface's term for going to
|
||||
* deco? */
|
||||
strcpy(state->cur_event.name, "deco");
|
||||
state->cur_event.name = "deco"s;
|
||||
break;
|
||||
case 4:
|
||||
/* 4 Ascent warning */
|
||||
strcpy(state->cur_event.name, "ascent");
|
||||
state->cur_event.name = "ascent"s;
|
||||
break;
|
||||
case 5:
|
||||
/* 5 Ceiling broken */
|
||||
strcpy(state->cur_event.name, "violation");
|
||||
state->cur_event.name = "violation"s;
|
||||
break;
|
||||
case 6:
|
||||
/* 6 Mandatory safety stop ceiling error */
|
||||
strcpy(state->cur_event.name, "violation");
|
||||
state->cur_event.name = "violation"s;
|
||||
break;
|
||||
case 7:
|
||||
/* 7 Below deco floor */
|
||||
strcpy(state->cur_event.name, "below floor");
|
||||
state->cur_event.name = "below floor"s;
|
||||
break;
|
||||
case 8:
|
||||
/* 8 Dive time alarm */
|
||||
strcpy(state->cur_event.name, "divetime");
|
||||
state->cur_event.name = "divetime"s;
|
||||
break;
|
||||
case 9:
|
||||
/* 9 Depth alarm */
|
||||
strcpy(state->cur_event.name, "maxdepth");
|
||||
state->cur_event.name = "maxdepth"s;
|
||||
break;
|
||||
case 10:
|
||||
/* 10 OLF 80% */
|
||||
case 11:
|
||||
/* 11 OLF 100% */
|
||||
strcpy(state->cur_event.name, "OLF");
|
||||
state->cur_event.name = "OLF"s;
|
||||
break;
|
||||
case 12:
|
||||
/* 12 High pO₂ */
|
||||
strcpy(state->cur_event.name, "PO2");
|
||||
state->cur_event.name = "PO2"s;
|
||||
break;
|
||||
case 13:
|
||||
/* 13 Air time */
|
||||
strcpy(state->cur_event.name, "airtime");
|
||||
state->cur_event.name = "airtime"s;
|
||||
break;
|
||||
case 17:
|
||||
/* 17 Ascent warning */
|
||||
strcpy(state->cur_event.name, "ascent");
|
||||
state->cur_event.name = "ascent"s;
|
||||
break;
|
||||
case 18:
|
||||
/* 18 Ceiling error */
|
||||
strcpy(state->cur_event.name, "ceiling");
|
||||
state->cur_event.name = "ceiling"s;
|
||||
break;
|
||||
case 19:
|
||||
/* 19 Surfaced */
|
||||
strcpy(state->cur_event.name, "surface");
|
||||
state->cur_event.name = "surface"s;
|
||||
break;
|
||||
case 20:
|
||||
/* 20 Deco */
|
||||
strcpy(state->cur_event.name, "deco");
|
||||
state->cur_event.name = "deco"s;
|
||||
break;
|
||||
case 22:
|
||||
case 32:
|
||||
/* 22 Mandatory safety stop violation */
|
||||
/* 32 Deep stop violation */
|
||||
strcpy(state->cur_event.name, "violation");
|
||||
state->cur_event.name = "violation"s;
|
||||
break;
|
||||
case 30:
|
||||
/* Tissue level warning */
|
||||
strcpy(state->cur_event.name, "tissue warning");
|
||||
state->cur_event.name = "tissue warning"s;
|
||||
break;
|
||||
case 37:
|
||||
/* Tank pressure alarm */
|
||||
strcpy(state->cur_event.name, "tank pressure");
|
||||
state->cur_event.name = "tank pressure"s;
|
||||
break;
|
||||
case 257:
|
||||
/* 257 Dive active */
|
||||
/* This seems to be given after surface when
|
||||
* descending again. */
|
||||
strcpy(state->cur_event.name, "surface");
|
||||
state->cur_event.name = "surface"s;
|
||||
break;
|
||||
case 258:
|
||||
/* 258 Bookmark */
|
||||
if (data[3]) {
|
||||
strcpy(state->cur_event.name, "heading");
|
||||
state->cur_event.name = "heading"s;
|
||||
state->cur_event.value = atoi(data[3]);
|
||||
} else {
|
||||
strcpy(state->cur_event.name, "bookmark");
|
||||
state->cur_event.name = "bookmark"s;
|
||||
}
|
||||
break;
|
||||
case 259:
|
||||
/* Deep stop */
|
||||
strcpy(state->cur_event.name, "Deep stop");
|
||||
state->cur_event.name = "Deep stop"s;
|
||||
break;
|
||||
case 260:
|
||||
/* Deep stop */
|
||||
strcpy(state->cur_event.name, "Deep stop cleared");
|
||||
state->cur_event.name = "Deep stop cleared"s;
|
||||
break;
|
||||
case 266:
|
||||
/* Mandatory safety stop activated */
|
||||
strcpy(state->cur_event.name, "safety stop (mandatory)");
|
||||
state->cur_event.name = "safety stop (mandatory)"s;
|
||||
break;
|
||||
case 267:
|
||||
/* 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 */
|
||||
break;
|
||||
default:
|
||||
strcpy(state->cur_event.name, "unknown");
|
||||
state->cur_event.name = "unknown"s;
|
||||
state->cur_event.value = atoi(data[2]);
|
||||
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 **)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
struct parser_state *state = (struct parser_state *)param;
|
||||
|
||||
event_start(state);
|
||||
if (data[0])
|
||||
state->cur_event.time.seconds = atoi(data[0]);
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
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)
|
||||
{
|
||||
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;
|
||||
if (MATCH("name", event_name, state->cur_event.name))
|
||||
if (MATCH("name", utf8_string_std, &state->cur_event.name))
|
||||
return;
|
||||
if (MATCH_STATE("time", eventtime, &state->cur_event.time))
|
||||
return;
|
||||
|
@ -1931,39 +1923,39 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
|
|||
state.cur_event.time.seconds = time;
|
||||
switch (ptr[4]) {
|
||||
case 1:
|
||||
strcpy(state.cur_event.name, "Setpoint Manual");
|
||||
state.cur_event.name = "Setpoint Manual"s;
|
||||
state.cur_event.value = ptr[6];
|
||||
sample_start(&state);
|
||||
state.cur_sample->setpoint.mbar = ptr[6] * 10;
|
||||
sample_end(&state);
|
||||
break;
|
||||
case 2:
|
||||
strcpy(state.cur_event.name, "Setpoint Auto");
|
||||
state.cur_event.name = "Setpoint Auto"s;
|
||||
state.cur_event.value = ptr[6];
|
||||
sample_start(&state);
|
||||
state.cur_sample->setpoint.mbar = ptr[6] * 10;
|
||||
sample_end(&state);
|
||||
switch (ptr[7]) {
|
||||
case 0:
|
||||
strcat(state.cur_event.name, " Manual");
|
||||
state.cur_event.name += " Manual"s;
|
||||
break;
|
||||
case 1:
|
||||
strcat(state.cur_event.name, " Auto Start");
|
||||
state.cur_event.name += " Auto Start"s;
|
||||
break;
|
||||
case 2:
|
||||
strcat(state.cur_event.name, " Auto Hypox");
|
||||
state.cur_event.name += " Auto Hypox"s;
|
||||
break;
|
||||
case 3:
|
||||
strcat(state.cur_event.name, " Auto Timeout");
|
||||
state.cur_event.name += " Auto Timeout"s;
|
||||
break;
|
||||
case 4:
|
||||
strcat(state.cur_event.name, " Auto Ascent");
|
||||
state.cur_event.name += " Auto Ascent"s;
|
||||
break;
|
||||
case 5:
|
||||
strcat(state.cur_event.name, " Auto Stall");
|
||||
state.cur_event.name += " Auto Stall"s;
|
||||
break;
|
||||
case 6:
|
||||
strcat(state.cur_event.name, " Auto SP Low");
|
||||
state.cur_event.name += " Auto SP Low"s;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -1971,14 +1963,14 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
|
|||
break;
|
||||
case 3:
|
||||
// obsolete
|
||||
strcpy(state.cur_event.name, "OC");
|
||||
state.cur_event.name = "OC"s;
|
||||
break;
|
||||
case 4:
|
||||
// obsolete
|
||||
strcpy(state.cur_event.name, "CCR");
|
||||
state.cur_event.name = "CCR"s;
|
||||
break;
|
||||
case 5:
|
||||
strcpy(state.cur_event.name, "gaschange");
|
||||
state.cur_event.name = "gaschange"s;
|
||||
state.cur_event.type = SAMPLE_EVENT_GASCHANGE2;
|
||||
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;
|
||||
case 6:
|
||||
strcpy(state.cur_event.name, "Start");
|
||||
state.cur_event.name = "Start"s;
|
||||
break;
|
||||
case 7:
|
||||
strcpy(state.cur_event.name, "Too Fast");
|
||||
state.cur_event.name = "Too Fast"s;
|
||||
break;
|
||||
case 8:
|
||||
strcpy(state.cur_event.name, "Above Ceiling");
|
||||
state.cur_event.name = "Above Ceiling"s;
|
||||
break;
|
||||
case 9:
|
||||
strcpy(state.cur_event.name, "Toxic");
|
||||
state.cur_event.name = "Toxic"s;
|
||||
break;
|
||||
case 10:
|
||||
strcpy(state.cur_event.name, "Hypox");
|
||||
state.cur_event.name = "Hypox"s;
|
||||
break;
|
||||
case 11:
|
||||
strcpy(state.cur_event.name, "Critical");
|
||||
state.cur_event.name = "Critical"s;
|
||||
break;
|
||||
case 12:
|
||||
strcpy(state.cur_event.name, "Sensor Disabled");
|
||||
state.cur_event.name = "Sensor Disabled"s;
|
||||
break;
|
||||
case 13:
|
||||
strcpy(state.cur_event.name, "Sensor Enabled");
|
||||
state.cur_event.name = "Sensor Enabled"s;
|
||||
break;
|
||||
case 14:
|
||||
strcpy(state.cur_event.name, "O2 Backup");
|
||||
state.cur_event.name = "O2 Backup"s;
|
||||
break;
|
||||
case 15:
|
||||
strcpy(state.cur_event.name, "Peer Down");
|
||||
state.cur_event.name = "Peer Down"s;
|
||||
break;
|
||||
case 16:
|
||||
strcpy(state.cur_event.name, "HS Down");
|
||||
state.cur_event.name = "HS Down"s;
|
||||
break;
|
||||
case 17:
|
||||
strcpy(state.cur_event.name, "Inconsistent");
|
||||
state.cur_event.name = "Inconsistent"s;
|
||||
break;
|
||||
case 18:
|
||||
// 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;
|
||||
case 19:
|
||||
// obsolete
|
||||
strcpy(state.cur_event.name, "SCR");
|
||||
state.cur_event.name = "SCR"s;
|
||||
break;
|
||||
case 20:
|
||||
strcpy(state.cur_event.name, "Above Stop");
|
||||
state.cur_event.name = "Above Stop"s;
|
||||
break;
|
||||
case 21:
|
||||
strcpy(state.cur_event.name, "Safety Miss");
|
||||
state.cur_event.name = "Safety Miss"s;
|
||||
break;
|
||||
case 22:
|
||||
strcpy(state.cur_event.name, "Fatal");
|
||||
state.cur_event.name = "Fatal"s;
|
||||
break;
|
||||
case 23:
|
||||
strcpy(state.cur_event.name, "gaschange");
|
||||
state.cur_event.name = "gaschange"s;
|
||||
state.cur_event.type = SAMPLE_EVENT_GASCHANGE2;
|
||||
state.cur_event.value = ptr[7] << 8 ^ ptr[6];
|
||||
event_end(&state);
|
||||
break;
|
||||
case 24:
|
||||
strcpy(state.cur_event.name, "gaschange");
|
||||
state.cur_event.name = "gaschange"s;
|
||||
state.cur_event.type = SAMPLE_EVENT_GASCHANGE2;
|
||||
state.cur_event.value = ptr[7] << 8 ^ ptr[6];
|
||||
event_end(&state);
|
||||
// This is both a mode change and a gas change event
|
||||
// so we encode it as two separate events.
|
||||
event_start(&state);
|
||||
strcpy(state.cur_event.name, "Change Mode");
|
||||
state.cur_event.name = "Change Mode"s;
|
||||
switch (ptr[8]) {
|
||||
case 1:
|
||||
strcat(state.cur_event.name, ": OC");
|
||||
state.cur_event.name += ": OC"s;
|
||||
break;
|
||||
case 2:
|
||||
strcat(state.cur_event.name, ": CCR");
|
||||
state.cur_event.name += ": CCR"s;
|
||||
break;
|
||||
case 3:
|
||||
strcat(state.cur_event.name, ": mCCR");
|
||||
state.cur_event.name += ": mCCR"s;
|
||||
break;
|
||||
case 4:
|
||||
strcat(state.cur_event.name, ": Free");
|
||||
state.cur_event.name += ": Free"s;
|
||||
break;
|
||||
case 5:
|
||||
strcat(state.cur_event.name, ": Gauge");
|
||||
state.cur_event.name += ": Gauge"s;
|
||||
break;
|
||||
case 6:
|
||||
strcat(state.cur_event.name, ": ASCR");
|
||||
state.cur_event.name += ": ASCR"s;
|
||||
break;
|
||||
case 7:
|
||||
strcat(state.cur_event.name, ": PSCR");
|
||||
state.cur_event.name += ": PSCR"s;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -2098,22 +2090,22 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
|
|||
case 25:
|
||||
// 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);
|
||||
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;
|
||||
case 26:
|
||||
strcpy(state.cur_event.name, "User mark");
|
||||
state.cur_event.name = "User mark"s;
|
||||
break;
|
||||
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;
|
||||
case 28:
|
||||
strcpy(state.cur_event.name, "Peer Up");
|
||||
state.cur_event.name = "Peer Up"s;
|
||||
break;
|
||||
case 29:
|
||||
strcpy(state.cur_event.name, "HS Up");
|
||||
state.cur_event.name = "HS Up"s;
|
||||
break;
|
||||
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;
|
||||
default:
|
||||
// No values above 30 had any description
|
||||
|
|
|
@ -72,7 +72,7 @@ void event_end(struct parser_state *state)
|
|||
struct divecomputer *dc = get_dc(state);
|
||||
if (state->cur_event.type == 123) {
|
||||
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 */
|
||||
pic.offset.seconds = state->cur_event.time.seconds;
|
||||
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
|
||||
* 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;
|
||||
ev = add_event(dc, state->cur_event.time.seconds,
|
||||
state->cur_event.type, state->cur_event.flags,
|
||||
|
|
|
@ -86,7 +86,7 @@ int get_cylinderid_at_time(struct dive *dive, struct divecomputer *dc, duration_
|
|||
int cylinder_idx = 0;
|
||||
struct event *event = dc->events;
|
||||
while (event && event->time.seconds <= time.seconds) {
|
||||
if (!strcmp(event->name, "gaschange"))
|
||||
if (event->name == "gaschange")
|
||||
cylinder_idx = get_cylinder_index(dive, event);
|
||||
event = event->next;
|
||||
}
|
||||
|
|
|
@ -221,19 +221,19 @@ int get_cylinder_index(const struct dive *dive, const struct event *ev)
|
|||
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;
|
||||
while (event) {
|
||||
if (same_string(event->name, name))
|
||||
if (event->name == name)
|
||||
return event;
|
||||
event = event->next;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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->flags, "flags=", "");
|
||||
|
||||
if (!strcmp(ev->name,"modechange"))
|
||||
if (ev->name == "modechange")
|
||||
show_utf8(b, " divemode=", divemode_text[ev->value], "");
|
||||
else
|
||||
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)) {
|
||||
struct gasmix mix = get_gasmix_from_event(dive, ev);
|
||||
if (ev->gas.index >= 0)
|
||||
|
|
|
@ -91,7 +91,7 @@ static void put_HTML_bookmarks(struct membuffer *b, struct dive *dive)
|
|||
put_string(b, separator);
|
||||
separator = ", ";
|
||||
put_string(b, "{\"name\":\"");
|
||||
put_quoted(b, ev->name, 1, 0);
|
||||
put_quoted(b, ev->name.c_str(), 1, 0);
|
||||
put_string(b, "\",");
|
||||
put_format(b, "\"value\":\"%d\",", ev->value);
|
||||
put_format(b, "\"type\":\"%d\",", ev->type);
|
||||
|
|
|
@ -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));
|
||||
show_index(b, ev->type, "type='", "'");
|
||||
show_index(b, ev->flags, "flags='", "'");
|
||||
if (!strcmp(ev->name,"modechange"))
|
||||
if (ev->name == "modechange")
|
||||
show_utf8(b, divemode_text[ev->value], " divemode='", "'",1);
|
||||
else
|
||||
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)) {
|
||||
struct gasmix mix = get_gasmix_from_event(dive, ev);
|
||||
if (ev->gas.index >= 0)
|
||||
|
|
|
@ -49,9 +49,9 @@ struct event *DiveEventItem::getEventMutable()
|
|||
void DiveEventItem::setupPixmap(struct gasmix lastgasmix, const DivePixmaps &pixmaps)
|
||||
{
|
||||
event_severity severity = get_event_severity(ev);
|
||||
if (empty_string(ev->name)) {
|
||||
if (ev->name.empty()) {
|
||||
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)
|
||||
setPixmap(pixmaps.bailout);
|
||||
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) ||
|
||||
// those are useless internals of the dive computer
|
||||
same_string_caseinsensitive(ev->name, "heading") ||
|
||||
(same_string_caseinsensitive(ev->name, "SP change") && ev->time.seconds == 0)) {
|
||||
same_string_caseinsensitive(ev->name.c_str(), "heading") ||
|
||||
(same_string_caseinsensitive(ev->name.c_str(), "SP change") && ev->time.seconds == 0)) {
|
||||
// 2 cases:
|
||||
// a) some dive computers have heading in every sample
|
||||
// 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);
|
||||
} else if (severity == EVENT_SEVERITY_ALARM) {
|
||||
setPixmap(pixmaps.violation);
|
||||
} else if (same_string_caseinsensitive(ev->name, "violation") || // generic libdivecomputer
|
||||
same_string_caseinsensitive(ev->name, "Safety stop violation") || // the rest are from the Uemis downloader
|
||||
same_string_caseinsensitive(ev->name, "pO₂ ascend alarm") ||
|
||||
same_string_caseinsensitive(ev->name, "RGT alert") ||
|
||||
same_string_caseinsensitive(ev->name, "Dive time alert") ||
|
||||
same_string_caseinsensitive(ev->name, "Low battery alert") ||
|
||||
same_string_caseinsensitive(ev->name, "Speed alarm")) {
|
||||
} else if (same_string_caseinsensitive(ev->name.c_str(), "violation") || // generic libdivecomputer
|
||||
same_string_caseinsensitive(ev->name.c_str(), "Safety stop violation") || // the rest are from the Uemis downloader
|
||||
same_string_caseinsensitive(ev->name.c_str(), "pO₂ ascend alarm") ||
|
||||
same_string_caseinsensitive(ev->name.c_str(), "RGT alert") ||
|
||||
same_string_caseinsensitive(ev->name.c_str(), "Dive time alert") ||
|
||||
same_string_caseinsensitive(ev->name.c_str(), "Low battery alert") ||
|
||||
same_string_caseinsensitive(ev->name.c_str(), "Speed alarm")) {
|
||||
setPixmap(pixmaps.violation);
|
||||
} else if (same_string_caseinsensitive(ev->name, "non stop time") || // generic libdivecomputer
|
||||
same_string_caseinsensitive(ev->name, "safety stop") ||
|
||||
same_string_caseinsensitive(ev->name, "safety stop (voluntary)") ||
|
||||
same_string_caseinsensitive(ev->name, "Tank change suggested") || // Uemis downloader
|
||||
same_string_caseinsensitive(ev->name, "Marker")) {
|
||||
} else if (same_string_caseinsensitive(ev->name.c_str(), "non stop time") || // generic libdivecomputer
|
||||
same_string_caseinsensitive(ev->name.c_str(), "safety stop") ||
|
||||
same_string_caseinsensitive(ev->name.c_str(), "safety stop (voluntary)") ||
|
||||
same_string_caseinsensitive(ev->name.c_str(), "Tank change suggested") || // Uemis downloader
|
||||
same_string_caseinsensitive(ev->name.c_str(), "Marker")) {
|
||||
setPixmap(pixmaps.info);
|
||||
} else {
|
||||
// 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)
|
||||
{
|
||||
// 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 type = ev->type;
|
||||
|
||||
|
@ -147,19 +147,19 @@ void DiveEventItem::setupToolTipString(struct gasmix lastgasmix)
|
|||
qPrintable(tr("ΔN₂")), icd_data.dN2 / 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]));
|
||||
} 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);
|
||||
} 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;
|
||||
double depth_value = get_depth_units(value*1000, NULL, &depth_unit);
|
||||
name += QString(": %1%2").arg((int) round(depth_value)).arg(depth_unit);
|
||||
} else {
|
||||
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
|
||||
// warn of high or low pO₂ and are turning it into a setpoint change event
|
||||
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
|
||||
*/
|
||||
const struct sample *first_sample = &dc->sample[0];
|
||||
if (!strcmp(ev->name, "gaschange") &&
|
||||
if (ev->name == "gaschange" &&
|
||||
(ev->time.seconds == 0 ||
|
||||
(first_sample && ev->time.seconds == first_sample->time.seconds) ||
|
||||
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.
|
||||
* 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;
|
||||
if (time <= 30 || time + 30 >= (int)dc->duration.seconds)
|
||||
return false;
|
||||
|
|
|
@ -556,9 +556,9 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM
|
|||
while (event) {
|
||||
// if print mode is selected only draw headings, SP change, gas events or bookmark event
|
||||
if (printMode) {
|
||||
if (empty_string(event->name) ||
|
||||
!(strcmp(event->name, "heading") == 0 ||
|
||||
(same_string(event->name, "SP change") && event->time.seconds == 0) ||
|
||||
if (event->name.empty() ||
|
||||
!(event->name == "heading" ||
|
||||
(event->name == "SP change" && event->time.seconds == 0) ||
|
||||
event_is_gaschange(event) ||
|
||||
event->type == SAMPLE_EVENT_BOOKMARK)) {
|
||||
event = event->next;
|
||||
|
|
|
@ -697,7 +697,7 @@ void ProfileWidget2::hideEventType(DiveEventItem *item)
|
|||
{
|
||||
const struct event *event = item->getEvent();
|
||||
|
||||
if (!empty_string(event->name)) {
|
||||
if (!event->name.empty()) {
|
||||
hide_event_type(event);
|
||||
|
||||
replot();
|
||||
|
@ -727,7 +727,7 @@ void ProfileWidget2::removeEvent(DiveEventItem *item)
|
|||
|
||||
if (QMessageBox::question(this, TITLE_OR_TEXT(
|
||||
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)
|
||||
Command::removeEvent(mutable_dive(), dc, event);
|
||||
}
|
||||
|
@ -786,7 +786,7 @@ void ProfileWidget2::editName(DiveEventItem *item)
|
|||
bool ok;
|
||||
QString newName = QInputDialog::getText(this, tr("Edit name of bookmark"),
|
||||
tr("Custom name:"), QLineEdit::Normal,
|
||||
event->name, &ok);
|
||||
event->name.c_str(), &ok);
|
||||
if (ok && !newName.isEmpty()) {
|
||||
if (newName.length() > 22) { //longer names will display as garbage.
|
||||
QMessageBox lengthWarning;
|
||||
|
|
Loading…
Reference in a new issue