44#ifndef __ADS_ObservableArray
45 #define __ADS_ObservableArray
57#include <initializer_list>
74template<
class T ,
class Policy = NoObservers >
96 typename Policy::template bind< modifications , ObservableArray >;
100 template<
class... O >
102 : f_a( n , v ) , f_sub( o... ) { }
106 template<
class... O >
108 : f_a( il ) , f_sub( o... ) { }
113 [[nodiscard]] std::size_t
size(
void )
const {
return( f_a.size() ); }
116 [[nodiscard]]
bool empty(
void )
const {
return( f_a.empty() ); }
126 [[nodiscard]]
const T *
data(
void )
const {
return( f_a.data() ); }
135 [[nodiscard]]
const std::vector< T > &
values(
void )
const {
156 void set( std::size_t i ,
const T & v ) {
158 if constexpr( Subject::template listened< Assign > )
159 if( f_sub.template live< Assign >() ) [[unlikely]] {
160 if constexpr( Subject::dynamic )
172 void add( std::size_t i ,
const T & d ) {
174 if constexpr( Subject::template listened< Assign > )
175 if( f_sub.template live< Assign >() ) [[unlikely]] {
176 if constexpr( Subject::dynamic )
177 setCold( i , f_a[ i ] + d );
179 setTold( i , f_a[ i ] + d );
187 if constexpr( Subject::template listened< Insert > )
188 if( f_sub.template live< Insert >() ) [[unlikely]] {
189 if constexpr( Subject::dynamic )
202 if constexpr( Subject::template listened< Erase > )
203 if( f_sub.template live< Erase >() ) [[unlikely]] {
204 if constexpr( Subject::dynamic )
218 template< std::input_iterator I >
248 requires( Subject::dynamic )
250 return( f_sub.attach( o ) );
256 requires( Subject::dynamic )
264 void setTold( std::size_t i ,
const T & v );
267 const T & v ) { setTold( i , v ); }
270 void pushTold(
const T & v );
272 ADS_COLD_PATH void pushCold(
const T & v ) { pushTold( v ); }
275 void popTold(
void );
279 std::vector< T > f_a;
292#include "ADS/sequence/impl/ObservableArray.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The typed modifications, beyond the book: the vocabulary by which a structure tells the observers att...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
T value_type
the values
Definition ObservableArray.h:80
const_iterator begin(void) const
the first value
Definition ObservableArray.h:129
void pop_back(void)
the last value removed, and Erased before
Definition ObservableArray.h:200
void clear(void)
all the values removed, and Cleared
std::size_t size_type
the indices
Definition ObservableArray.h:81
int attach(O &o)
attaches the observer and gives its number
Definition ObservableArray.h:247
Subject & subject(void)
the subject, for ADS::batch() and ADS::quiet()
Definition ObservableArray.h:240
typename std::vector< T >::const_iterator const_iterator
the reads, which never change the array
Definition ObservableArray.h:83
ObservableArray(std::size_t n=0, const T &v=T(), O &... o)
the array of values v, the static observers o...; no event
Definition ObservableArray.h:101
void apply(const Assign &e)
the change of the event , told as such (for UndoLog)
Definition ObservableArray.h:223
typename Policy::template bind< modifications, ObservableArray > Subject
the subject
Definition ObservableArray.h:95
bool empty(void) const
whether there is no value
Definition ObservableArray.h:116
const T & operator[](std::size_t i) const
the value of the index
Definition ObservableArray.h:120
ObservableArray(std::initializer_list< T > il, O &... o)
the array of the values of il, the static observers o...; no event
Definition ObservableArray.h:107
void push_back(const T &v)
appended, and Inserted
Definition ObservableArray.h:186
mod::list< Assign, Insert, Erase, mod::Cleared, mod::Rebuilt > modifications
the events
Definition ObservableArray.h:92
void apply(const Insert &e)
the insertion of
Definition ObservableArray.h:226
void detach(int id)
detaches the observer number
Definition ObservableArray.h:255
void add(std::size_t i, const T &d)
the value of the index raised by (+=), and Assigned
Definition ObservableArray.h:172
mod::Assigned< std::size_t, T > Assign
a value written: the index, the value before and after
Definition ObservableArray.h:86
mod::Inserted< std::size_t, std::size_t, T > Insert
a value appended: its index (the handle and the key) and the value
Definition ObservableArray.h:88
void set(std::size_t i, const T &v)
the value of the index set to , and Assigned
Definition ObservableArray.h:156
const T * data(void) const
the values, in a contiguous array
Definition ObservableArray.h:126
void apply(const Erase &e)
the erasure of
Definition ObservableArray.h:232
std::size_t size(void) const
the number of values
Definition ObservableArray.h:113
const std::vector< T > & values(void) const
the vector of the values
Definition ObservableArray.h:135
const Subject & subject(void) const
the subject
Definition ObservableArray.h:242
mod::Erased< std::size_t, std::size_t, T > Erase
the last value removed: its index and the value
Definition ObservableArray.h:90
const_iterator end(void) const
after the last value
Definition ObservableArray.h:132
void assign(I first, I last)
the values of in place of all those of the array, and Rebuilt
#define ADS_PRE(cond)
[check]
Definition Contract.h:121
Changed< Value, H, V > Assigned
the value of an item changed
Definition Modification.h:623
#define ADS_COLD_PATH
a function of a rare path: never inlined, laid out away from the hot code
Definition Portable.h:107
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition Portable.h:81
V to
the value after
Definition Modification.h:608
H h
< the value
Definition Modification.h:606
the item of handle , key and value erased, told before the removal outside a batch
Definition Modification.h:568
H h
< the value
Definition Modification.h:574
the item of handle , key and value inserted
Definition Modification.h:536
V value
the value
Definition Modification.h:544
H h
< the value
Definition Modification.h:542
a list of types, the events of a structure [see Modification.h]
Definition Modification.h:482