Stroika Library 3.0d23x
 
Loading...
Searching...
No Matches
ObjectCollection.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_ObjectCollection_h_
5#define _Stroika_Foundation_Database_Document_ObjectCollection_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include "Stroika/Foundation/DataExchange/ObjectVariantMapper.h"
11
12/**
13 * \file
14 *
15 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
16 */
17
18namespace Stroika::Foundation::Database::Document::ObjectCollection {
19
20 using namespace Database::Document::Collection;
21 using DataExchange::ObjectVariantMapper;
22
23 /**
24 * Provide an API similar to Database::Document::Collection::Ptr, but using an ObjectVariantMapper
25 * to do IO with the higher level objects directly.
26 */
27 template <typename T>
29 private:
31
32 public:
33 /**
34 */
35 Ptr (const Ptr& src) = default;
36 Ptr (Ptr&& src) noexcept = default;
37 Ptr () noexcept = default;
38 Ptr (const Database::Document::Collection::Ptr& underlyingCollection, const ObjectVariantMapper& mapper);
39 using inherited::inherited;
40
41 public:
42 ~Ptr () = default;
43
44 public:
45 /**
46 */
47 nonvirtual Ptr& operator= (const Ptr& src) = default;
48 nonvirtual Ptr& operator= (Ptr&& src) noexcept = default;
49
50 public:
51 /**
52 * returns ID
53 */
54 using inherited::Add;
55 nonvirtual IDType Add (const T& v) const;
56
57 public:
58 /**
59 */
60 nonvirtual optional<T> Get (const IDType& id, const optional<Projection>& projection = {}) const;
61 nonvirtual optional<T> Get (const Filter& filter, const optional<Projection>& projection = {}) const;
62
63 public:
64 /**
65 */
66 nonvirtual T GetOrThrow (const IDType& id, const optional<Projection>& projection = {}) const;
67 nonvirtual T GetOrThrow (const Filter& filter, const optional<Projection>& projection = {}) const;
68
69 public:
70 /**
71 */
72 nonvirtual Sequence<T> GetAll (const optional<Filter>& filter = {}, const optional<Projection>& projection = {}) const;
73
74 public:
75 /**
76 */
77 using inherited::Replace;
78 nonvirtual void Replace (const T& newV) const;
79 nonvirtual void Replace (const IDType& id, const T& newV) const;
80
81 public:
82 /**
83 */
84 using inherited::Update;
85 nonvirtual void Update (const T& newV, const Set<String>& onlyTheseFields) const;
86 nonvirtual void Update (const IDType& id, const T& newV, const Set<String>& onlyTheseFields) const;
87
88 public:
89 /**
90 * @brief if v contains and ID, look it up, and if found, Replace. If not found, then synonym for Add ()
91 */
92 using inherited::AddOrUpdate;
93 nonvirtual IDType AddOrUpdate (const T& newV) const;
94
95 private:
96 ObjectVariantMapper fMapper_;
97 };
98
99 /**
100 */
101 template <typename T>
102 Ptr<T> New (const Database::Document::Collection::Ptr& underlyingCollection, const ObjectVariantMapper& mapper);
103
104}
105
106/*
107 ********************************************************************************
108 ***************************** Implementation Details ***************************
109 ********************************************************************************
110 */
111#include "ObjectCollection.inl"
112
113#endif /*_Stroika_Foundation_Database_Document_ObjectCollection_h_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
A generalization of a vector: a container whose elements are keyed by the natural numbers.
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
ObjectVariantMapper can be used to map C++ types to and from variant-union types, which can be transp...
nonvirtual void Replace(const Document &newV) const
except for issues of timing, equivalent to remove, and then add newV using id
nonvirtual optional< Document > Get(const IDType &id, const optional< Projection > &projection={}) const
Read the unique document given by id (or filter) or return nullopt if no such.
nonvirtual void Update(const Document &newV) const
Update the document named by 'id' - just updating fields in newV (all or ones given in argument onlyT...
nonvirtual IDType AddOrUpdate(const Document &v) const
if v contains and ID, look it up, and if found, Replace. If not found, then synonym for Add ()
nonvirtual Sequence< Document > GetAll(const optional< Filter > &filter={}, const optional< Projection > &projection={}) const