firebase::database::DataSnapshot

#include <data_snapshot.h>

A DataSnapshot instance contains data from a Firebase Database location.

Summary

Any time you read Database data, you receive the data as a DataSnapshot. These are efficiently-generated and cannot be changed. To modify data, use DatabaseReference::SetValue() or DatabaseReference::RunTransaction().

Constructors and Destructors

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

Public functions

Child(const char *path) const
Get a DataSnapshot for the location at the specified relative path.
Child(const std::string & path) const
Get a DataSnapshot for the location at the specified relative path.
GetReference() const
Obtain a DatabaseReference to the source location for this snapshot.
HasChild(const char *path) const
bool
Does this DataSnapshot have data at a particular location?
HasChild(const std::string & path) const
bool
Does this DataSnapshot 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 this DataSnapshot 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=(const DataSnapshot & 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

DataSnapshot Child(
  const char *path
) const 

Get a DataSnapshot 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
A DataSnapshot corresponding to specified child location.

Child

DataSnapshot Child(
  const std::string & path
) const 

Get a DataSnapshot for the location at the specified relative path.

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

DataSnapshot

 DataSnapshot()

Default constructor.

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

DataSnapshot

 DataSnapshot(
  const DataSnapshot & 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

DatabaseReference GetReference() const 

Obtain a DatabaseReference to the source location for this snapshot.

Details
Returns
A DatabaseReference corresponding to same location as this snapshot.

HasChild

bool HasChild(
  const char *path
) const 

Does this DataSnapshot 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

bool HasChild(
  const std::string & path
) const 

Does this DataSnapshot 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_t children_count() const 

Get the number of children of this location.

Details
Returns
The number of immediate children of this snapshot.

exists

bool exists() const 

Returns true if the data is non-empty.

has_children

bool has_children() const 

Does this DataSnapshot have any children at all?

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

is_valid

bool is_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

const char * key() const 

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

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

key_string

std::string key_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=(
  const DataSnapshot & snapshot
)

Copy assignment operator.

DataSnapshots are immutable, so they can be efficiently copied.

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

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

priority

Variant priority() 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

Variant value() 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.