Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
live_cells::peek_cell_state< C > Class Template Reference

Maintains the state of a peek_cell. More...

#include <peek_cell.hpp>

Inheritance diagram for live_cells::peek_cell_state< C >:
Collaboration diagram for live_cells::peek_cell_state< C >:

Public Member Functions

 peek_cell_state (key_ref k, C cell)
 Create a peek_cell state.
 
void will_update (const key_ref &k) override
 Notifies this observer that the value of the Cell identified by k is going to change.
 
void update (const key_ref &k, bool) override
 Notifies this observer that the value of the Cell identified by k has changed.
 
- Public Member Functions inherited from live_cells::cell_state
 cell_state (key_ref k)
 Create a cell state with a given key.
 
cell_stateoperator= (const cell_state &other)=delete
 
virtual void add_observer (observer::ref o)
 Add an observer to the cell's set of observers.
 
virtual void remove_observer (observer::ref o)
 Remove an observer from the cell's set of observers.
 
virtual void notify_will_update ()
 Notify the observers that the cell's value will change.
 
virtual void notify_update (bool did_change=true)
 Notify the observers that the cell's value has changed.
 

Protected Member Functions

void init () override
 Called before the first observer is added.
 
void pause () override
 Called after the last observer is removed.
 
- Protected Member Functions inherited from live_cells::cell_state
bool is_active () const
 Does the cell have at least one observer?
 

Additional Inherited Members

- Public Types inherited from live_cells::cell_state
typedef std::shared_ptr< cell_stateref
 Shared pointer to a cell_state.
 
- Public Types inherited from live_cells::observer
typedef std::shared_ptr< observerref
 Shared pointer to an observer.
 
- Protected Attributes inherited from live_cells::cell_state
key_ref key_
 Key identifying the cell corresponding to this state.
 
std::unordered_map< observer::ref, std::size_t > observers
 The set of observers observing changes to the values in the cell corresponding to this state.
 

Detailed Description

template<typename C>
class live_cells::peek_cell_state< C >

Maintains the state of a peek_cell.

This state merely adds an observer on the argument cell when the state is initialized, and removes it when its disposed.

Constructor & Destructor Documentation

◆ peek_cell_state()

template<typename C >
live_cells::peek_cell_state< C >::peek_cell_state ( key_ref k,
C cell )
inline

Create a peek_cell state.

Parameters
kKey identifying cell
cellArgument cell

Member Function Documentation

◆ init()

template<typename C >
void live_cells::peek_cell_state< C >::init ( )
inlineoverrideprotectedvirtual

Called before the first observer is added.

Subclasses should override this method to include initialization logic specific to this cell state.

Note
If the state needs to set up observers to other cells, it should be done in this method.

Reimplemented from live_cells::cell_state.

◆ pause()

template<typename C >
void live_cells::peek_cell_state< C >::pause ( )
inlineoverrideprotectedvirtual

Called after the last observer is removed.

Subclasses should override this method to include cleanup logic specific to this cell state.

Note
Observers added in init() should be removed in this method.

Reimplemented from live_cells::cell_state.

◆ update()

template<typename C >
void live_cells::peek_cell_state< C >::update ( const key_ref & k,
bool did_change )
inlineoverridevirtual

Notifies this observer that the value of the Cell identified by k has changed.

Parameters
kidentifying observable
did_changetrue if the value of the cell may have changed, false if it is know that it hasn't changed.

Implements live_cells::observer.

◆ will_update()

template<typename C >
void live_cells::peek_cell_state< C >::will_update ( const key_ref & k)
inlineoverridevirtual

Notifies this observer that the value of the Cell identified by k is going to change.

Parameters
kidentifying observable

Implements live_cells::observer.


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