Ditto 2.0.6
Public Member Functions | List of all members
ditto::MutableDocumentPath Class Reference

Provides an interface to specify a path to a key in a document that you can then call various update functions on. More...

#include <MutableDocumentPath.hpp>

Inheritance diagram for ditto::MutableDocumentPath:
ditto::AbstractDocumentPath

Public Member Functions

MutableDocumentPath operator[] (std::string key)
 
MutableDocumentPath operator[] (std::size_t index)
 
std::shared_ptr< AttachmentTokenget_attachment_token () const
 Returns the value at the previously specified key in the document as a std::shared_ptr<AttachmentToken>. If the key was invalid the return value will be a nullptr. More...
 
std::shared_ptr< MutableCounterget_counter () const
 Returns the value at the previously specified key in the document as a std::shared_ptr<MutableCounter>. If the key was invalid the return value will be a nullptr. More...
 
std::shared_ptr< MutableRegisterget_register () const
 Returns the value at the previously specified key in the document as a std::shared_ptr<MutableRegister>. If the key was invalid the return value will be a nullptr. More...
 
std::shared_ptr< MutableRgaget_rga () const DITTO_DEPRECATED
 Returns the value at the previously specified key in the document as a std::shared_ptr<MutableRga>. If the key was invalid the return value will be a nullptr. More...
 
void set (nlohmann::json value, bool is_default=false) const
 Set a value at the document's key defined by the preceding subscripting. More...
 
void remove () const
 Remove a value at the document's key defined by the preceding subscripting. More...
 
- Public Member Functions inherited from ditto::AbstractDocumentPath
nlohmann::json get_json (PathAccessorType path_type) const
 
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 in the document and eventually perform an update operation on. More...
 
AbstractDocumentPath operator[] (std::size_t index)
 Used to specify an index in the array at the preceding key-path specified through the subscripting defined previously. You can subscript the return value further to access a further nested key in the document and eventually perform an update operation. More...
 
std::string get_string_value () const
 Returns the value at the previously specified key in the document as a std::string. If the key was invalid a default value of an empty string will be returned. More...
 
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 default value of 0 will be returned. More...
 
double get_double_value () const
 Returns the value at the previously specified key in the document as a double. If the key was invalid a default value of 0 will be returned. More...
 
float get_float_value () const
 Returns the value at the previously specified key in the document as a float. If the key was invalid a default value of 0 will be returned. More...
 
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 default value of false will be returned. More...
 
nlohmann::json get_json () const
 Returns the value at the previously specified key in the document as a nlohmann::json object. If the key was invalid the return value will be a nullptr. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ditto::AbstractDocumentPath
 AbstractDocumentPath (CDocument_t const *document, DocumentId id, std::string initial_path)
 Constructs a new initial AbstractDocumentPath for a document. More...
 
 AbstractDocumentPath (const AbstractDocumentPath *document_path, std::string key)
 Constructs a new AbstractDocumentPath from an existing AbstractDocumentPath by appending a path. More...
 
 AbstractDocumentPath (const AbstractDocumentPath *document_path, std::size_t index)
 Constructs a new AbstractDocumentPath from an existing AbstractDocumentPath by appending an index. More...
 
 AbstractDocumentPath (const AbstractDocumentPath *document_path)
 Copy constructor. More...
 
template<typename 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. More...
 
template<typename T >
std::shared_ptr< T > get_object_or_default (json_callback json_cb, PathAccessorType path_type) const
 Helper function to retrieve crdt objects. More...
 
template<typename T >
std::shared_ptr< T > get_mut_object_or_default (json_callback json_cb, PathAccessorType path_type) const
 
- Protected Attributes inherited from ditto::AbstractDocumentPath
CDocument_t const * document
 
DocumentId id
 
std::string path
 

Detailed Description

Provides an interface to specify a path to a key in a document that you can then call various update functions on.

You obtain a MutableDocumentPath by subscripting a MutableDocument and you can then further subscript a MutableDocumentPath to further specify the key of the document that you want to update.

Member Function Documentation

◆ get_attachment_token()

std::shared_ptr< AttachmentToken > ditto::MutableDocumentPath::get_attachment_token ( ) const

Returns the value at the previously specified key in the document as a std::shared_ptr<AttachmentToken>. If the key was invalid the return value will be a nullptr.

Returns
The value at the path specified by the document subscripting as a std::shared_ptr<AttachmentToken>. The return value will be a nullptr if the key was invalid or the value was not an AttachmentToken object.

◆ get_counter()

std::shared_ptr< MutableCounter > ditto::MutableDocumentPath::get_counter ( ) const

Returns the value at the previously specified key in the document as a std::shared_ptr<MutableCounter>. If the key was invalid the return value will be a nullptr.

Returns
The value at the path specified by the document subscripting as a std::shared_ptr<MutableCounter>. The return value will be a nullptr if the key was invalid or the value was not a Counter object.

◆ get_register()

std::shared_ptr< MutableRegister > ditto::MutableDocumentPath::get_register ( ) const

Returns the value at the previously specified key in the document as a std::shared_ptr<MutableRegister>. If the key was invalid the return value will be a nullptr.

Returns
The value at the path specified by the document subscripting as a std::shared_ptr<MutableRegister>. The return value will be a nullptr if the key was invalid or the value was not a register object.

◆ get_rga()

std::shared_ptr< MutableRga > ditto::MutableDocumentPath::get_rga ( ) const

Returns the value at the previously specified key in the document as a std::shared_ptr<MutableRga>. If the key was invalid the return value will be a nullptr.

Returns
The value at the path specified by the document subscripting as a std::shared_ptr<MutableRga>. The return value will be a nullptr if the key was invalid or the value was not a MutableRga object.

◆ remove()

void ditto::MutableDocumentPath::remove ( ) const

Remove a value at the document's key defined by the preceding subscripting.

Exceptions
DittoErrorthrown if trying to update the document at an invalid key.

◆ set()

void ditto::MutableDocumentPath::set ( nlohmann::json  value,
bool  is_default = false 
) const

Set a value at the document's key defined by the preceding subscripting.

Parameters
valuethe value to set at the subscripting-defined document key.
is_defaultrepresents whether or not the value should be set as a default value. Set this to true if you want to set a default value that you expect to be overwritten by other devices in the network. The default value is false.
Exceptions
DittoErrorthrown if trying to update the document at an invalid key.