|
| template<class... O> |
| | ObservedGraph (G &g, O &... o) |
| | the wrapper of \( g \), the static observers o...; \( g \) must stay alive, and change only through the wrapper
|
| | ObservedGraph (const ObservedGraph &)=delete |
| | not copied
|
| ObservedGraph & | operator= (const ObservedGraph &)=delete |
| | not assigned
|
| const G & | graph (void) const |
| | the graph
|
| unsigned | mask (void) const |
| | the union of the masks of the observers
|
| bool | listening (unsigned k=GraphEvents::ALL) const |
| | whether anyone listens to one of the kinds \( k \)
|
| std::size_t | built (void) const |
| | the events built so far, sent or collected (none when no one listens)
|
| Subject & | subject (void) |
| | the subject, for ADS::batch() and ADS::quiet()
|
| const Subject & | subject (void) const |
| | the subject
|
| const G & | observed (void) const |
| | what the audits of the observers read: the graph
|
| bool | directed (void) const |
| | whether the graph is oriented
|
| int | n (void) const |
| | the number of nodes
|
| int | bound (void) const |
| | a bound of the numbers of the nodes
|
| bool | hasNode (int u) const |
| | whether \( u \) is a node
|
| std::vector< int > | V (void) const |
| | the nodes
|
| std::vector< int > | adj (int u) const |
| | the nodes adjacent to \( u \)
|
| template<class F> |
| void | forEachAdj (int u, F &&f) const |
| | f( v ) for each node \( v \) adjacent to \( u \)
|
| template<class F> |
| void | forEachEdge (int u, F &&f) const |
| | f( v , w ) for each edge \( ( u , v ) \) of weight \( w \)
|
| std::optional< Weight > | weight (int u, int v) const |
| | the weight of \( ( u , v ) \), nothing if there is no such edge
|
| int | insertNode (void) |
| | insertNode() of the graph, and NodeInserted
|
| void | insertEdge (int u, int v, const Weight &w=Weight()) |
| | insertEdge() of the graph, and EdgeInserted, or WeightChanged if the edge was there
|
| void | deleteEdge (int u, int v) |
| | deleteEdge() of the graph, and EdgeDeleted if the edge was there
|
| void | deleteNode (int u) |
| | EdgeDeleted for each edge of \( u \), deleteNode() of the graph, and NodeDeleted
|
| bool | setWeight (int u, int v, const Weight &w) |
| | the weight of the edge \( ( u , v ) \) set to \( w \), and WeightChanged; false, and nothing, if there is no such edge
|
| void | apply (const EdgeInserted< Weight > &e) |
| | the insertion of the edge of \( e \), for UndoLog
|
| void | apply (const EdgeDeleted< Weight > &e) |
| | the deletion of the edge of \( e \), for UndoLog
|
| void | apply (const WeightChanged< Weight > &e) |
| | the change of the weight of \( e \), for UndoLog
|
| std::size_t | checkpoint (void) const |
| | a checkpoint of the batches open, the number of their events so far: with rollback() it makes the wrapper undoable, so that a batch that exits by an exception leaves the graph and the observers as they were [see Batch]
|
| bool | revertible (std::size_t t) const |
| | whether the changes since the checkpoint \( t \) can be undone: all on edges, and every kind listened to, so that each is collected
|
| void | rollback (std::size_t t) |
| | back to the checkpoint \( t \) of the batches open: the changes collected since undone by their inverses, the last first (under the mute of the batch, which tells nobody); the graph is then the one at \( t \), up to the order of the edges in its lists
|
template<class D>
requires ( Subject::dynamic ) |
| int | attach (D &o) |
| | attaches the observer \( o \), of either form, its mask read now, and gives its number
|
| void | detach (int id) |
| | detaches the observer number \( \mathit{id} \)
|
| Batch | batch (void) |
| | opens a channel: the events are collected until it is closed
|
| int | depth (void) const |
| | the depth of the channels open, \( 0 \) if none
|
template<Graph G, class Policy = NoObservers>
class ADS::ObservedGraph< G, Policy >
the graph \( g \), whose changes are sent through the subject policy Policy [see Modification.h]
template<Graph G, class Policy = NoObservers>
the weight of the edge \( ( u , v ) \) set to \( w \), and WeightChanged; false, and nothing, if there is no such edge
In pseudocode (beyond the book), the pattern of every change, with \( k \) the kind of its event, \( M \) the union of the masks, \( d \) the depth of the channels and \( B \) the events collected:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{setWeight}( u , v , w ) \cr
2 & \quad \textbf{if}\ k \notin M\ \textbf{then}\ \text{change } g;
\ \textbf{return} \cr
3 & \quad w_0 \gets \text{the weight of } ( u , v ) \text{ in } g;
\ \text{change } g \cr
4 & \quad e \gets \mathrm{WeightChanged}( u , v , w_0 , w ) \cr
5 & \quad \textbf{if}\ d > 0\ \textbf{then}\ \text{append } e
\text{ to } B \cr
6 & \quad \textbf{else foreach}\ \text{observer } o\ \textbf{with}
\ k \in M_o\ \textbf{do}\ o.\mathrm{notify}( e )
\end{array}}
\]
The test of line 2 is false at compile time when nobody may listen (NoObservers, or static observers that do not want \( k \)), and the change is then the code of the graph.
- Precondition
- \( u \) and \( v \) are nodes