Ditto 4.13.1
 
Loading...
Searching...
No Matches
AbstractDocumentPath.hpp
1#ifndef DITTO_ABSTRACT_DOCUMENT_PATH_H
2#define DITTO_ABSTRACT_DOCUMENT_PATH_H
3
4#include "Helpers.hpp"
5#include "UpdateResult.hpp"
6#include "json.hpp"
7
8using CDocument_t = struct CDocument;
9
16using json_callback DITTO_DEPRECATED_BECAUSE(
17 "Use DQL (Ditto Query Language) instead. For more information "
18 "see: https://ditto.com/link/legacy-to-dql-guide") =
19 bool (nlohmann::json::*)() const;
20
21namespace ditto {
22
29 *
30 */
31class DITTO_DEPRECATED_BECAUSE(
32 "Use DQL (Ditto Query Language) instead. For more information "
33 "see: https://ditto.com/link/legacy-to-dql-guide") AbstractDocumentPath {
34protected:
35 // NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes)
36 // NOLINTBEGIN(misc-non-private-member-variables-in-classes)
37 CDocument_t const *document;
38 DocumentId id;
39 std::string path;
40 // NOLINTEND(misc-non-private-member-variables-in-classes)
41 // NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes)
42
54 AbstractDocumentPath(CDocument_t const *document, DocumentId id,
55 std::string initial_path);
56
65 AbstractDocumentPath(const AbstractDocumentPath *document_path,
66 std::string key);
67
75 AbstractDocumentPath(const AbstractDocumentPath *document_path,
76 std::size_t index);
77
83 explicit AbstractDocumentPath(const AbstractDocumentPath *document_path);
84
93 template <typename T>
94 T get_primitive_or_default(T default_value, json_callback json_cb,
95 PathAccessorType path_type) const;
96
97 // TODO
98 template <typename T>
99 std::shared_ptr<T> get_object_or_default(json_callback json_cb,
100 PathAccessorType path_type) const;
101 // TODO
102 template <typename T>
103 std::shared_ptr<T>
104 get_mut_object_or_default(json_callback json_cb,
105 PathAccessorType path_type) const;
106
107public:
108 nlohmann::json get_json(PathAccessorType path_type) const;
119 AbstractDocumentPath operator[](std::string path);
120
132 AbstractDocumentPath operator[](std::size_t index);
133
143 std::string get_string_value() const;
144
153 int get_int_value() const;
154
163 double get_double_value() const;
164
173 float get_float_value() const;
174
183 bool get_bool_value() const;
184
194 nlohmann::json get_json() const;
195};
196
197} // namespace ditto
198
199#endif
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...
double get_double_value() const
Returns the value at the previously specified key in the document as a double. If the key was invalid...
AbstractDocumentPath(CDocument_t const *document, DocumentId id, std::string initial_path)
Constructs a new initial AbstractDocumentPath for a document.
float get_float_value() const
Returns the value at the previously specified key in the document as a float. If the key was invalid ...
AbstractDocumentPath 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...
T get_primitive_or_default(T default_value, json_callback json_cb, PathAccessorType path_type) const
Get the primitive stored at a given path or the corresponding default value.
std::string get_string_value() const
Returns the value at the previously specified key in the document as a std::string....
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...
Namespace for the Ditto C++ SDK types and functions.
Definition AbstractDocumentPath.hpp:19
An identifier for a Document.
Definition DocumentId.hpp:23