From 9e36dbbe74fd9541f0431b7715d3f97895384d28 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 23 Jan 2017 11:44:54 -0500 Subject: Added filter compacting Before statement compilation, empty filters are removed from group filters, and childless group filters become empty filters. --- lib/filter.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'lib/filter.cpp') 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 { throw std::domain_error("This filter has no children"); } } - + filter filter::operator!() const { switch (type_) @@ -1371,4 +1371,36 @@ namespace verbly { } } + filter filter::compact() const + { + switch (type_) + { + case type::empty: + case type::singleton: + { + return *this; + } + + case type::group: + { + filter result(group_.orlogic); + for (const filter& child : group_.children) + { + filter compactedChild = child.compact(); + if (compactedChild.type_ != type::empty) + { + result += child; + } + } + + if (group_.children.empty()) + { + result = {}; + } + + return result; + } + } + } + }; -- cgit 1.4.1