fulltext: replace plain pointer by std::unique_ptr<>

This was a plain pointer owing to C compatibility.

Replacing it by a unique_ptr<> allows us to make it
'self-desctruct' in the constructor. However, we do this
with a special twist: the data is _not_ copied when copying
the dive, since the copied dive is not registered in the fulltext
system. Hackish, but it should(!) work.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-03 19:09:43 +02:00 committed by bstoeger
parent 5c7cfb1057
commit c9d4ce0c15
4 changed files with 25 additions and 26 deletions

View file

@ -5,11 +5,6 @@
// issues such as COW semantics and UTF-16 encoding, it provides
// platform independence and reasonable performance. Therefore,
// this is based in QString instead of std::string.
//
// To make this accessible from C, this does manual memory management:
// Every dive is associated with a cache of words. Thus, when deleting
// a dive, a function freeing that data has to be called.
// TODO: remove this complexity.
#ifndef FULLTEXT_H
#define FULLTEXT_H
@ -17,7 +12,6 @@
#include <QString>
#include <vector>
struct full_text_cache;
struct dive;
void fulltext_register(struct dive *d); // Note: can be called repeatedly
void fulltext_unregister(struct dive *d); // Note: can be called repeatedly
@ -30,6 +24,11 @@ enum class StringFilterMode {
EXACT = 2
};
// This class caches each dives words, so that we can unregister a dive from the full text search
struct full_text_cache {
std::vector<QString> words;
};
// A fulltext query. Basically a list of normalized words we search for
struct FullTextQuery {
std::vector<QString> words;