diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-04-01 11:33:21 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-04-01 11:33:21 -0400 |
| commit | 494e19b3c27e6a1eb63b39c245ad4024702e883b (patch) | |
| tree | eb3980c7652ed24b402b5424c085f36827037880 /lib/filter.h | |
| parent | 8b95516aef0cd4bd98e2592d6f247882dc88886a (diff) | |
| download | verbly-494e19b3c27e6a1eb63b39c245ad4024702e883b.tar.gz verbly-494e19b3c27e6a1eb63b39c245ad4024702e883b.tar.bz2 verbly-494e19b3c27e6a1eb63b39c245ad4024702e883b.zip | |
Converted verbly::filter to use a variant object
Diffstat (limited to 'lib/filter.h')
| -rw-r--r-- | lib/filter.h | 77 |
1 files changed, 38 insertions, 39 deletions
| diff --git a/lib/filter.h b/lib/filter.h index 942fe18..7db2773 100644 --- a/lib/filter.h +++ b/lib/filter.h | |||
| @@ -4,6 +4,8 @@ | |||
| 4 | #include <list> | 4 | #include <list> |
| 5 | #include <string> | 5 | #include <string> |
| 6 | #include <memory> | 6 | #include <memory> |
| 7 | #include "../vendor/hkutil/vendor/variant.hpp" | ||
| 8 | #include "../vendor/hkutil/hkutil/recptr.h" | ||
| 7 | #include "field.h" | 9 | #include "field.h" |
| 8 | #include "enums.h" | 10 | #include "enums.h" |
| 9 | 11 | ||
| @@ -11,6 +13,7 @@ namespace verbly { | |||
| 11 | 13 | ||
| 12 | class filter { | 14 | class filter { |
| 13 | public: | 15 | public: |
| 16 | |||
| 14 | enum class type { | 17 | enum class type { |
| 15 | empty, | 18 | empty, |
| 16 | singleton, | 19 | singleton, |
| @@ -40,23 +43,6 @@ namespace verbly { | |||
| 40 | field_does_not_equal | 43 | field_does_not_equal |
| 41 | }; | 44 | }; |
| 42 | 45 | ||
| 43 | // Copy and move constructors | ||
| 44 | |||
| 45 | filter(const filter& other); | ||
| 46 | filter(filter&& other); | ||
| 47 | |||
| 48 | // Assignment | ||
| 49 | |||
| 50 | filter& operator=(filter other); | ||
| 51 | |||
| 52 | // Swap | ||
| 53 | |||
| 54 | friend void swap(filter& first, filter& second); | ||
| 55 | |||
| 56 | // Destructor | ||
| 57 | |||
| 58 | ~filter(); | ||
| 59 | |||
| 60 | // Accessors | 46 | // Accessors |
| 61 | 47 | ||
| 62 | type getType() const | 48 | type getType() const |
| @@ -66,7 +52,7 @@ namespace verbly { | |||
| 66 | 52 | ||
| 67 | // Empty | 53 | // Empty |
| 68 | 54 | ||
| 69 | filter(); | 55 | filter() = default; |
| 70 | 56 | ||
| 71 | // Singleton | 57 | // Singleton |
| 72 | 58 | ||
| @@ -140,29 +126,42 @@ namespace verbly { | |||
| 140 | filter compact() const; | 126 | filter compact() const; |
| 141 | 127 | ||
| 142 | private: | 128 | private: |
| 143 | union { | 129 | |
| 144 | struct { | 130 | using rec_filter = hatkirby::recptr<filter>; |
| 145 | field filterField; | 131 | |
| 146 | comparison filterType; | 132 | struct singleton_type { |
| 147 | union { | 133 | field filterField; |
| 148 | std::unique_ptr<filter> join; | 134 | comparison filterType; |
| 149 | std::string stringValue; | 135 | |
| 150 | int intValue; | 136 | mpark::variant< |
| 151 | bool boolValue; | 137 | mpark::monostate, |
| 152 | field compareField; | 138 | rec_filter, |
| 153 | }; | 139 | std::string, |
| 154 | } singleton_; | 140 | int, |
| 155 | struct { | 141 | bool, |
| 156 | std::list<filter> children; | 142 | field> data; |
| 157 | bool orlogic; | 143 | }; |
| 158 | } group_; | 144 | |
| 159 | struct { | 145 | struct group_type { |
| 160 | std::string name; | 146 | std::list<filter> children; |
| 161 | bool internal; | 147 | bool orlogic; |
| 162 | std::unique_ptr<filter> subfilter; | ||
| 163 | } mask_; | ||
| 164 | }; | 148 | }; |
| 149 | |||
| 150 | struct mask_type { | ||
| 151 | std::string name; | ||
| 152 | bool internal; | ||
| 153 | rec_filter subfilter; | ||
| 154 | }; | ||
| 155 | |||
| 156 | using variant_type = | ||
| 157 | mpark::variant< | ||
| 158 | mpark::monostate, | ||
| 159 | singleton_type, | ||
| 160 | group_type, | ||
| 161 | mask_type>; | ||
| 162 | |||
| 165 | type type_ = type::empty; | 163 | type type_ = type::empty; |
| 164 | variant_type variant_; | ||
| 166 | 165 | ||
| 167 | }; | 166 | }; |
| 168 | 167 | ||
