diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-23 11:44:54 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-23 11:44:54 -0500 |
commit | 9e36dbbe74fd9541f0431b7715d3f97895384d28 (patch) | |
tree | 05121ec1fbb2aceb5f60764a290122711d0d7251 /lib/filter.cpp | |
parent | d19c329607d611901540e5d3d746c1a94a0b6210 (diff) | |
download | verbly-9e36dbbe74fd9541f0431b7715d3f97895384d28.tar.gz verbly-9e36dbbe74fd9541f0431b7715d3f97895384d28.tar.bz2 verbly-9e36dbbe74fd9541f0431b7715d3f97895384d28.zip |
Added filter compacting
Before statement compilation, empty filters are removed from group filters, and childless group filters become empty filters.
Diffstat (limited to 'lib/filter.cpp')
-rw-r--r-- | lib/filter.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/filter.cpp b/lib/filter.cpp index 1af7314..17309f1 100644 --- a/lib/filter.cpp +++ b/lib/filter.cpp | |||
@@ -871,7 +871,7 @@ namespace verbly { | |||
871 | throw std::domain_error("This filter has no children"); | 871 | throw std::domain_error("This filter has no children"); |
872 | } | 872 | } |
873 | } | 873 | } |
874 | 874 | ||
875 | filter filter::operator!() const | 875 | filter filter::operator!() const |
876 | { | 876 | { |
877 | switch (type_) | 877 | switch (type_) |
@@ -1371,4 +1371,36 @@ namespace verbly { | |||
1371 | } | 1371 | } |
1372 | } | 1372 | } |
1373 | 1373 | ||
1374 | filter filter::compact() const | ||
1375 | { | ||
1376 | switch (type_) | ||
1377 | { | ||
1378 | case type::empty: | ||
1379 | case type::singleton: | ||
1380 | { | ||
1381 | return *this; | ||
1382 | } | ||
1383 | |||
1384 | case type::group: | ||
1385 | { | ||
1386 | filter result(group_.orlogic); | ||
1387 | for (const filter& child : group_.children) | ||
1388 | { | ||
1389 | filter compactedChild = child.compact(); | ||
1390 | if (compactedChild.type_ != type::empty) | ||
1391 | { | ||
1392 | result += child; | ||
1393 | } | ||
1394 | } | ||
1395 | |||
1396 | if (group_.children.empty()) | ||
1397 | { | ||
1398 | result = {}; | ||
1399 | } | ||
1400 | |||
1401 | return result; | ||
1402 | } | ||
1403 | } | ||
1404 | } | ||
1405 | |||
1374 | }; | 1406 | }; |