summary refs log tree commit diff stats
path: root/lib/filter.h
blob: a12a822f5b874b0d2bf80115620a0507c27fba4e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#ifndef FILTER_H_932BA9C6
#define FILTER_H_932BA9C6

#include <list>
#include <string>
#include <memory>
#include "field.h"
#include "enums.h"

namespace verbly {

  class filter {
  public:
    enum class type {
      empty,
      singleton,
      group
    };

    enum class comparison {
      int_equals,
      int_does_not_equal,
      int_is_at_least,
      int_is_greater_than,
      int_is_at_most,
      int_is_less_than,
      boolean_equals,
      string_equals,
      string_does_not_equal,
      string_is_like,
      string_is_not_like,
      is_null,
      is_not_null,
      matches,
      does_not_match,
      hierarchally_matches,
      does_not_hierarchally_match,
      field_equals,
      field_does_not_equal
    };

    // Copy and move constructors

    filter(const filter& other);
    filter(filter&& other);

    // Assignment

    filter& operator=(filter other);

    // Swap

    friend void swap(filter& first, filter& second);

    // Destructor

    ~filter();

    // Accessors

    type getType() const
    {
      return type_;
    }

    // Empty

    filter();

    // Singleton

    filter(field filterField, comparison filterType, int filterValue);
    filter(field filterField, comparison filterType, std::string filterValue);
    filter(field filterField, comparison filterType, bool filterValue);
    filter(field filterField, comparison filterType);
    filter(field joinOn, comparison filterType, filter joinCondition);
    filter(field filterField, comparison filterType, field compareField);

    field getField() const;

    comparison getComparison() const;

    filter getJoinCondition() const;

    std::string getStringArgument() const;

    int getIntegerArgument() const;

    bool getBooleanArgument() const;

    field getCompareField() const;

    // Group

    explicit filter(bool orlogic);

    bool getOrlogic() const;

    filter operator+(filter condition) const;

    filter& operator+=(filter condition);

    using const_iterator = std::list<filter>::const_iterator;

    const_iterator begin() const;

    const_iterator end() const;

    // Negation

    filter operator!() const;

    // Groupifying

    filter operator&&(filter condition) const;
    filter operator||(filter condition) const;

    filter& operator&=(filter condition);
    filter& operator|=(filter condition);

    // Utility

    filter normalize(object context) const;

    filter compact() const;

  private:
    union {
      struct {
        field filterField;
        comparison filterType;
        union {
          std::unique_ptr<filter> join;
          std::string stringValue;
          int intValue;
          bool boolValue;
          field compareField;
        };
      } singleton_;
      struct {
        std::list<filter> children;
        bool orlogic;
      } group_;
    };
    type type_ = type::empty;

  };

};

#endif /* end of include guard: FILTER_H_932BA9C6 */