filter: remove filter_preset_table_t

We used a typedef "filter_preset_table_t" for the filter preset table,
because it is a "std::vector<filter_preset>". However, that is in
contrast to all the other global tables (dives, trips, sites) that we
have.

Therefore, turn this into a standard struct, which simply inherits
from "std::vector<filter_preset>". Note that while inheriting from
std::vector<> is generally not recommended, it is not a problem
here, because we don't modify it in any shape or form.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-10-17 09:58:23 +02:00 committed by Dirk Hohndel
parent 67aec56f8c
commit a7bbb6c1cc
20 changed files with 52 additions and 46 deletions

View file

@ -77,7 +77,7 @@ out:
static void zip_read(struct zip_file *file, const char *filename, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, filter_preset_table_t *filter_presets)
struct dive_site_table *sites, struct filter_preset_table *filter_presets)
{
int size = 1024, n, read = 0;
char *mem = malloc(size);
@ -93,7 +93,7 @@ static void zip_read(struct zip_file *file, const char *filename, struct dive_ta
}
int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
filter_preset_table_t *filter_presets)
struct filter_preset_table *filter_presets)
{
int success = 0;
/* Grr. libzip needs to re-open the file, it can't take a buffer */
@ -227,7 +227,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div
*/
static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
filter_preset_table_t *filter_presets)
struct filter_preset_table *filter_presets)
{
// hack to be able to provide a comment for the translated string
static char *csv_warning = QT_TRANSLATE_NOOP3("gettextFromC",
@ -258,7 +258,7 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
}
static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table,
struct trip_table *trips, struct dive_site_table *sites, filter_preset_table_t *filter_presets)
struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets)
{
int ret;
char *fmt = strrchr(filename, '.');
@ -305,7 +305,7 @@ int check_git_sha(const char *filename, struct git_repository **git_p, const cha
return 1;
}
int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, filter_preset_table_t *filter_presets)
int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets)
{
struct git_repository *git;
const char *branch = NULL;

View file

@ -26,8 +26,8 @@ extern int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct
extern void ostctools_import(const char *file, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
extern int readfile(const char *filename, struct memblock *mem);
extern int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, filter_preset_table_t *filter_presets);
extern int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, filter_preset_table_t *filter_presets);
extern int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets);
extern int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets);
// Platform specific functions
extern int subsurface_rename(const char *path, const char *newpath);

View file

@ -3,7 +3,7 @@
#include "qthelper.h"
#include "subsurface-string.h"
std::vector<filter_preset> filter_preset_table;
struct filter_preset_table filter_preset_table;
extern "C" void clear_filter_presets(void)
{
@ -74,7 +74,7 @@ extern "C" void filter_preset_set_name(struct filter_preset *preset, const char
preset->name = name;
}
static int filter_preset_add_to_table(const QString &name, const FilterData &d, filter_preset_table_t &table)
static int filter_preset_add_to_table(const QString &name, const FilterData &d, struct filter_preset_table &table)
{
// std::lower_bound does a binary search - the vector must be sorted.
filter_preset newEntry { name, d };
@ -86,7 +86,7 @@ static int filter_preset_add_to_table(const QString &name, const FilterData &d,
}
// Take care that the name doesn't already exist by adding numbers
static QString get_unique_preset_name(const QString &orig, const filter_preset_table_t &table)
static QString get_unique_preset_name(const QString &orig, const struct filter_preset_table &table)
{
QString res = orig;
int count = 2;
@ -99,7 +99,7 @@ static QString get_unique_preset_name(const QString &orig, const filter_preset_t
return res;
}
extern "C" void add_filter_preset_to_table(const struct filter_preset *preset, filter_preset_table_t *table)
extern "C" void add_filter_preset_to_table(const struct filter_preset *preset, struct filter_preset_table *table)
{
QString name = get_unique_preset_name(preset->name, *table);
filter_preset_add_to_table(name, preset->data, *table);

View file

@ -24,12 +24,18 @@ struct filter_preset {
FilterData data;
};
using filter_preset_table_t = std::vector<filter_preset>;
extern filter_preset_table_t filter_preset_table;
// Subclassing standard library containers is generally
// not recommended. However, this makes interaction with
// C-code easier and since we don't add any member functions,
// this is not a problem.
struct filter_preset_table : public std::vector<filter_preset>
{
};
extern struct filter_preset_table filter_preset_table;
#else
struct filter_preset;
struct filter_preset_table;
typedef struct filter_preset_table filter_preset_table_t;
#endif
@ -49,7 +55,7 @@ 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, filter_preset_table_t *table);
extern void add_filter_preset_to_table(const struct filter_preset *preset, struct filter_preset_table *table);
extern void filter_preset_add_constraint(struct filter_preset *preset, const char *type, const char *string_mode,
const char *range_mode, bool negate, const char *data); // called by the parser, therefore data passed as strings.

View file

@ -21,7 +21,7 @@ extern int check_git_sha(const char *filename, git_repository **git_p, const cha
extern int sync_with_remote(struct git_repository *repo, const char *remote, const char *branch, enum remote_transport rt);
extern int git_save_dives(struct git_repository *, const char *, const char *remote, bool select_only);
extern int git_load_dives(struct git_repository *repo, const char *branch, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, filter_preset_table_t *filter_presets);
struct dive_site_table *sites, struct filter_preset_table *filter_presets);
extern const char *get_sha(git_repository *repo, const char *branch);
extern int do_git_save(git_repository *repo, const char *branch, const char *remote, bool select_only, bool create_empty);
extern const char *saved_git_id;

View file

@ -105,7 +105,7 @@ static char *parse_dan_new_line(char *buf, const char *NL)
static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, const char *tag);
static int parse_dan_format(const char *filename, char **params, int pnr, struct dive_table *table,
struct trip_table *trips, struct dive_site_table *sites,
filter_preset_table_t *filter_presets)
struct filter_preset_table *filter_presets)
{
int ret = 0, i;
size_t end_ptr = 0;
@ -286,7 +286,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr, struct
int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
filter_preset_table_t *filter_presets)
struct filter_preset_table *filter_presets)
{
int ret, i;
struct memblock mem;
@ -808,8 +808,8 @@ int parse_txt_file(const char *filename, const char *csv, struct dive_table *tab
#define SBPARAMS 40
static int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, filter_preset_table_t *filter_presets);
int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, filter_preset_table_t *filter_presets)
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets);
int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets)
{
char *params[SBPARAMS];
int pnr = 0;
@ -826,7 +826,7 @@ int parse_seabear_log(const char *filename, struct dive_table *table, struct tri
static int parse_seabear_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
filter_preset_table_t *filter_presets)
struct filter_preset_table *filter_presets)
{
int ret, i;
struct memblock mem;
@ -954,7 +954,7 @@ static int parse_seabear_csv_file(const char *filename, char **params, int pnr,
}
int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, filter_preset_table_t *filter_presets)
struct dive_site_table *sites, struct filter_preset_table *filter_presets)
{
struct memblock mem;
time_t now;

View file

@ -24,14 +24,14 @@ extern "C" {
#endif
int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate, struct dive_table *table,
struct trip_table *trips, struct dive_site_table *sites, filter_preset_table_t *filter_presets);
struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets);
int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
filter_preset_table_t *filter_presets);
struct filter_preset_table *filter_presets);
int parse_manual_file(const char *filename, char **params, int pnr, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, filter_preset_table_t *filter_presets);
struct dive_site_table *sites, struct filter_preset_table *filter_presets);
#ifdef __cplusplus
}

View file

@ -47,7 +47,7 @@ struct git_parser_state {
struct dive_table *table;
struct trip_table *trips;
struct dive_site_table *sites;
filter_preset_table_t *filter_presets;
struct filter_preset_table *filter_presets;
int o2pressure_sensor;
};
@ -1879,7 +1879,7 @@ const char *get_sha(git_repository *repo, const char *branch)
* or report an error and return 1 if the load failed.
*/
int git_load_dives(struct git_repository *repo, const char *branch, struct dive_table *table, struct trip_table *trips,
struct dive_site_table *sites, filter_preset_table_t *filter_presets)
struct dive_site_table *sites, struct filter_preset_table *filter_presets)
{
int ret;
struct git_parser_state state = { 0 };

View file

@ -1721,7 +1721,7 @@ static const char *preprocess_divelog_de(const char *buffer)
int parse_xml_buffer(const char *url, const char *buffer, int size,
struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
filter_preset_table_t *filter_presets, const char **params)
struct filter_preset_table *filter_presets, const char **params)
{
UNUSED(size);
xmlDoc *doc;

View file

@ -73,10 +73,10 @@ struct parser_state {
int sample_rate;
struct extra_data cur_extra_data;
struct units xml_parsing_units;
struct dive_table *target_table; /* non-owning */
struct trip_table *trips; /* non-owning */
struct dive_site_table *sites; /* non-owning */
filter_preset_table_t *filter_presets; /* non-owning */
struct dive_table *target_table; /* non-owning */
struct trip_table *trips; /* non-owning */
struct dive_site_table *sites; /* non-owning */
struct filter_preset_table *filter_presets; /* non-owning */
sqlite3 *sql_handle; /* for SQL based parsers */
event_allocation_t event_allocation;
@ -140,7 +140,7 @@ int atoi_n(char *ptr, unsigned int len);
void parse_xml_init(void);
int parse_xml_buffer(const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
filter_preset_table_t *filter_presets, const char **params);
struct filter_preset_table *filter_presets, const char **params);
void parse_xml_exit(void);
int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);