Ditto 4.13.1
 
Loading...
Searching...
No Matches
MutableDocumentPath.hpp
1#ifndef DITTO_MUTABLE_DOCUMENT_PATH_H
2#define DITTO_MUTABLE_DOCUMENT_PATH_H
3
4#include "AbstractDocumentPath.hpp"
5#include "AttachmentToken.hpp"
6#include "Helpers.hpp"
7
8#include "UpdateResult.hpp"
9
10#include "json.hpp"
11
12using CDocument_t = struct CDocument;
13
14namespace ditto {
15
20class MutableCounter;
21class MutableRegister;
22
34class DITTO_DEPRECATED_BECAUSE(
35 "Use DQL (Ditto Query Language) instead. For more information see: "
36 "https://ditto.com/link/legacy-to-dql-guide") MutableDocumentPath
37 : public AbstractDocumentPath {
38 DITTO_DISABLE_DEPRECATED_WARNINGS("The legacy query API is deprecated")
39
40 friend class MutableDocument;
41 friend class MutableCounter;
42 friend class MutableRegister;
43
44private:
45 // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
46 std::vector<std::unique_ptr<UpdateResult>> &results;
47
65 MutableDocumentPath(CDocument_t const *document, DocumentId id,
66 std::string initial_path,
67 std::vector<std::unique_ptr<UpdateResult>> &results);
68
81 MutableDocumentPath(const MutableDocumentPath *document_path,
82 std::string key);
83
96 MutableDocumentPath(const MutableDocumentPath *document_path,
97 std::size_t index);
98
99 explicit MutableDocumentPath(const MutableDocumentPath *doc_path);
100
101 template <typename T>
102 std::shared_ptr<T>
103 get_mut_object_or_default(json_callback json_cb,
104 PathAccessorType path_type) const;
105
106public:
107 MutableDocumentPath operator[](std::string key);
108 MutableDocumentPath operator[](std::size_t index);
109
119 std::shared_ptr<AttachmentToken> get_attachment_token() const;
120
130 std::shared_ptr<MutableCounter> get_counter() const;
131
141 std::shared_ptr<MutableRegister> get_register() const;
142
155 void set(nlohmann::json value, bool is_default = false) const;
156
164 void remove() const;
165
166private:
177 void increment(double amount) const;
178
179 DITTO_REENABLE_WARNINGS
180};
181
182} // namespace ditto
183
184#endif
AbstractDocumentPath(CDocument_t const *document, DocumentId id, std::string initial_path)
Constructs a new initial AbstractDocumentPath for a document.
Definition MutableCounter.hpp:18
void set(nlohmann::json value, bool is_default=false) const
Set a value at the document's key defined by the preceding subscripting.
void remove() const
Remove a value at the document's key defined by the preceding subscripting.
std::shared_ptr< MutableCounter > get_counter() const
Returns the value at the previously specified key in the document as a std::shared_ptr<MutableCounter...
std::shared_ptr< MutableRegister > get_register() const
Returns the value at the previously specified key in the document as a std::shared_ptr<MutableRegiste...
std::shared_ptr< AttachmentToken > get_attachment_token() const
Returns the value at the previously specified key in the document as a std::shared_ptr<AttachmentToke...
Definition MutableRegister.hpp:18
Namespace for the Ditto C++ SDK types and functions.
Definition AbstractDocumentPath.hpp:19
An identifier for a Document.
Definition DocumentId.hpp:23