core: move dive-site-table functions into class

There were a number of free standing functions acting on a
dive-site-table. Make them member functions. This allows
for shorter names. Use the get_idx() function of the base
class, which returns a size_t instead of an int (since that
is what the standard, somewhat unfortunately, uses).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-11 14:22:33 +02:00 committed by bstoeger
parent 6b835710bc
commit 76c52c87a3
19 changed files with 87 additions and 99 deletions

View file

@ -175,9 +175,9 @@ static void parse_dive_gps(char *line, struct git_parser_state *state)
parse_location(line, &location);
if (!ds) {
ds = get_dive_site_by_gps(&location, *state->log->sites);
ds = state->log->sites->get_by_gps(&location);
if (!ds)
ds = create_dive_site_with_gps(std::string(), &location, *state->log->sites);
ds = state->log->sites->create(std::string(), &location);
add_dive_to_dive_site(state->active_dive, ds);
} else {
if (dive_site_has_gps_location(ds) && ds->location != location) {
@ -221,9 +221,9 @@ static void parse_dive_location(char *, struct git_parser_state *state)
std::string name = get_first_converted_string(state);
struct dive_site *ds = get_dive_site_for_dive(state->active_dive);
if (!ds) {
ds = get_dive_site_by_name(name, *state->log->sites);
ds = state->log->sites->get_by_name(name);
if (!ds)
ds = create_dive_site(name, *state->log->sites);
ds = state->log->sites->create(name);
add_dive_to_dive_site(state->active_dive, ds);
} else {
// we already had a dive site linked to the dive
@ -252,7 +252,7 @@ static void parse_dive_notes(char *, struct git_parser_state *state)
{ state->active_dive->notes = get_first_converted_string_c(state); }
static void parse_dive_divesiteid(char *line, struct git_parser_state *state)
{ add_dive_to_dive_site(state->active_dive, get_dive_site_by_uuid(get_hex(line), *state->log->sites)); }
{ add_dive_to_dive_site(state->active_dive, state->log->sites->get_by_uuid(get_hex(line))); }
/*
* We can have multiple tags.
@ -1711,7 +1711,7 @@ static int parse_site_entry(struct git_parser_state *state, const git_tree_entry
if (*suffix == '\0')
return report_error("Dive site without uuid");
uint32_t uuid = strtoul(suffix, NULL, 16);
state->active_site = alloc_or_get_dive_site(uuid, *state->log->sites);
state->active_site = state->log->sites->alloc_or_get(uuid);
git_blob *blob = git_tree_entry_blob(state->repo, entry);
if (!blob)
return report_error("Unable to read dive site file");