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(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.
GetChildren() const
FIREBASE_DEPRECATED std::vector< DataSnapshot >
Deprecated. Renamed to children().
Get all the immediate children of this location.
GetChildrenCount() const
FIREBASE_DEPRECATED size_t
Deprecated. Renamed to children_count().
Get the number of children of this location.
GetKey() const
FIREBASE_DEPRECATED const char *
Deprecated. Renamed to key().
Get the key name of the source location of this snapshot.
GetKeyString() const
FIREBASE_DEPRECATED std::string
Deprecated. Renamed to key_string();
Get the key name of the source location of this snapshot.
GetPriority() const
FIREBASE_DEPRECATED Variant
Deprecated. Renamed to priority().
Get the priority of the data contained in this snapshot.
GetReference() const
Obtain a DatabaseReference to the source location for this snapshot.
GetValue() const
FIREBASE_DEPRECATED Variant
Deprecated. Renamed to Value().
Get the value of the data contained in 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?
HasChildren() const
FIREBASE_DEPRECATED bool
Deprecated. Renamed to has_children().
Does this DataSnapshot have any children at all?
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(
  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.

GetChildren

FIREBASE_DEPRECATED std::vector< DataSnapshot > GetChildren() const 

Get all the immediate children of this location.

Deprecated. Renamed to children().

Details
Returns
The immediate children of this snapshot.

GetChildrenCount

FIREBASE_DEPRECATED size_t GetChildrenCount() const 

Get the number of children of this location.

Deprecated. Renamed to children_count().

Details
Returns
The number of immediate children of this snapshot.

GetKey

FIREBASE_DEPRECATED const char * GetKey() const 

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

Note:The returned pointer is only guaranteed to be valid while the DataSnapshot is still in memory. Deprecated. Renamed to key().

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

GetKeyString

FIREBASE_DEPRECATED std::string GetKeyString() const 

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

Deprecated. Renamed to key_string();

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

GetPriority

FIREBASE_DEPRECATED Variant GetPriority() const 

Get the priority of the data contained in this snapshot.

Deprecated. Renamed to priority().

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

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.

GetValue

FIREBASE_DEPRECATED Variant GetValue() const 

Get the value of the data contained in this snapshot.

Deprecated. Renamed to Value().

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

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.

HasChildren

FIREBASE_DEPRECATED bool HasChildren() const 

Does this DataSnapshot have any children at all?

Deprecated. Renamed to has_children().

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

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 occured.

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.

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

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.

Send feedback about...

Need help? Visit our support page.