summary refs log tree commit diff stats
path: root/lib/filter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/filter.cpp')
-rw-r--r--lib/filter.cpp34
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};