ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::ObservableArray< T, Policy > Class Template Reference

an array of values of T whose changes are told through Policy More...

#include <ADS/sequence/ObservableArray.h>

Public types

using value_type = T
 the values
using size_type = std::size_t
 the indices
using const_iterator = typename std::vector< T >::const_iterator
 the reads, which never change the array
using Assign = mod::Assigned< std::size_t , T >
 a value written: the index, the value before and after
using Insert = mod::Inserted< std::size_t , std::size_t , T >
 a value appended: its index (the handle and the key) and the value
using Erase = mod::Erased< std::size_t , std::size_t , T >
 the last value removed: its index and the value
using modifications
 the events
using Subject
 the subject

Public member functions

template<class... O>
 ObservableArray (std::size_t n=0, const T &v=T(), O &... o)
 the array of \( n \) values v, the static observers o...; no event
template<class... O>
 ObservableArray (std::initializer_list< T > il, O &... o)
 the array of the values of il, the static observers o...; no event
std::size_t size (void) const
 the number \( n \) of values
bool empty (void) const
 whether there is no value
const T & operator[] (std::size_t i) const
 the value of the index \( i \)
const T * data (void) const
 the values, in a contiguous array
const_iterator begin (void) const
 the first value
const_iterator end (void) const
 after the last value
const std::vector< T > & values (void) const
 the vector of the values
void set (std::size_t i, const T &v)
 the value of the index \( i \) set to \( v \), and Assigned
void add (std::size_t i, const T &d)
 the value of the index \( i \) raised by \( d \) (+=), and Assigned
void push_back (const T &v)
 \( v \) appended, and Inserted
void pop_back (void)
 the last value removed, and Erased before
void clear (void)
 all the values removed, and Cleared
template<std::input_iterator I>
void assign (I first, I last)
 the values of \( [ \mathit{first} , \mathit{last} ) \) in place of all those of the array, and Rebuilt
void apply (const Assign &e)
 the change of the event \( e \), told as such (for UndoLog)
void apply (const Insert &e)
 the insertion of \( e \)
void apply (const Erase &e)
 the erasure of \( e \)
Subject & subject (void)
 the subject, for ADS::batch() and ADS::quiet()
const Subject & subject (void) const
 the subject
template<class O>
requires ( Subject::dynamic )
int attach (O &o)
 attaches the observer \( o \) and gives its number
void detach (int id)
 detaches the observer number \( \mathit{id} \)

Detailed description

template<class T, class Policy = NoObservers>
class ADS::ObservableArray< T, Policy >

an array of values of T whose changes are told through Policy

Member typedef documentation

◆ Assign

template<class T, class Policy = NoObservers>
using ADS::ObservableArray< T, Policy >::Assign = mod::Assigned< std::size_t , T >

a value written: the index, the value before and after

◆ const_iterator

template<class T, class Policy = NoObservers>
using ADS::ObservableArray< T, Policy >::const_iterator = typename std::vector< T >::const_iterator

the reads, which never change the array

◆ Erase

template<class T, class Policy = NoObservers>
using ADS::ObservableArray< T, Policy >::Erase = mod::Erased< std::size_t , std::size_t , T >

the last value removed: its index and the value

◆ Insert

template<class T, class Policy = NoObservers>
using ADS::ObservableArray< T, Policy >::Insert = mod::Inserted< std::size_t , std::size_t , T >

a value appended: its index (the handle and the key) and the value

◆ modifications

template<class T, class Policy = NoObservers>
using ADS::ObservableArray< T, Policy >::modifications
Initial value:
a list of types, the events of a structure [see Modification.h]
Definition Modification.h:482

the events

◆ size_type

template<class T, class Policy = NoObservers>
using ADS::ObservableArray< T, Policy >::size_type = std::size_t

the indices

◆ Subject

template<class T, class Policy = NoObservers>
using ADS::ObservableArray< T, Policy >::Subject
Initial value:
typename Policy::template bind< modifications , ObservableArray >

the subject

◆ value_type

template<class T, class Policy = NoObservers>
using ADS::ObservableArray< T, Policy >::value_type = T

the values

Constructor and destructor documentation

◆ ObservableArray() [1/2]

template<class T, class Policy = NoObservers>
template<class... O>
ADS::ObservableArray< T, Policy >::ObservableArray ( std::size_t n = 0,
const T & v = T(),
O &... o )
inlineexplicit

the array of \( n \) values v, the static observers o...; no event

◆ ObservableArray() [2/2]

template<class T, class Policy = NoObservers>
template<class... O>
ADS::ObservableArray< T, Policy >::ObservableArray ( std::initializer_list< T > il,
O &... o )
inline

the array of the values of il, the static observers o...; no event

Member function documentation

◆ add()

template<class T, class Policy = NoObservers>
void ADS::ObservableArray< T, Policy >::add ( std::size_t i,
const T & d )
inline

the value of the index \( i \) raised by \( d \) (+=), and Assigned

Precondition
\( i < n \)

◆ apply() [1/3]

template<class T, class Policy = NoObservers>
void ADS::ObservableArray< T, Policy >::apply ( const Assign & e)
inline

the change of the event \( e \), told as such (for UndoLog)

Precondition
\( e \) starts from the present state

◆ apply() [2/3]

template<class T, class Policy = NoObservers>
void ADS::ObservableArray< T, Policy >::apply ( const Erase & e)
inline

the erasure of \( e \)

Precondition
\( e \) is at the index \( n - 1 \)

◆ apply() [3/3]

template<class T, class Policy = NoObservers>
void ADS::ObservableArray< T, Policy >::apply ( const Insert & e)
inline

the insertion of \( e \)

Precondition
\( e \) is at the index \( n \)

◆ assign()

template<class T, class Policy = NoObservers>
template<std::input_iterator I>
void ADS::ObservableArray< T, Policy >::assign ( I first,
I last )

the values of \( [ \mathit{first} , \mathit{last} ) \) in place of all those of the array, and Rebuilt

◆ attach()

template<class T, class Policy = NoObservers>
template<class O>
requires ( Subject::dynamic )
int ADS::ObservableArray< T, Policy >::attach ( O & o)
inline

attaches the observer \( o \) and gives its number

Precondition
no batch is open

◆ begin()

template<class T, class Policy = NoObservers>
const_iterator ADS::ObservableArray< T, Policy >::begin ( void ) const
inlinenodiscard

the first value

◆ clear()

template<class T, class Policy = NoObservers>
void ADS::ObservableArray< T, Policy >::clear ( void )

all the values removed, and Cleared

◆ data()

template<class T, class Policy = NoObservers>
const T * ADS::ObservableArray< T, Policy >::data ( void ) const
inlinenodiscard

the values, in a contiguous array

◆ detach()

template<class T, class Policy = NoObservers>
void ADS::ObservableArray< T, Policy >::detach ( int id)
inline

detaches the observer number \( \mathit{id} \)

Precondition
it is attached, no batch is open

◆ empty()

template<class T, class Policy = NoObservers>
bool ADS::ObservableArray< T, Policy >::empty ( void ) const
inlinenodiscard

whether there is no value

◆ end()

template<class T, class Policy = NoObservers>
const_iterator ADS::ObservableArray< T, Policy >::end ( void ) const
inlinenodiscard

after the last value

◆ operator[]()

template<class T, class Policy = NoObservers>
const T & ADS::ObservableArray< T, Policy >::operator[] ( std::size_t i) const
inlinenodiscard

the value of the index \( i \)

Precondition
\( i < n \)

◆ pop_back()

template<class T, class Policy = NoObservers>
void ADS::ObservableArray< T, Policy >::pop_back ( void )
inline

the last value removed, and Erased before

Precondition
the array is not empty

◆ push_back()

template<class T, class Policy = NoObservers>
void ADS::ObservableArray< T, Policy >::push_back ( const T & v)
inline

\( v \) appended, and Inserted

◆ set()

template<class T, class Policy = NoObservers>
void ADS::ObservableArray< T, Policy >::set ( std::size_t i,
const T & v )
inline

the value of the index \( i \) set to \( v \), and Assigned

In pseudocode (beyond the book), the pattern of every change, with \( \ell \) whether someone may want Assigned (a constant of the type) and \( \lambda \) whether someone wants it now:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{set}( i , v ) \cr 2 & \quad \textbf{if}\ \ell\ \textbf{and}\ \lambda\ \textbf{then} \ u \gets a[ i ];\ a[ i ] \gets v; \ \mathrm{emit}( \mathrm{Assigned}( i , u , v ) ) \cr 3 & \quad \textbf{else}\ a[ i ] \gets v \end{array}} \]

Precondition
\( i < n \)

◆ size()

template<class T, class Policy = NoObservers>
std::size_t ADS::ObservableArray< T, Policy >::size ( void ) const
inlinenodiscard

the number \( n \) of values

◆ subject() [1/2]

template<class T, class Policy = NoObservers>
Subject & ADS::ObservableArray< T, Policy >::subject ( void )
inlinenodiscard

the subject, for ADS::batch() and ADS::quiet()

◆ subject() [2/2]

template<class T, class Policy = NoObservers>
const Subject & ADS::ObservableArray< T, Policy >::subject ( void ) const
inlinenodiscard

the subject

◆ values()

template<class T, class Policy = NoObservers>
const std::vector< T > & ADS::ObservableArray< T, Policy >::values ( void ) const
inlinenodiscard

the vector of the values


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