Stroika Library 3.0d20
 
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
8
9#include "Filter.h"
10
11using namespace Stroika::Foundation;
13
14using namespace Database;
15using namespace Database::Document;
16
17/*
18 ********************************************************************************
19 ********************** Document::FilterElements::Equals ************************
20 ********************************************************************************
21 */
22bool FilterElements::Equals::Matches (const Database::Document::Document& doc) const
23{
24 if (optional<VariantValue> elt = doc.Lookup (fLHS)) {
25 // RHS could be value, or another lookup
26 optional<VariantValue> rhsValue = Memory::OptionalFromNullable (get_if<Value> (&fRHS)); // intentionally object slice
27 if (not rhsValue) {
28 // then must be name, so fetch from document
29 rhsValue = doc.Lookup (get<FieldName> (fRHS)); // but COULD still be missing from doc - not an error
30 }
31 return *elt == rhsValue;
32 }
33 return false;
34}
35
36String FilterElements::Equals::ToString () const
37{
39 sb << "{"sv;
40 sb << "op: EQUALS "sv;
41 sb << ", lhs: "sv << fLHS;
42 sb << ", rhs: "sv << fRHS;
43 sb << "}"sv;
44 return sb;
45}
46
47/*
48 ********************************************************************************
49 ********************** Document::FilterElements::Matches ***********************
50 ********************************************************************************
51 */
52bool FilterElements::Matches (const Operation& op, const Database::Document::Document& doc)
53{
54 if (auto ei = get_if<Equals> (&op)) {
55 return ei->Matches (doc);
56 }
57 AssertNotReached (); // so far only variant supported
58 return false;
59}
60
61/*
62 ********************************************************************************
63 ******************************* Document::Filter *******************************
64 ********************************************************************************
65 */
66bool Filter::Matches (const Database::Document::Document& doc) const
67{
68 for (FilterElements::Operation op : fConjunction_) {
69 if (not FilterElements::Matches (op, doc)) {
70 return false;
71 }
72 }
73 return true;
74}
75
77{
79 sb << "{"sv;
80 sb << ", conjunction: "sv << fConjunction_;
81 sb << "}"sv;
82 return sb;
83}
#define AssertNotReached()
Definition Assertions.h:355
Similar to String, but intended to more efficiently construct a String. Mutable type (String is large...
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201