From 92a1a08b21f862a80784237c00de676e046c456c Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 1 Mar 2024 22:44:45 +0100 Subject: [PATCH] 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 --- core/filterpreset.cpp | 10 ---------- core/filterpreset.h | 2 -- core/load-git.cpp | 15 +++++++-------- core/parse-xml.cpp | 2 +- core/parse.cpp | 12 +++++------- core/parse.h | 3 ++- 6 files changed, 15 insertions(+), 29 deletions(-) diff --git a/core/filterpreset.cpp b/core/filterpreset.cpp index 40bd72cfa..fa07f5879 100644 --- a/core/filterpreset.cpp +++ b/core/filterpreset.cpp @@ -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; diff --git a/core/filterpreset.h b/core/filterpreset.h index 059934b88..c15a88fdf 100644 --- a/core/filterpreset.h +++ b/core/filterpreset.h @@ -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); diff --git a/core/load-git.cpp b/core/load-git.cpp index 092111b3d..03098a549 100644 --- a/core/load-git.cpp +++ b/core/load-git.cpp @@ -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 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(); 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; } diff --git a/core/parse-xml.cpp b/core/parse-xml.cpp index d516ab5ec..447f4cee7 100644 --- a/core/parse-xml.cpp +++ b/core/parse-xml.cpp @@ -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) { diff --git a/core/parse.cpp b/core/parse.cpp index ee5150c18..89b07c911 100644 --- a/core/parse.cpp +++ b/core/parse.cpp @@ -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(); } 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(); diff --git a/core/parse.h b/core/parse.h index d8da4ace8..661ad196e 100644 --- a/core/parse.h +++ b/core/parse.h @@ -10,6 +10,7 @@ #include "filterpreset.h" #include "picture.h" +#include #include #include @@ -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 cur_filter; /* owning */ std::string fulltext; /* owning */ std::string fulltext_string_mode; /* owning */ std::string filter_constraint_type; /* owning */