Ditto  3.0.4
AbstractDocumentPath.hpp
1 #ifndef _DITTO_ABSTRACT_DOCUMENT_PATH_
2 #define _DITTO_ABSTRACT_DOCUMENT_PATH_
3 
4 #include "Helpers.hpp"
5 #include "UpdateResult.hpp"
6 #include "json.hpp"
7 
8 typedef struct CDocument CDocument_t;
9 
13 typedef bool (nlohmann::json::*json_callback)() const;
14 namespace ditto {
15 
22 protected:
23  CDocument_t const *document;
24  DocumentId id;
25  std::string path;
26 
38  AbstractDocumentPath(CDocument_t const *document, DocumentId id,
39  std::string initial_path);
40 
49  AbstractDocumentPath(const AbstractDocumentPath *document_path,
50  std::string key);
51 
59  AbstractDocumentPath(const AbstractDocumentPath *document_path,
60  std::size_t index);
61 
67  AbstractDocumentPath(const AbstractDocumentPath *document_path);
68 
77  template <typename T>
78  T get_primitive_or_default(T default_value, json_callback json_cb,
79  PathAccessorType path_type) const;
80 
81  // TODO
82  template <typename T>
83  std::shared_ptr<T> get_object_or_default(json_callback json_cb,
84  PathAccessorType path_type) const;
85  // TODO
86  template <typename T>
87  std::shared_ptr<T>
88  get_mut_object_or_default(json_callback json_cb,
89  PathAccessorType path_type) const;
90 
91 public:
92  nlohmann::json get_json(PathAccessorType path_type) const;
103  AbstractDocumentPath operator[](std::string path);
104 
116  AbstractDocumentPath operator[](std::size_t index);
117 
127  std::string get_string_value() const;
128 
137  int get_int_value() const;
138 
147  double get_double_value() const;
148 
157  float get_float_value() const;
158 
167  bool get_bool_value() const;
168 
178  nlohmann::json get_json() const;
179 };
180 
181 } // namespace ditto
182 
183 #endif
Provides an interface to specify a path to a key in a document that you can then call various update ...
Definition: AbstractDocumentPath.hpp:21
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: AbstractDocumentPath.cpp:146
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: AbstractDocumentPath.cpp:151
std::shared_ptr< T > get_object_or_default(json_callback json_cb, PathAccessorType path_type) const
Helper function to retrieve crdt objects.
Definition: AbstractDocumentPath.cpp:109
AbstractDocumentPath(CDocument_t const *document, DocumentId id, std::string initial_path)
Constructs a new initial AbstractDocumentPath for a document.
Definition: AbstractDocumentPath.cpp:32
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: AbstractDocumentPath.cpp:156
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...
Definition: AbstractDocumentPath.cpp:52
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 correspondign default value.
Definition: AbstractDocumentPath.cpp:83
std::string get_string_value() const
Returns the value at the previously specified key in the document as a std::string....
Definition: AbstractDocumentPath.cpp:141
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: AbstractDocumentPath.cpp:161
nlohmann::json get_json() const
Returns the value at the previously specified key in the document as a nlohmann::json object....
Definition: AbstractDocumentPath.cpp:166
basic_json<> json
default JSON class
Definition: json.hpp:2933
An identifier for a Document.
Definition: DocumentId.hpp:21