Ditto 1.1.3
MutableDocumentPath.hpp
1#ifndef _DITTO_MUTABLE_DOCUMENT_PATH_
2#define _DITTO_MUTABLE_DOCUMENT_PATH_
3
4#include "AttachmentToken.hpp"
5#include "UpdateResult.hpp"
6
7#include "json.hpp"
8
9typedef struct CDocument CDocument_t;
10
11namespace ditto {
12
22 friend class MutableDocument;
23
24private:
25 CDocument_t const *document;
26 DocumentId id;
27 std::vector<std::unique_ptr<UpdateResult>> &results;
28 std::string path;
29
47 MutableDocumentPath(CDocument_t const *document, DocumentId id,
48 std::string initial_path,
49 std::vector<std::unique_ptr<UpdateResult>> &results);
50
64 MutableDocumentPath(const MutableDocumentPath *document_path,
65 std::string component);
66
67public:
78 MutableDocumentPath operator[](std::string path);
79
91 MutableDocumentPath operator[](std::size_t index);
92
102 std::string get_string_value() const;
103
112 int get_int_value() const;
113
122 double get_double_value() const;
123
132 float get_float_value() const;
133
142 bool get_bool_value() const;
143
153 nlohmann::json get_json() const;
154
164 std::shared_ptr<AttachmentToken> get_attachment_token() const;
165
178 void set(nlohmann::json value, bool is_default = false) const;
179
187 void remove() const;
188
200 void replace_with_counter(bool is_default = false) const;
201
212 void increment(double amount) const;
213
223 void push(nlohmann::json value) const;
224
234 nlohmann::json pop() const;
235
245 void insert(nlohmann::json value) const;
246};
247
248} // namespace ditto
249
250#endif
This is used as part of update operations for documents.
Definition: MutableDocument.hpp:29
Provides an interface to specify a path to a key in a document that you can then call various update ...
Definition: MutableDocumentPath.hpp:21
bool get_bool_value() const
Returns the value at the previously specified key in the document as a bool. If the key was invalid a...
Definition: MutableDocumentPath.cpp:81
nlohmann::json pop() const
Pop a value off the end of an array at the document's key defined by the preceding subscripting....
Definition: MutableDocumentPath.cpp:165
nlohmann::json get_json() const
Returns the value at the previously specified key in the document as a nlohmann::json object....
Definition: MutableDocumentPath.cpp:89
std::string get_string_value() const
Returns the value at the previously specified key in the document as a std::string....
Definition: MutableDocumentPath.cpp:49
int get_int_value() const
Returns the value at the previously specified key in the document as an int. If the key was invalid a...
Definition: MutableDocumentPath.cpp:57
void push(nlohmann::json value) const
Push a value on to the end of an array at the document's key defined by the preceding subscripting....
Definition: MutableDocumentPath.cpp:156
void set(nlohmann::json value, bool is_default=false) const
Set a value at the document's key defined by the preceding subscripting.
Definition: MutableDocumentPath.cpp:115
float get_float_value() const
Returns the value at the previously specified key in the document as a float. If the key was invalid ...
Definition: MutableDocumentPath.cpp:73
void remove() const
Remove a value at the document's key defined by the preceding subscripting.
Definition: MutableDocumentPath.cpp:130
void replace_with_counter(bool is_default=false) const
Replace a value at the document's key defined by the preceding subscripting with a counter.
Definition: MutableDocumentPath.cpp:137
double get_double_value() const
Returns the value at the previously specified key in the document as a double. If the key was invalid...
Definition: MutableDocumentPath.cpp:65
void increment(double amount) const
Increment a counter at the document's key defined by the preceding subscripting. This will only succe...
Definition: MutableDocumentPath.cpp:149
MutableDocumentPath operator[](std::string path)
Used to specify a path to a key in the document that you can subscript further to access a nested key...
Definition: MutableDocumentPath.cpp:37
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: MutableDocumentPath.cpp:102
void insert(nlohmann::json value) const
Inserts a value into an array at the index defined by the preceding subscripting. This will only succ...
Definition: MutableDocumentPath.cpp:177
basic_json<> json
default JSON class
Definition: json.hpp:2933
An identifier for a Document.
Definition: DocumentId.hpp:21