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

An immutable, in-memory copy of a document read from a collection. More...

#include <cbl++/Document.hh>

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

Public Member Functions

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

 Document (CBLRefCounted *r)
 Document (const CBLDocument *_Nullable ref)
 (Internal) Constructs a reference wrapping, and retaining, a C object pointer.

Static Protected Member Functions

static Document adopt (const CBLDocument *_Nullable d, CBLError *error)
static bool checkSave (bool saveResult, CBLError &error)

Friends

class Collection
class Database
class Replicator

Detailed Description

An immutable, in-memory copy of a document read from a collection.

Constructor & Destructor Documentation

◆ Document() [1/5]

cbl::Document::Document ( CBLRefCounted * r)
inlineprotected

◆ Document() [2/5]

cbl::Document::Document ( )
inlinenoexcept

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

◆ Document() [3/5]

cbl::Document::Document ( const CBLDocument *_Nullable ref)
inlineexplicitprotected

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

◆ Document() [4/5]

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

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

◆ Document() [5/5]

cbl::Document::Document ( Document && other)
inlinenoexcept

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

Member Function Documentation

◆ adopt()

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

◆ checkSave()

bool cbl::Document::checkSave ( bool saveResult,
CBLError & error )
inlinestaticprotected

◆ collection()

Collection cbl::Document::collection ( ) const
inline

A document's collection or NULL for the new document that hasn't been saved.

◆ id()

std::string cbl::Document::id ( ) const
inline

A document's ID.

◆ mutableCopy()

MutableDocument cbl::Document::mutableCopy ( ) const
inline

Creates a new mutable Document instance that refers to the same document as the original.

If the original document has unsaved changes, the new one will also start out with the same changes; but mutating one document thereafter will not affect the other.

◆ operator bool()

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

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

◆ operator!=()

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

Returns true if the two sides reference different objects.

◆ operator=() [1/3]

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

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

◆ operator=() [2/3]

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

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

◆ operator=() [3/3]

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

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

◆ operator==()

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

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

◆ operator[]()

fleece::Value cbl::Document::operator[] ( std::string_view key) const
inline

A subscript operator to access a document's property value by key.

◆ properties()

fleece::Dict cbl::Document::properties ( ) const
inline

A document's properties as an immutable dictionary.

◆ propertiesAsJSON()

alloc_slice cbl::Document::propertiesAsJSON ( ) const
inline

A document's properties as JSON.

◆ ref()

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

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

◆ revisionID()

std::string cbl::Document::revisionID ( ) const
inline

A document's revision ID, which is a short opaque string that's guaranteed to be unique to every change made to the document.

If the document doesn't exist yet, this function returns an empty string.

◆ sequence()

uint64_t cbl::Document::sequence ( ) const
inline

A document's current sequence in the local database.

This number increases every time the document is saved, and a more recently saved document will have a greater sequence number than one saved earlier, so sequences may be used as an abstract 'clock' to tell relative modification times.

◆ timestamp()

uint64_t cbl::Document::timestamp ( ) const
inline

The hybrid logical timestamp in nanoseconds since epoch that the revision was created.

◆ valid()

bool cbl::Document::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

◆ Replicator

friend class Replicator
friend

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