|
| 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
|
|
| 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} \)
|
template<class T, class Policy = NoObservers>
class ADS::ObservableArray< T, Policy >
an array of values of T whose changes are told through Policy
template<class T, class Policy = NoObservers>
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 \)