mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Mostly NFC; this commit is mainly to get familiar with the codebase and to meet the people who will review these changes. I hope to make some changes to the DAN parsing code to eventually extract more metainfo from my aqualung divecomputer's `.zxu` formatted logs. To do so, and for me to be able to work on this efficiently, I've refactored the DAN parsing code using a bit more modern C++-style, as well as being more true-to-spec wrt. the (...ancient) DAN file format documentation that i could dig up... hopefully that's an alright tradeoff for the project. This more true-to-spec parsing also fixed a bug with the number being parsed from the incorrect index in the ZDH vector (or, atleast i consider it a bug - the "Export sequence" number was being used as the dive number, instead of the "Internal Dive Sequence" number. The latter, described in the spec as: `The sequence number assigned to the dive by the recording computer`). Also contains some unrelated formatting changes; i tried to keep these minimal (i presume these files haven't been touched in a while by `clang-format`). Signed-off-by: Morten Borup Petersen <morten_bp@live.dk>
67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#include "xmlparams.h"
|
|
|
|
struct xml_params *alloc_xml_params()
|
|
{
|
|
return new xml_params;
|
|
}
|
|
|
|
void free_xml_params(struct xml_params *params)
|
|
{
|
|
delete params;
|
|
}
|
|
|
|
void xml_params_resize(struct xml_params *params, int count)
|
|
{
|
|
params->items.resize(count);
|
|
}
|
|
|
|
void xml_params_add(struct xml_params *params, const char *key, const char *value)
|
|
{
|
|
xml_params_add(params, std::string(key), std::string(value));
|
|
}
|
|
|
|
void xml_params_add(struct xml_params *params, const std::string &key, const std::string &value)
|
|
{
|
|
params->items.push_back({key, value});
|
|
}
|
|
|
|
void xml_params_add_int(struct xml_params *params, const char *key, int value)
|
|
{
|
|
params->items.push_back({std::string(key), std::to_string(value)});
|
|
}
|
|
|
|
int xml_params_count(const struct xml_params *params)
|
|
{
|
|
return (int)params->items.size();
|
|
}
|
|
|
|
const char *xml_params_get_key(const struct xml_params *params, int idx)
|
|
{
|
|
return params->items[idx].first.c_str();
|
|
}
|
|
|
|
const char *xml_params_get_value(const struct xml_params *params, int idx)
|
|
{
|
|
return params->items[idx].second.c_str();
|
|
}
|
|
|
|
extern void xml_params_set_value(struct xml_params *params, int idx, const char *value)
|
|
{
|
|
if (idx < 0 || idx >= (int)params->items.size())
|
|
return;
|
|
params->items[idx].second = value;
|
|
}
|
|
|
|
const char **xml_params_get(const struct xml_params *params)
|
|
{
|
|
if (!params)
|
|
return nullptr;
|
|
params->data.resize(params->items.size() * 2 + 1);
|
|
for (size_t i = 0; i < params->items.size(); ++i) {
|
|
params->data[i * 2] = params->items[i].first.c_str();
|
|
params->data[i * 2 + 1] = params->items[i].second.c_str();
|
|
}
|
|
params->data[params->items.size() * 2] = nullptr;
|
|
return params->data.data();
|
|
}
|