Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
live_cells::cell Class Reference

Dynamically typed Cell container. More...

#include <observable.hpp>

Public Member Functions

template<Cell O>
 cell (O o)
 Create a container holding the Cell o.
 
template<typename T >
 cell (typed_cell< T > c)
 Create a container holding the Cell held in c.
 
void add_observer (observer::ref obs)
 Add an observer to the underlying Cell.
 
void remove_observer (observer::ref obs)
 Remove an observer from the underlying Cell.
 
key_ref key () const
 Get the key that uniquely identifies the underlying Cell.
 
template<typename T >
value () const
 Get the value held by the underlying Cell.
 
template<typename T >
void value (T value)
 Set the value of the underlying Cell.
 
template<typename T >
operator() () const
 Get the value held by the underlying Cell and track it as a dependency.
 

Protected Attributes

std::shared_ptr< internal::ref_base > obs_ref
 Pointer to the container holding the underlying cell.
 

Friends

template<typename T >
class typed_cell
 

Related Symbols

(Note that these are not member symbols.)

bool operator== (const cell &a, const cell &b)
 Compare two cell's by their keys.
 
bool operator!= (const cell &a, const cell &b)
 Compare two cell's by their keys.
 

Detailed Description

Dynamically typed Cell container.

This class erases the types of Cell's, so that a cell can be used and stored in containers, when its exact type is not known at compile-time.

Constructor & Destructor Documentation

◆ cell() [1/2]

template<Cell O>
live_cells::cell::cell ( O o)
inline

Create a container holding the Cell o.

Parameters
oThe cell to hold in the container

◆ cell() [2/2]

template<typename T >
live_cells::cell::cell ( typed_cell< T > c)
inline

Create a container holding the Cell held in c.

Parameters
cA typed_cell container.

Member Function Documentation

◆ add_observer()

void live_cells::cell::add_observer ( observer::ref obs)
inline

Add an observer to the underlying Cell.

Parameters
obsThe observer to add to the cell.

◆ key()

key_ref live_cells::cell::key ( ) const
inline

Get the key that uniquely identifies the underlying Cell.

Returns
The key identifying the underlying cell.

◆ operator()()

template<typename T >
T live_cells::cell::operator() ( ) const
inline

Get the value held by the underlying Cell and track it as a dependency.

This method attempts to cast the underlying Cell to a cell holding a value of type T. If the underlying cell does not hold a value of type T, an std::bad_cast exception is thrown.

Returns
The value of the underlying cell.

◆ remove_observer()

void live_cells::cell::remove_observer ( observer::ref obs)
inline

Remove an observer from the underlying Cell.

Note
The observer is only removed when this method is called the same number of times add_observer was called for the same observer obs.
Parameters
obsThe observer to remove from the cell.

◆ value() [1/2]

template<typename T >
T live_cells::cell::value ( ) const
inline

Get the value held by the underlying Cell.

This method attempts to cast the underlying Cell to a cell holding a value of type T. If the underlying cell does not hold a value of type T, an std::bad_cast exception is thrown.

Returns
The value of the underlying cell.

◆ value() [2/2]

template<typename T >
void live_cells::cell::value ( T value)
inline

Set the value of the underlying Cell.

This method attempts to cast the underlying cell to a cell holding a value of type T. If the underlying cell does not hold a value of type T, or is not a MutableCell, an std::bad_cast exception is thrown.

Parameters
valueThe value to set the underlying cell to.

Friends And Related Symbol Documentation

◆ operator!=()

bool operator!= ( const cell & a,
const cell & b )
related

Compare two cell's by their keys.

Parameters
aA dynamically typed cell
bA dynamically typed cell
Returns
true if the key of a is not equal to the key of b.

◆ operator==()

bool operator== ( const cell & a,
const cell & b )
related

Compare two cell's by their keys.

Parameters
aA dynamically typed cell
bA dynamically typed cell
Returns
true if the key of a is equal to the key of b.

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