Stroika Library 3.0d25
 
Loading...
Searching...
No Matches
Projection.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Database_Document_Projection_h_
5#define _Stroika_Foundation_Database_Document_Projection_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
10#include "Stroika/Foundation/Containers/Set.h"
12
13/**
14 * \file
15 *
16 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
17 */
18
19namespace Stroika::Foundation::Database::Document {
20
21 using Characters::String;
22 using Containers::Set;
23
24 /**
25 * \brief define a (simple) projection on a document, subsetting the fields of that document.
26 *
27 * The projection can either be specified as a set of fields to include, or a set of fields to exclude.
28 *
29 * \note As of Stroika v3.0d18, these can only be simple top level field names, but this might be someday extended like
30 * in mongodb, and perhaps using json pointer syntax?
31 */
32 class Projection {
33 private:
34 // use optional<Projection> so no need for monostate/default-constructible Projection
35 using MyVariant_ = variant<Set<String>, Set<String>>;
36
37 public:
38 enum class Flag {
39 eOmit = 0,
40 eInclude = 1
41 };
42 using Flag::eInclude;
43 using Flag::eOmit;
44
45 public:
46 /**
47 */
48 Projection () = delete;
49 Projection (Flag f, const Set<String>& fields);
50
51 public:
52 /**
53 */
54 nonvirtual tuple<Flag, Set<String>> GetFields () const;
55
56 public:
57 /**
58 * Apply this projection to the argument document, and return the updated document.
59 */
61
62 public:
63 /**
64 * See if fieldName included after Projection applied
65 */
66 nonvirtual bool Includes (const String& fieldName) const;
67
68 public:
69 /**
70 * @see Characters::ToString ()
71 */
72 nonvirtual String ToString () const;
73
74 public:
75 /**
76 */
77 nonvirtual bool operator== (const Projection&) const = default;
78
79 public:
80 /**
81 * \note not orderable because argument Set<String> is not orderable (could fix but no point for now).
82 */
83 nonvirtual auto operator<=> (const Projection&) const = delete;
84
85 private:
86 /**
87 * get<Projection::eOmit> are fields that are omitted, and get<Projection::eInclude> are fields that are included.
88 * ONLY specify one or the other.
89 */
90 MyVariant_ fFields_;
91 };
92
93 /**
94 */
95 inline const Projection kOmitIDs = Projection{Projection::eOmit, {kID}};
96
97 /**
98 */
99 inline const Projection kOnlyIDs = Projection{Projection::eInclude, get<Set<String>> (kOmitIDs.GetFields ())};
100
101}
102
103/*
104 ********************************************************************************
105 ***************************** Implementation Details ***************************
106 ********************************************************************************
107 */
108#include "Projection.inl"
109
110#endif /*_Stroika_Foundation_Database_Document_Projection_h_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
A Mapping uniquely associates two elements: a key and a value (use Assocation to allow multiple value...
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
define a (simple) projection on a document, subsetting the fields of that document.
Definition Projection.h:32
nonvirtual bool Includes(const String &fieldName) const
nonvirtual Database::Document::Document Apply(const Database::Document::Document &d) const
nonvirtual auto operator<=>(const Projection &) const =delete