Couchbase Lite C++
Couchbase Lite C++ API
Loading...
Searching...
No Matches
cbl::MutableDocument Class Reference

A mutable document, whose properties can be modified and saved to a collection. More...

#include <cbl++/Document.hh>

Inheritance diagram for cbl::MutableDocument:
cbl::Document

Public Member Functions

 MutableDocument (std::nullptr_t)
 Creates a new, empty document in memory, with a randomly-generated unique ID.
 MutableDocument (std::string_view docID)
 Creates a new, empty document in memory, with the given ID.
fleece::MutableDict properties ()
 Returns a mutable document's properties as a mutable dictionary.
template<typename V>
void set (std::string_view key, const V &val)
 Sets a property key and value.
template<typename K, typename V>
void set (const K &key, const V &val)
 Sets a property key and value.
fleece::keyref< fleece::MutableDict, fleece::slice > operator[] (std::string_view key)
 A subscript operator to access a document's property value by key for either getting or setting the value.
void setProperties (fleece::MutableDict properties)
 Sets a mutable document's properties.
void setProperties (fleece::Dict properties)
 Sets a mutable document's properties.
void setPropertiesAsJSON (std::string_view json)
 Sets a mutable document's properties from a JSON Dictionary string.
 MutableDocument () noexcept
 Constructs a null reference (one that points to no object).
MutableDocumentoperator= (std::nullptr_t)
 Releases the underlying object and resets this to a null reference.
bool valid () const
 Returns true if this references an object, or false if it is a null reference.
 operator bool () const
 Returns true if this references an object (same as valid).
bool operator== (const MutableDocument &other) const
 Returns true if both sides reference the same object, or are both null references.
bool operator!= (const MutableDocument &other) const
 Returns true if the two sides reference different objects.
CBLDocument *_Nullable ref () const
 Returns a pointer to the underlying C object (CBLDocument), or NULL if this is a null reference.
 MutableDocument (const MutableDocument &other) noexcept
 Copy constructor: creates another reference to the same object as other.
 MutableDocument (MutableDocument &&other) noexcept
 Move constructor: takes over the reference from other, leaving it a null reference.
MutableDocumentoperator= (const MutableDocument &other) noexcept
 Copy assignment: replaces this reference with a reference to other's object.
MutableDocumentoperator= (MutableDocument &&other) noexcept
 Move assignment: replaces this reference with other's, leaving other a null reference.
Public Member Functions inherited from cbl::Document
std::string id () const
 A document's ID.
std::string revisionID () const
 A document's revision ID, which is a short opaque string that's guaranteed to be unique to every change made to the document.
uint64_t timestamp () const
 The hybrid logical timestamp in nanoseconds since epoch that the revision was created.
uint64_t sequence () const
 A document's current sequence in the local database.
Collection collection () const
 A document's collection or NULL for the new document that hasn't been saved.
fleece::Dict properties () const
 A document's properties as an immutable dictionary.
alloc_slice propertiesAsJSON () const
 A document's properties as JSON.
fleece::Value operator[] (std::string_view key) const
 A subscript operator to access a document's property value by key.
MutableDocument mutableCopy () const
 Creates a new mutable Document instance that refers to the same document as the original.
 Document () noexcept
 Constructs a null reference (one that points to no object).
Documentoperator= (std::nullptr_t)
 Releases the underlying object and resets this to a null reference.
bool valid () const
 Returns true if this references an object, or false if it is a null reference.
 operator bool () const
 Returns true if this references an object (same as valid).
bool operator== (const Document &other) const
 Returns true if both sides reference the same object, or are both null references.
bool operator!= (const Document &other) const
 Returns true if the two sides reference different objects.
const CBLDocument *_Nullable ref () const
 Returns a pointer to the underlying C object (const CBLDocument), or NULL if this is a null reference.
 Document (const Document &other) noexcept
 Copy constructor: creates another reference to the same object as other.
 Document (Document &&other) noexcept
 Move constructor: takes over the reference from other, leaving it a null reference.
Documentoperator= (const Document &other) noexcept
 Copy assignment: replaces this reference with a reference to other's object.
Documentoperator= (Document &&other) noexcept
 Move assignment: replaces this reference with other's, leaving other a null reference.

Protected Member Functions

 MutableDocument (CBLDocument *_Nullable ref)
 (Internal) Constructs a reference wrapping, and retaining, a C object pointer.
Protected Member Functions inherited from cbl::Document
 Document (CBLRefCounted *r)
 Document (const CBLDocument *_Nullable ref)
 (Internal) Constructs a reference wrapping, and retaining, a C object pointer.

Static Protected Member Functions

static MutableDocument adopt (CBLDocument *_Nullable d, CBLError *error)
Static Protected Member Functions inherited from cbl::Document
static Document adopt (const CBLDocument *_Nullable d, CBLError *error)
static bool checkSave (bool saveResult, CBLError &error)

Friends

class Collection
class Database
class Document

Detailed Description

A mutable document, whose properties can be modified and saved to a collection.

Constructor & Destructor Documentation

◆ MutableDocument() [1/6]

cbl::MutableDocument::MutableDocument ( std::nullptr_t )
inlineexplicit

Creates a new, empty document in memory, with a randomly-generated unique ID.

It will not be added to a database until saved.

◆ MutableDocument() [2/6]

cbl::MutableDocument::MutableDocument ( std::string_view docID)
inlineexplicit

Creates a new, empty document in memory, with the given ID.

It will not be added to a database until saved.

Note
If the given ID conflicts with a document already in the database, that will not be apparent until this document is saved. At that time, the result depends on the conflict handling mode used when saving; see the save functions for details.
Parameters
docIDThe ID of the new document, or NULL to assign a new unique ID.

◆ MutableDocument() [3/6]

cbl::MutableDocument::MutableDocument ( )
inlinenoexcept

Constructs a null reference (one that points to no object).

◆ MutableDocument() [4/6]

cbl::MutableDocument::MutableDocument ( CBLDocument *_Nullable ref)
inlineexplicitprotected

(Internal) Constructs a reference wrapping, and retaining, a C object pointer.

◆ MutableDocument() [5/6]

cbl::MutableDocument::MutableDocument ( const MutableDocument & other)
inlinenoexcept

Copy constructor: creates another reference to the same object as other.

◆ MutableDocument() [6/6]

cbl::MutableDocument::MutableDocument ( MutableDocument && other)
inlinenoexcept

Move constructor: takes over the reference from other, leaving it a null reference.

Member Function Documentation

◆ adopt()

MutableDocument cbl::MutableDocument::adopt ( CBLDocument *_Nullable d,
CBLError * error )
inlinestaticprotected

◆ operator bool()

cbl::MutableDocument::operator bool ( ) const
inlineexplicit

Returns true if this references an object (same as valid).

◆ operator!=()

bool cbl::MutableDocument::operator!= ( const MutableDocument & other) const
inline

Returns true if the two sides reference different objects.

◆ operator=() [1/3]

MutableDocument & cbl::MutableDocument::operator= ( const MutableDocument & other)
inlinenoexcept

Copy assignment: replaces this reference with a reference to other's object.

◆ operator=() [2/3]

MutableDocument & cbl::MutableDocument::operator= ( MutableDocument && other)
inlinenoexcept

Move assignment: replaces this reference with other's, leaving other a null reference.

◆ operator=() [3/3]

MutableDocument & cbl::MutableDocument::operator= ( std::nullptr_t )
inline

Releases the underlying object and resets this to a null reference.

◆ operator==()

bool cbl::MutableDocument::operator== ( const MutableDocument & other) const
inline

Returns true if both sides reference the same object, or are both null references.

◆ operator[]()

fleece::keyref< fleece::MutableDict, fleece::slice > cbl::MutableDocument::operator[] ( std::string_view key)
inline

A subscript operator to access a document's property value by key for either getting or setting the value.

Call Collection::saveDocument(MutableDocument &doc) to persist the changes.

◆ properties()

fleece::MutableDict cbl::MutableDocument::properties ( )
inline

Returns a mutable document's properties as a mutable dictionary.

You may modify this dictionary and then call Collection::saveDocument(MutableDocument &doc) to persist the changes.

Note
When accessing nested collections inside the properties as a mutable collection for modification, use fleece::MutableDict::getMutableDict() or fleece::MutableDict::getMutableArray()

◆ ref()

CBLDocument *_Nullable cbl::MutableDocument::ref ( ) const
inline

Returns a pointer to the underlying C object (CBLDocument), or NULL if this is a null reference.

◆ set() [1/2]

template<typename K, typename V>
void cbl::MutableDocument::set ( const K & key,
const V & val )
inline

Sets a property key and value.

Call Collection::saveDocument(MutableDocument &doc) to persist the changes.

◆ set() [2/2]

template<typename V>
void cbl::MutableDocument::set ( std::string_view key,
const V & val )
inline

Sets a property key and value.

Call Collection::saveDocument(MutableDocument &doc) to persist the changes.

◆ setProperties() [1/2]

void cbl::MutableDocument::setProperties ( fleece::Dict properties)
inline

Sets a mutable document's properties.

Call Collection::saveDocument(MutableDocument &doc) to persist the changes.

Parameters
propertiesThe document properties.

◆ setProperties() [2/2]

void cbl::MutableDocument::setProperties ( fleece::MutableDict properties)
inline

Sets a mutable document's properties.

Call Collection::saveDocument(MutableDocument &doc) to persist the changes.

Parameters
propertiesThe document properties.

◆ setPropertiesAsJSON()

void cbl::MutableDocument::setPropertiesAsJSON ( std::string_view json)
inline

Sets a mutable document's properties from a JSON Dictionary string.

Call Collection::saveDocument(MutableDocument &doc) to persist the changes.

Parameters
jsonA JSON Dictionary string.

◆ valid()

bool cbl::MutableDocument::valid ( ) const
inline

Returns true if this references an object, or false if it is a null reference.

◆ Collection

friend class Collection
friend

◆ Database

friend class Database
friend

◆ Document

friend class Document
friend

The documentation for this class was generated from the following file: