core: convert parser_state to C++

Add constructor, destructor and use std::string for memory
management of text data.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-02-29 07:56:27 +01:00 committed by Michael Keller
parent 5e466d91f0
commit 8d96b7557d
8 changed files with 179 additions and 227 deletions

View file

@ -262,7 +262,7 @@ static int shearwater_dive(void *param, int, char **data, char **)
settings_start(state);
dc_settings_start(state);
if (data[9])
utf8_string(data[9], &state->cur_settings.dc.serial_nr);
utf8_string_std(data[9], &state->cur_settings.dc.serial_nr);
if (data[10]) {
switch (atoi(data[10])) {
case 2:
@ -392,7 +392,7 @@ static int shearwater_cloud_dive(void *param, int, char **data, char **)
settings_start(state);
dc_settings_start(state);
if (data[9])
utf8_string(data[9], &state->cur_settings.dc.serial_nr);
utf8_string_std(data[9], &state->cur_settings.dc.serial_nr);
if (data[10]) {
switch (atoi(data[10])) {
case 2:
@ -477,7 +477,6 @@ extern "C" int parse_shearwater_buffer(sqlite3 *handle, const char *url, const c
int retval;
struct parser_state state;
init_parser_state(&state);
state.log = log;
state.sql_handle = handle;
@ -487,7 +486,6 @@ extern "C" int parse_shearwater_buffer(sqlite3 *handle, const char *url, const c
char get_dives[] = "select l.number,timestamp,location||' / '||site,buddy,notes,imperialUnits,maxDepth,maxTime,startSurfacePressure,computerSerial,computerModel,i.diveId FROM dive_info AS i JOIN dive_logs AS l ON i.diveId=l.diveId";
retval = sqlite3_exec(handle, get_dives, &shearwater_dive, &state, NULL);
free_parser_state(&state);
if (retval != SQLITE_OK) {
fprintf(stderr, "Database query failed '%s'.\n", url);
@ -502,14 +500,12 @@ extern "C" int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, c
int retval;
struct parser_state state;
init_parser_state(&state);
state.log = log;
state.sql_handle = handle;
char get_dives[] = "select l.number,strftime('%s', DiveDate),location||' / '||site,buddy,notes,imperialUnits,maxDepth,DiveLengthTime,startSurfacePressure,computerSerial,computerModel,d.diveId,l.sampleRateMs / 1000 FROM dive_details AS d JOIN dive_logs AS l ON d.diveId=l.diveId";
retval = sqlite3_exec(handle, get_dives, &shearwater_cloud_dive, &state, NULL);
free_parser_state(&state);
if (retval != SQLITE_OK) {
fprintf(stderr, "Database query failed '%s'.\n", url);