@@ -40,6 +40,9 @@ namespace sqlite_reflection {
4040 // / Returns a textual representation of the predicate, ready to be consumed by the SELECT query
4141 virtual std::string Evaluate () const = 0;
4242
43+ // / Creates a clone for compounding predicates
44+ virtual QueryPredicateBase* Clone () const = 0;
45+
4346 // / Returns a compound predicate, which requires that both the current
4447 // / and the other predicate are valid at the same time
4548 AndPredicate And (const QueryPredicateBase& other) const ;
@@ -56,11 +59,13 @@ namespace sqlite_reflection {
5659 {
5760 public:
5861 std::string Evaluate () const override ;
62+ QueryPredicateBase* Clone () const override ;
5963
6064 protected:
6165 template <typename T, typename R>
62- QueryPredicate (R T::* fn, R value, const std::string& symbol, std::function<std::string(void *, SqliteStorageClass)> value_retrieval) {
63- symbol_ = symbol;
66+ QueryPredicate (R T::* fn, R value, const std::string& symbol, std::function<std::string(void *, SqliteStorageClass)> value_retrieval)
67+ : symbol_(symbol)
68+ {
6469 auto record = GetRecordFromTypeId (typeid (T).name ());
6570 auto offset = OffsetFromStart (fn);
6671 for (auto i = 0 ; i < record.member_metadata .size (); ++i) {
@@ -78,6 +83,9 @@ namespace sqlite_reflection {
7883 return GetStringForValue (v, storage_class);
7984 }) {}
8085
86+ QueryPredicate (const std::string& symbol, const std::string& member_name, const std::string& value)
87+ : symbol_(symbol), member_name_(member_name), value_(value) {}
88+
8189 // / Returns a textual representation of the value used for the current query, against which the
8290 // / struct member (defined from the pointer-to-member function) will be compared. The value needs
8391 // / to be type-erased, so that the header file is not bloated with unnecessary implementation details
@@ -100,6 +108,7 @@ namespace sqlite_reflection {
100108 {
101109 public:
102110 std::string Evaluate () const override ;
111+ QueryPredicateBase* Clone () const override ;
103112 };
104113
105114 // / A wrapper for an equality predicate, for which the value of the
@@ -204,8 +213,8 @@ namespace sqlite_reflection {
204213 protected:
205214 BinaryPredicate (const QueryPredicateBase& left, const QueryPredicateBase& right, const std::string& symbol);
206215
207- const QueryPredicateBase* left_;
208- const QueryPredicateBase* right_;
216+ std::unique_ptr< QueryPredicateBase> left_;
217+ std::unique_ptr< QueryPredicateBase> right_;
209218 std::string symbol_;
210219 };
211220
@@ -214,12 +223,14 @@ namespace sqlite_reflection {
214223 {
215224 public:
216225 AndPredicate (const QueryPredicateBase& left, const QueryPredicateBase& right);
226+ QueryPredicateBase* Clone () const override ;
217227 };
218228
219229 // / A compound predicate, which requires that either predicate is valid
220230 class REFLECTION_EXPORT OrPredicate final : public BinaryPredicate
221231 {
222232 public:
223233 OrPredicate (const QueryPredicateBase& left, const QueryPredicateBase& right);
234+ QueryPredicateBase* Clone () const override ;
224235 };
225236}
0 commit comments