firebase::firestore::DocumentChange

#include <document_change.h>

ADocumentChange represents a change to the documents matching a query.

Summary

DocumentChange contains the document affected and the type of change that occurred (added, modified, or removed).

Note: Firestore classes are not meant to be subclassed except for use in test mocks. Subclassing is not supported in production code and new SDK releases may break code that does so.

Constructors and Destructors

DocumentChange()
Creates an invalidDocumentChange that has to be reassigned before it can be used.
DocumentChange(constDocumentChange & other)
Copy constructor.
DocumentChange(DocumentChange && other)
Move constructor.
~DocumentChange()

Public types

Type{
  kAdded,
  kModified,
  kRemoved
}
enum
An enumeration of snapshot diff types.

Public static attributes

npos = static_cast(-1)
constexpr std::size_t
The sentinel index used as a return value to indicate no matches.

Public functions

document() const
The document affected by this change.
is_valid() const
bool
Returns true if thisDocumentChange is valid, false if it is not valid.
new_index() const
virtual std::size_t
The index of the changed document in the result set immediately after thisDocumentChange (that is, supposing that all priorDocumentChange objects and the currentDocumentChange object have been applied).
old_index() const
virtual std::size_t
The index of the changed document in the result set immediately prior to thisDocumentChange (that is, supposing that all priorDocumentChange objects have been applied).
operator=(constDocumentChange & other)
Copy assignment operator.
operator=(DocumentChange && other)
Move assignment operator.
type() const
virtualType
Returns the type of change that occurred (added, modified, or removed).

Public types

Type

Type

An enumeration of snapshot diff types.

Properties
kAdded

Indicates a new document was added to the set of documents matching the query.

kModified

Indicates a document within the query was modified.

kRemoved

Indicates a document within the query was removed (either deleted or no longer matches the query).

Public static attributes

npos

constexprstd::size_tnpos=static_cast<std::size_t>(-1)

The sentinel index used as a return value to indicate no matches.

Public functions

DocumentChange

DocumentChange()

Creates an invalidDocumentChange that has to be reassigned before it can be used.

Calling any member function on an invalidDocumentChange will be a no-op. If the function returns a value, it will return a zero, empty, or invalid value, depending on the type of the value.

DocumentChange

DocumentChange(constDocumentChange&other)

Copy constructor.

DocumentChange is immutable and can be efficiently copied (no deep copy is performed).

Details
Parameters
other
DocumentChange to copy from.

DocumentChange

DocumentChange(DocumentChange&&other)

Move constructor.

Moving is more efficient than copying for aDocumentChange. After being moved from, aDocumentChange is equivalent to its default-constructed state.

Details
Parameters
other
DocumentChange to move data from.

document

virtualDocumentSnapshotdocument()const

The document affected by this change.

Returns the newly added or modified document if thisDocumentChange is for an updated document. Returns the deleted document if this document change represents a removal.

is_valid

boolis_valid()const

Returns true if thisDocumentChange is valid, false if it is not valid.

An invalidDocumentChange could be the result of:

Details
Returns
true if thisDocumentChange is valid, false if thisDocumentChange is invalid.

new_index

virtualstd::size_tnew_index()const

The index of the changed document in the result set immediately after thisDocumentChange (that is, supposing that all priorDocumentChange objects and the currentDocumentChange object have been applied).

ReturnsDocumentChange::npos for 'removed' events.

old_index

virtualstd::size_told_index()const

The index of the changed document in the result set immediately prior to thisDocumentChange (that is, supposing that all priorDocumentChange objects have been applied).

ReturnsDocumentChange::npos for 'added' events.

operator=

DocumentChange&operator=(constDocumentChange&other)

Copy assignment operator.

DocumentChange is immutable and can be efficiently copied (no deep copy is performed).

Details
Parameters
other
DocumentChange to copy from.
Returns
Reference to the destinationDocumentChange.

operator=

DocumentChange&operator=(DocumentChange&&other)

Move assignment operator.

Moving is more efficient than copying for aDocumentChange. After being moved from, aDocumentChange is equivalent to its default-constructed state.

Details
Parameters
other
DocumentChange to move data from.
Returns
Reference to the destinationDocumentChange.

type

virtualTypetype()const

Returns the type of change that occurred (added, modified, or removed).

~DocumentChange

virtual~DocumentChange()

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-01-23 UTC.