Ditto 3.0.11
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ditto::AbstractDocumentPath 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 <AbstractDocumentPath.hpp>

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

Public Member Functions

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

Protected Member Functions

 AbstractDocumentPath (CDocument_t const *document, DocumentId id, std::string initial_path)
 Constructs a new initial AbstractDocumentPath for a document.
 
 AbstractDocumentPath (const AbstractDocumentPath *document_path, std::string key)
 Constructs a new AbstractDocumentPath from an existing AbstractDocumentPath by appending a path.
 
 AbstractDocumentPath (const AbstractDocumentPath *document_path, std::size_t index)
 Constructs a new AbstractDocumentPath from an existing AbstractDocumentPath by appending an index.
 
 AbstractDocumentPath (const AbstractDocumentPath *document_path)
 Copy constructor.
 
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.
 
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.
 
template<typename T >
std::shared_ptr< T > get_mut_object_or_default (json_callback json_cb, PathAccessorType path_type) const
 

Protected Attributes

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.

Constructor & Destructor Documentation

◆ AbstractDocumentPath() [1/4]

ditto::AbstractDocumentPath::AbstractDocumentPath ( CDocument_t const *  document,
DocumentId  id,
std::string  initial_path 
)
protected

Constructs a new initial AbstractDocumentPath for a document.

Parameters
[in]documentA pointer to the Rust CDocument_t.
[in]idThe ID of the Document to which this path corresponds.
[in]initial_pathThe key for the initial path into the document. This must always be a string key (i.e. a map key) rather than an array index as every top level Document is a map. The initial_path will be sanitized within the constructor.

◆ AbstractDocumentPath() [2/4]

ditto::AbstractDocumentPath::AbstractDocumentPath ( const AbstractDocumentPath document_path,
std::string  key 
)
protected

Constructs a new AbstractDocumentPath from an existing AbstractDocumentPath by appending a path.

Parameters
[in]documentPathThe existing document path.
[in]keyThe path component to append. It will be sanitized internally

◆ AbstractDocumentPath() [3/4]

ditto::AbstractDocumentPath::AbstractDocumentPath ( const AbstractDocumentPath document_path,
std::size_t  index 
)
protected

Constructs a new AbstractDocumentPath from an existing AbstractDocumentPath by appending an index.

Parameters
[in]documentPathThe existing document path.
[in]keyThe path component to append.

◆ AbstractDocumentPath() [4/4]

ditto::AbstractDocumentPath::AbstractDocumentPath ( const AbstractDocumentPath document_path)
protected

Copy constructor.

Parameters
document_path

Member Function Documentation

◆ get_bool_value()

bool ditto::AbstractDocumentPath::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.

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::AbstractDocumentPath::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.

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::AbstractDocumentPath::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.

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::AbstractDocumentPath::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.

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::AbstractDocumentPath::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.

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

template<typename T >
template std::shared_ptr< Rga > ditto::AbstractDocumentPath::get_object_or_default< Rga > ( json_callback  json_cb,
PathAccessorType  path_type 
) const
protected

Helper function to retrieve crdt objects.

This is done here because safer_ffi_utils in not included within Ditto.h.

Template Parameters
T
Parameters
json_cbcallback to check if the retrieved json value has the right typing. If no callback is provided - nullptr - this check is simply skipped.
path_typeexpected type at path
Returns
std::shared_ptr<T>

◆ get_primitive_or_default()

template<typename T >
T ditto::AbstractDocumentPath::get_primitive_or_default ( default_value,
json_callback  json_cb,
PathAccessorType  path_type 
) const
protected

Get the primitive stored at a given path or the correspondign default value.

Template Parameters
Ttype wanted
Parameters
default_valuedefault value T if it cannot be retrieved from the document.

◆ get_string_value()

std::string ditto::AbstractDocumentPath::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.

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.

◆ operator[]() [1/2]

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

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

◆ operator[]() [2/2]

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

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