Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
Filter.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6#include "Filter.h"
7
8using namespace Stroika::Foundation;
9
10using namespace Database;
11using namespace Database::Document;
12
13/*
14 ********************************************************************************
15 ********************** Document::FilterElements::Equals ************************
16 ********************************************************************************
17 */
18bool FilterElements::Equals::Matches (const Database::Document::Document& doc) const
19{
20 if (optional<VariantValue> elt = doc.Lookup (fLHS)) {
21 // RHS could be value, or another lookup
22 optional<VariantValue> rhsValue = get_if<Value> (&fRHS); // intentionally object slice
23 if (!rhsValue) {
24 // then fetch from document
25 rhsValue = doc.Lookup (get<FieldName> (fRHS));
26 }
27 return *elt == rhsValue;
28 }
29 return false;
30}
31
32/*
33 ********************************************************************************
34 ********************** Document::FilterElements::Matches ***********************
35 ********************************************************************************
36 */
37bool FilterElements::Matches (const Operation& op, const Database::Document::Document& doc)
38{
39 if (auto ei = get_if<Equals> (&op)) {
40 return ei->Matches (doc);
41 }
42 AssertNotReached (); // so far only variant supported
43 return false;
44}
45
46/*
47 ********************************************************************************
48 ******************************* Document::Filter *******************************
49 ********************************************************************************
50 */
51bool Filter::Matches (const Database::Document::Document& doc) const
52{
53 for (FilterElements::Operation op : fAndedOperations_) {
54 if (not FilterElements::Matches (op, doc)) {
55 return false;
56 }
57 }
58 return true;
59}
#define AssertNotReached()
Definition Assertions.h:355