Ditto  1.0.14
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...

Public Member Functions

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 in the document and eventually perform an update operation on. More...
 
MutableDocumentPath 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 ()
 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 ()
 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 ()
 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 ()
 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 ()
 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 ()
 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...
 
std::shared_ptr< AttachmentTokenget_attachment_token ()
 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...
 
void set (nlohmann::json value, bool is_default=false)
 Set a value at the document's key defined by the preceding subscripting. More...
 
void remove ()
 Remove a value at the document's key defined by the preceding subscripting. More...
 
void replace_with_counter (bool is_default=false)
 Replace a value at the document's key defined by the preceding subscripting with a counter. More...
 
void increment (double amount)
 Increment a counter at the document's key defined by the preceding subscripting. This will only succeed if the value at the subscripting-defined key is a counter. More...
 
void push (nlohmann::json value)
 Push a value on to the end of an array at the document's key defined by the preceding subscripting. This will only succeed if the value at the subscripting-defined key is an array. More...
 
nlohmann::json pop ()
 Pop a value off the end of an array at the document's key defined by the preceding subscripting. This will only succeed if the value at the subscripting-defined key is an array. More...
 
void insert (nlohmann::json value)
 Inserts a value into an array at the index defined by the preceding subscripting. This will only succeed if the value at the subscripting-defined key is an index into an array. More...
 

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 ( )

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_bool_value()

bool ditto::MutableDocumentPath::get_bool_value ( )

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.

Returns
The value at the path specified by the document subscripting as a bool. The return value will be false if the key was invalid or the value was not a boolean type.

◆ get_double_value()

double ditto::MutableDocumentPath::get_double_value ( )

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.

Returns
The value at the path specified by the document subscripting as a double. The return value will be 0 if the key was invalid or the value was not a numeric type.

◆ get_float_value()

float ditto::MutableDocumentPath::get_float_value ( )

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.

Returns
The value at the path specified by the document subscripting as a float. The return value will be 0 if the key was invalid or the value was not a numeric type.

◆ get_int_value()

int ditto::MutableDocumentPath::get_int_value ( )

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.

Returns
The value at the path specified by the document subscripting as an int. The return value will be 0 if the key was invalid or the value was not a numeric type.

◆ get_json()

json ditto::MutableDocumentPath::get_json ( )

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.

Returns
The value at the path specified by the document subscripting as a nlohmann::json object. The return value will be a nullptr if the key was invalid.

◆ get_string_value()

std::string ditto::MutableDocumentPath::get_string_value ( )

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.

Returns
The value at the path specified by the document subscripting as a std::string. The return value will be an empty string if the key was invalid or the value was not a string.

◆ increment()

void ditto::MutableDocumentPath::increment ( double  amount)

Increment a counter at the document's key defined by the preceding subscripting. This will only succeed if the value at the subscripting-defined key is a counter.

Parameters
[in]amountthe amount to increment the counter by. This can be a positive or a negative value.
Exceptions
DittoErrorthrown if trying to update the document at an invalid key.

◆ insert()

void ditto::MutableDocumentPath::insert ( nlohmann::json  value)

Inserts a value into an array at the index defined by the preceding subscripting. This will only succeed if the value at the subscripting-defined key is an index into an array.

Parameters
[in]valuethe value to insert into the array.
Exceptions
DittoErrorthrown if trying to update the document at an invalid key.

◆ operator[]() [1/2]

MutableDocumentPath ditto::MutableDocumentPath::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.

Parameters
[in]indexthe index of the array that you wish to access in the key previously specified with the preceding subscripting.
Returns
a MutableDocumentPath with the provided index incorporated into the path.

◆ operator[]() [2/2]

MutableDocumentPath ditto::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 in the document and eventually perform an update operation on.

Parameters
[in]paththe next part of the path needed to get to the key in the document you wish to update.
Returns
a MutableDocumentPath with the provided key incorporated into the path.

◆ pop()

json ditto::MutableDocumentPath::pop ( )

Pop a value off the end of an array at the document's key defined by the preceding subscripting. This will only succeed if the value at the subscripting-defined key is an array.

Returns
the value popped off from the end of the array.
Exceptions
DittoErrorthrown if trying to update the document at an invalid key.

◆ push()

void ditto::MutableDocumentPath::push ( nlohmann::json  value)

Push a value on to the end of an array at the document's key defined by the preceding subscripting. This will only succeed if the value at the subscripting-defined key is an array.

Parameters
[in]valuethe value to push on to the array.
Exceptions
DittoErrorthrown if trying to update the document at an invalid key.

◆ remove()

void ditto::MutableDocumentPath::remove ( )

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.

◆ replace_with_counter()

void ditto::MutableDocumentPath::replace_with_counter ( bool  is_default = false)

Replace a value at the document's key defined by the preceding subscripting with a counter.

Parameters
[in]is_defaultrepresents whether or not the value is being replaced with a counter that should serve 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.

◆ set()

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

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.