Stroika Library 3.0d20
 
Loading...
Searching...
No Matches
Projection.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. 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#if qCompilerAndStdLib_explicitly_defaulted_threeway_warning_Buggy
80 DISABLE_COMPILER_CLANG_WARNING_START ("clang diagnostic ignored \"-Wdefaulted-function-deleted\"")
81#endif
82 public:
83 /**
84 */
85 nonvirtual auto operator<=> (const Projection&) const = default;
86#if qCompilerAndStdLib_explicitly_defaulted_threeway_warning_Buggy
87 DISABLE_COMPILER_CLANG_WARNING_END ("clang diagnostic ignored \"-Wdefaulted-function-deleted\"")
88#endif
89
90 private:
91 /**
92 * get<Projection::eOmit> are fields that are omitted, and get<Projection::eInclude> are fields that are included.
93 * ONLY specify one or the other.
94 */
95 MyVariant_ fFields_;
96 };
97
98/**
99 */
100#if qCompilerAndStdLib_inline_const_order_wrong_sometimes_Buggy
101 inline const Projection kOmitIDs = Projection{Projection::eOmit, {"id"sv}};
102#else
103 inline const Projection kOmitIDs = Projection{Projection::eOmit, {kID}};
104#endif
105
106 /**
107 */
108 inline const Projection kOnlyIDs = Projection{Projection::eInclude, get<Set<String>> (kOmitIDs.GetFields ())};
109
110}
111
112/*
113 ********************************************************************************
114 ***************************** Implementation Details ***************************
115 ********************************************************************************
116 */
117#include "Projection.inl"
118
119#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
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