firebase::database::DataSnapshot

#include <data_snapshot.h>

ADataSnapshot instance contains data from a FirebaseDatabase location.

Summary

Any time you readDatabase data, you receive the data as aDataSnapshot. These are efficiently-generated and cannot be changed. To modify data, useDatabaseReference::SetValue() orDatabaseReference::RunTransaction().

Constructors and Destructors

DataSnapshot()
Default constructor.
DataSnapshot(constDataSnapshot & snapshot)
Copy constructor.
DataSnapshot(DataSnapshot && snapshot)
Move constructor.
~DataSnapshot()
Destructor.

Public functions

Child(const char *path) const
Get aDataSnapshot for the location at the specified relative path.
Child(const std::string & path) const
Get aDataSnapshot for the location at the specified relative path.
GetReference() const
Obtain aDatabaseReference to the source location for this snapshot.
HasChild(const char *path) const
bool
Does thisDataSnapshot have data at a particular location?
HasChild(const std::string & path) const
bool
Does thisDataSnapshot have data at a particular location?
children() const
std::vector<DataSnapshot >
Get all the immediate children of this location.
children_count() const
size_t
Get the number of children of this location.
exists() const
bool
Returns true if the data is non-empty.
has_children() const
bool
Does thisDataSnapshot have any children at all?
is_valid() const
bool
Returns true if this snapshot is valid, false if it is not valid.
key() const
const char *
Get the key name of the source location of this snapshot.
key_string() const
std::string
Get the key name of the source location of this snapshot.
operator=(constDataSnapshot & snapshot)
Copy assignment operator.
operator=(DataSnapshot && snapshot)
Move assignment operator.
priority() const
Get the priority of the data contained in this snapshot.
value() const
Get the value of the data contained in this snapshot.

Public functions

Child

DataSnapshotChild(constchar*path)const

Get aDataSnapshot for the location at the specified relative path.

Details
Parameters
path
Path relative to this snapshot's location. It only needs to be valid during this call.
Returns
ADataSnapshot corresponding to specified child location.

Child

DataSnapshotChild(conststd::string&path)const

Get aDataSnapshot for the location at the specified relative path.

Details
Parameters
path
Path relative to this snapshot's location.
Returns
ADataSnapshot corresponding to specified child location.

DataSnapshot

DataSnapshot()

Default constructor.

ThisDataSnapshot contains nothing and is considered invalid (i.e.is_valid() == false). Use this to construct an emptyDataSnapshot that you will later populate with data from a database callback.

DataSnapshot

DataSnapshot(constDataSnapshot&snapshot)

Copy constructor.

DataSnapshots are immutable, so they can be efficiently copied.

Details
Parameters
snapshot
DataSnapshot to copy.

DataSnapshot

DataSnapshot(DataSnapshot&&snapshot)

Move constructor.

DataSnapshots are immutable, so they can be efficiently moved.

Details
Parameters
snapshot
DataSnapshot to move into this one.

GetReference

DatabaseReferenceGetReference()const

Obtain aDatabaseReference to the source location for this snapshot.

Details
Returns
ADatabaseReference corresponding to same location as this snapshot.

HasChild

boolHasChild(constchar*path)const

Does thisDataSnapshot have data at a particular location?

Details
Parameters
path
Path relative to this snapshot's location. The pointer only needs to be valid during this call.
Returns
True if the snapshot has data at the specified location, false if not.

HasChild

boolHasChild(conststd::string&path)const

Does thisDataSnapshot have data at a particular location?

Details
Parameters
path
Path relative to this snapshot's location.
Returns
True if the snapshot has data at the specified location, false if not.

children

std::vector<DataSnapshot>children()const

Get all the immediate children of this location.

Details
Returns
The immediate children of this snapshot.

children_count

size_tchildren_count()const

Get the number of children of this location.

Details
Returns
The number of immediate children of this snapshot.

exists

boolexists()const

Returns true if the data is non-empty.

has_children

boolhas_children()const

Does thisDataSnapshot have any children at all?

Details
Returns
True if the snapshot has any children, false otherwise.

is_valid

boolis_valid()const

Returns true if this snapshot is valid, false if it is not valid.

An invalid snapshot could be returned by a transaction where an error has occurred.

Details
Returns
true if this snapshot is valid, false if this snapshot is invalid.

key

constchar*key()const

Get the key name of the source location of this snapshot.

Note: The returned pointer is only guaranteed to be valid while theDataSnapshot is still in memory.

Details
Returns
Key name of the source location of this snapshot.

key_string

std::stringkey_string()const

Get the key name of the source location of this snapshot.

Details
Returns
Key name of the source location of this snapshot.

operator=

DataSnapshot&operator=(constDataSnapshot&snapshot)

Copy assignment operator.

DataSnapshots are immutable, so they can be efficiently copied.

Details
Parameters
snapshot
DataSnapshot to copy.
Returns
Reference to the destinationDataSnapshot.

operator=

DataSnapshot&operator=(DataSnapshot&&snapshot)

Move assignment operator.

DataSnapshots are immutable, so they can be efficiently moved.

Details
Parameters
snapshot
DataSnapshot to move into this one.
Returns
Reference to this destinationDataSnapshot.

priority

Variantpriority()const

Get the priority of the data contained in this snapshot.

Details
Returns
The value of this location's Priority relative to its siblings.

value

Variantvalue()const

Get the value of the data contained in this snapshot.

Details
Returns
The value of the data contained in this location.

~DataSnapshot

~DataSnapshot()

Destructor.

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.