ledger-core
QueryFilter.h
1 /*
2  *
3  * QueryFilter
4  * ledger-core
5  *
6  * Created by Pierre Pollastri on 28/06/2017.
7  *
8  * The MIT License (MIT)
9  *
10  * Copyright (c) 2016 Ledger
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy
13  * of this software and associated documentation files (the "Software"), to deal
14  * in the Software without restriction, including without limitation the rights
15  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16  * copies of the Software, and to permit persons to whom the Software is
17  * furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included in all
20  * copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28  * SOFTWARE.
29  *
30  */
31 #ifndef LEDGER_CORE_QUERYFILTER_H
32 #define LEDGER_CORE_QUERYFILTER_H
33 
34 #include <api/QueryFilter.hpp>
35 #include <soci.h>
36 
37 namespace ledger {
38  namespace core {
39 
40  enum class QueryFilterOperator {
41  OP_AND, OP_OR, OP_AND_NOT, OP_OR_NOT
42  };
43 
44  class QueryFilter;
45  struct QueryFilterLink {
46  std::shared_ptr<QueryFilter> previous;
47  std::shared_ptr<QueryFilter> next;
48  QueryFilterOperator op;
49  };
50 
51  class QueryFilter : public api::QueryFilter, public std::enable_shared_from_this<QueryFilter> {
52  public:
53  std::shared_ptr<api::QueryFilter> op_and(const std::shared_ptr<api::QueryFilter> &filter) override;
54  std::shared_ptr<api::QueryFilter> op_or(const std::shared_ptr<api::QueryFilter> &filter) override;
55  std::shared_ptr<api::QueryFilter> op_and_not(const std::shared_ptr<api::QueryFilter> &filter) override;
56  std::shared_ptr<api::QueryFilter> op_or_not(const std::shared_ptr<api::QueryFilter> &filter) override;
57 
58  virtual std::string toString() const {
59  std::stringstream ss;
60  toString(ss);
61  return ss.str();
62  };
63  virtual void toString(std::stringstream& ss) const = 0;
64  virtual void bindValue(soci::details::prepare_temp_type& statement) const = 0;
65  int32_t getSiblingsCount() const;
66  std::shared_ptr<QueryFilter> getHead() const;
67  std::shared_ptr<QueryFilter> getTail() const;
68  bool isTail() const;
69  bool isHead() const;
70 
71  std::shared_ptr<QueryFilter> getNext() const;
72  std::shared_ptr<QueryFilter> getPrevious() const;
73  QueryFilterOperator getOperatorForNextFilter() const;
74 
75  private:
76  std::shared_ptr<api::QueryFilter> link(const std::shared_ptr<api::QueryFilter> &filter, QueryFilterOperator op);
77 
78  private:
79  QueryFilterLink _siblings;
80  };
81  }
82 }
83 
84 
85 #endif //LEDGER_CORE_QUERYFILTER_H
Definition: QueryFilter.hpp:26
Definition: QueryFilter.h:51
Definition: Account.cpp:8