core: remove alloc_filter_preset() and free_filter_preset()

All users of that are now C++ and don't need these helpers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-03-01 22:44:45 +01:00
parent c9a10733d3
commit 37994740ce
6 changed files with 15 additions and 29 deletions

View file

@ -53,16 +53,6 @@ extern "C" const filter_constraint *filter_preset_constraint(int preset, int con
return &global_table()[preset].data.constraints[constraint];
}
extern "C" struct filter_preset *alloc_filter_preset()
{
return new filter_preset;
}
extern "C" void free_filter_preset(const struct filter_preset *preset)
{
delete preset;
}
extern "C" void filter_preset_set_name(struct filter_preset *preset, const char *name)
{
preset->name = name;

View file

@ -47,8 +47,6 @@ extern int filter_presets_count(void);
extern const char *filter_preset_fulltext_mode(int preset); // string mode of fulltext query. ownership is *not* passed to caller.
extern int filter_preset_constraint_count(int preset); // number of constraints in the filter preset.
extern const struct filter_constraint *filter_preset_constraint(int preset, int constraint); // get constraint. ownership is *not* passed to caller.
extern struct filter_preset *alloc_filter_preset();
extern void free_filter_preset(const struct filter_preset *preset);
extern void filter_preset_set_name(struct filter_preset *preset, const char *name);
extern void filter_preset_set_fulltext(struct filter_preset *preset, const char *fulltext, const char *fulltext_string_mode);
extern void add_filter_preset_to_table(const struct filter_preset *preset, struct filter_preset_table *table);

View file

@ -50,7 +50,7 @@ struct git_parser_state {
std::string filter_constraint_data;
struct picture active_pic = { 0 };
struct dive_site *active_site = nullptr;
struct filter_preset *active_filter = nullptr;
std::unique_ptr<filter_preset> active_filter;
struct divelog *log = nullptr;
int o2pressure_sensor = 0;
};
@ -1190,7 +1190,7 @@ static void parse_filter_preset_constraint(char *line, struct membuffer *str, st
line = parse_keyvalue_entry(parse_filter_preset_constraint_keyvalue, state, line, str);
}
filter_preset_add_constraint(state->active_filter, state->filter_constraint_type.c_str(),
filter_preset_add_constraint(state->active_filter.get(), state->filter_constraint_type.c_str(),
state->filter_constraint_string_mode.c_str(),
state->filter_constraint_range_mode.c_str(),
state->filter_constraint_negate, state->filter_constraint_data.c_str());
@ -1227,14 +1227,14 @@ static void parse_filter_preset_fulltext(char *line, struct membuffer *str, stru
line = parse_keyvalue_entry(parse_filter_preset_fulltext_keyvalue, state, line, str);
}
filter_preset_set_fulltext(state->active_filter, state->fulltext_query.c_str(), state->fulltext_mode.c_str());
filter_preset_set_fulltext(state->active_filter.get(), state->fulltext_query.c_str(), state->fulltext_mode.c_str());
state->fulltext_mode.clear();
state->fulltext_query.clear();
}
static void parse_filter_preset_name(char *, struct membuffer *str, struct git_parser_state *state)
{
filter_preset_set_name(state->active_filter, detach_cstring(str));
filter_preset_set_name(state->active_filter.get(), detach_cstring(str));
}
/* These need to be sorted! */
@ -1792,14 +1792,13 @@ static int parse_filter_preset(struct git_parser_state *state, const git_tree_en
if (!blob)
return report_error("Unable to read filter preset file");
state->active_filter = alloc_filter_preset();
state->active_filter = std::make_unique<filter_preset>();
for_each_line(blob, filter_preset_parser, state);
git_blob_free(blob);
add_filter_preset_to_table(state->active_filter, state->log->filter_presets);
free_filter_preset(state->active_filter);
state->active_filter = NULL;
add_filter_preset_to_table(state->active_filter.get(), state->log->filter_presets);
state->active_filter.reset();
return 0;
}

View file

@ -1527,7 +1527,7 @@ static bool entry(const char *name, char *buf, struct parser_state *state)
return true;
}
if (state->cur_filter) {
try_to_fill_filter(state->cur_filter, name, buf);
try_to_fill_filter(state->cur_filter.get(), name, buf);
return true;
}
if (state->event_active) {

View file

@ -24,7 +24,6 @@ parser_state::~parser_state()
free_dive(cur_dive);
free_trip(cur_trip);
free_dive_site(cur_dive_site);
free_filter_preset(cur_filter);
free((void *)cur_extra_data.key);
free((void *)cur_extra_data.value);
}
@ -213,14 +212,13 @@ void filter_preset_start(struct parser_state *state)
{
if (state->cur_filter)
return;
state->cur_filter = alloc_filter_preset();
state->cur_filter = std::make_unique<filter_preset>();
}
void filter_preset_end(struct parser_state *state)
{
add_filter_preset_to_table(state->cur_filter, state->log->filter_presets);
free_filter_preset(state->cur_filter);
state->cur_filter = NULL;
add_filter_preset_to_table(state->cur_filter.get(), state->log->filter_presets);
state->cur_filter.reset();
}
void fulltext_start(struct parser_state *state)
@ -234,7 +232,7 @@ void fulltext_end(struct parser_state *state)
{
if (!state->in_fulltext)
return;
filter_preset_set_fulltext(state->cur_filter, state->fulltext.c_str(), state->fulltext_string_mode.c_str());
filter_preset_set_fulltext(state->cur_filter.get(), state->fulltext.c_str(), state->fulltext_string_mode.c_str());
state->fulltext.clear();
state->fulltext_string_mode.clear();
state->in_fulltext = false;
@ -251,7 +249,7 @@ void filter_constraint_end(struct parser_state *state)
{
if (!state->in_filter_constraint)
return;
filter_preset_add_constraint(state->cur_filter, state->filter_constraint_type.c_str(), state->filter_constraint_string_mode.c_str(),
filter_preset_add_constraint(state->cur_filter.get(), state->filter_constraint_type.c_str(), state->filter_constraint_string_mode.c_str(),
state->filter_constraint_range_mode.c_str(), state->filter_constraint_negate, state->filter_constraint.c_str());
state->filter_constraint_type.clear();

View file

@ -10,6 +10,7 @@
#include "filterpreset.h"
#include "picture.h"
#include <memory>
#include <sqlite3.h>
#include <time.h>
@ -68,7 +69,7 @@ struct parser_state {
struct dive_trip *cur_trip = nullptr; /* owning */
struct sample *cur_sample = nullptr; /* non-owning */
struct picture cur_picture { 0 }; /* owning */
struct filter_preset *cur_filter = nullptr; /* owning */
std::unique_ptr<filter_preset> cur_filter; /* owning */
std::string fulltext; /* owning */
std::string fulltext_string_mode; /* owning */
std::string filter_constraint_type; /* owning */