diff options
Diffstat (limited to 'lib/filter.h')
| -rw-r--r-- | lib/filter.h | 143 |
1 files changed, 143 insertions, 0 deletions
| diff --git a/lib/filter.h b/lib/filter.h new file mode 100644 index 0000000..d213d7a --- /dev/null +++ b/lib/filter.h | |||
| @@ -0,0 +1,143 @@ | |||
| 1 | #ifndef FILTER_H_932BA9C6 | ||
| 2 | #define FILTER_H_932BA9C6 | ||
| 3 | |||
| 4 | #include <list> | ||
| 5 | #include <string> | ||
| 6 | #include <memory> | ||
| 7 | #include "field.h" | ||
| 8 | #include "enums.h" | ||
| 9 | |||
| 10 | namespace verbly { | ||
| 11 | |||
| 12 | class filter { | ||
| 13 | public: | ||
| 14 | enum class type { | ||
| 15 | empty, | ||
| 16 | singleton, | ||
| 17 | group | ||
| 18 | }; | ||
| 19 | |||
| 20 | enum class comparison { | ||
| 21 | int_equals, | ||
| 22 | int_does_not_equal, | ||
| 23 | int_is_at_least, | ||
| 24 | int_is_greater_than, | ||
| 25 | int_is_at_most, | ||
| 26 | int_is_less_than, | ||
| 27 | boolean_equals, | ||
| 28 | string_equals, | ||
| 29 | string_does_not_equal, | ||
| 30 | string_is_like, | ||
| 31 | string_is_not_like, | ||
| 32 | is_null, | ||
| 33 | is_not_null, | ||
| 34 | matches, | ||
| 35 | does_not_match, | ||
| 36 | hierarchally_matches, | ||
| 37 | does_not_hierarchally_match | ||
| 38 | }; | ||
| 39 | |||
| 40 | // Copy and move constructors | ||
| 41 | |||
| 42 | filter(const filter& other); | ||
| 43 | filter(filter&& other); | ||
| 44 | |||
| 45 | // Assignment | ||
| 46 | |||
| 47 | filter& operator=(filter other); | ||
| 48 | |||
| 49 | // Swap | ||
| 50 | |||
| 51 | friend void swap(filter& first, filter& second); | ||
| 52 | |||
| 53 | // Destructor | ||
| 54 | |||
| 55 | ~filter(); | ||
| 56 | |||
| 57 | // Accessors | ||
| 58 | |||
| 59 | type getType() const | ||
| 60 | { | ||
| 61 | return type_; | ||
| 62 | } | ||
| 63 | |||
| 64 | // Empty | ||
| 65 | |||
| 66 | filter(); | ||
| 67 | |||
| 68 | // Singleton | ||
| 69 | |||
| 70 | filter(field filterField, comparison filterType, int filterValue); | ||
| 71 | filter(field filterField, comparison filterType, std::string filterValue); | ||
| 72 | filter(field filterField, comparison filterType, bool filterValue); | ||
| 73 | filter(field filterField, comparison filterType); | ||
| 74 | filter(field joinOn, comparison filterType, filter joinCondition); | ||
| 75 | |||
| 76 | field getField() const; | ||
| 77 | |||
| 78 | comparison getComparison() const; | ||
| 79 | |||
| 80 | filter getJoinCondition() const; | ||
| 81 | |||
| 82 | std::string getStringArgument() const; | ||
| 83 | |||
| 84 | int getIntegerArgument() const; | ||
| 85 | |||
| 86 | bool getBooleanArgument() const; | ||
| 87 | |||
| 88 | // Group | ||
| 89 | |||
| 90 | explicit filter(bool orlogic); | ||
| 91 | |||
| 92 | bool getOrlogic() const; | ||
| 93 | |||
| 94 | filter operator+(filter condition) const; | ||
| 95 | |||
| 96 | filter& operator+=(filter condition); | ||
| 97 | |||
| 98 | using const_iterator = std::list<filter>::const_iterator; | ||
| 99 | |||
| 100 | const_iterator begin() const; | ||
| 101 | |||
| 102 | const_iterator end() const; | ||
| 103 | |||
| 104 | // Negation | ||
| 105 | |||
| 106 | filter operator!() const; | ||
| 107 | |||
| 108 | // Groupifying | ||
| 109 | |||
| 110 | filter operator&&(filter condition) const; | ||
| 111 | filter operator||(filter condition) const; | ||
| 112 | |||
| 113 | filter& operator&=(filter condition); | ||
| 114 | filter& operator|=(filter condition); | ||
| 115 | |||
| 116 | // Utility | ||
| 117 | |||
| 118 | filter normalize(object context) const; | ||
| 119 | |||
| 120 | private: | ||
| 121 | union { | ||
| 122 | struct { | ||
| 123 | field filterField; | ||
| 124 | comparison filterType; | ||
| 125 | union { | ||
| 126 | std::unique_ptr<filter> join; | ||
| 127 | std::string stringValue; | ||
| 128 | int intValue; | ||
| 129 | bool boolValue; | ||
| 130 | }; | ||
| 131 | } singleton_; | ||
| 132 | struct { | ||
| 133 | std::list<filter> children; | ||
| 134 | bool orlogic; | ||
| 135 | } group_; | ||
| 136 | }; | ||
| 137 | type type_ = type::empty; | ||
| 138 | |||
| 139 | }; | ||
| 140 | |||
| 141 | }; | ||
| 142 | |||
| 143 | #endif /* end of include guard: FILTER_H_932BA9C6 */ | ||
