spot 2.12.2
|
Iterate over the successors of a state. More...
#include <spot/twa/twa.hh>
Public Member Functions | |
Iteration | |
virtual bool | first ()=0 |
Position the iterator on the first successor (if any). More... | |
virtual bool | next ()=0 |
Jump to the next successor (if any). More... | |
virtual bool | done () const =0 |
Check whether the iteration is finished. More... | |
Inspection | |
virtual const state * | dst () const =0 |
Get the destination state of the current edge. More... | |
virtual bdd | cond () const =0 |
Get the condition on the edge leading to this successor. More... | |
virtual acc_cond::mark_t | acc () const =0 |
Get the acceptance mark of the edge leading to this successor. More... | |
Iterate over the successors of a state.
This class provides the basic functionality required to iterate over the set of edges leaving a given state. Instance of twa_succ_iterator should normally not be created directly. Instead, they are created by passing a "source" state to twa::succ_iter(), which will create the instance of twa_succ_iterator to iterate over the successors of that state.
This twa_succ_iterator class offers two types of services, offered by two groups of methods. The methods first(), next(), and done() allow iteration over the set of outgoing edges. The methods cond(), acc(), dst(), allow inspecting the current edge.
The twa_succ_iterator is usually subclassed so that iteration methods and accessor methods can be implemented differently in different automata. In particular, this interface allows computing the set of successors on the fly if needed.
The iterator can be used to iterate over all successors in a loop as follows:
If there are n successors, there will be 1 call to first(), n calls to next() and n+1 calls to done(), so a total of 2(n+1) calls to virtual methods just to handle the iteration. For this reason, we usually favor the following more efficient way of performing the same loop:
This loop uses the return value of first() and next() to save n+1 calls to done().
|
pure virtual |
Get the acceptance mark of the edge leading to this successor.
Implemented in spot::fair_kripke_succ_iterator, spot::kripke_succ_iterator, spot::ta_explicit_succ_iterator, spot::ta_succ_iterator_product, spot::tgta_succ_iterator_product, spot::taa_succ_iterator, and spot::twa_graph_succ_iterator< Graph >.
|
pure virtual |
Get the condition on the edge leading to this successor.
This is a Boolean function of atomic propositions.
Implemented in spot::fair_kripke_succ_iterator, spot::kripke_succ_iterator, spot::ta_explicit_succ_iterator, spot::ta_succ_iterator_product, spot::tgta_succ_iterator_product, spot::taa_succ_iterator, and spot::twa_graph_succ_iterator< Graph >.
|
pure virtual |
Check whether the iteration is finished.
This function should be called after any call to first()
or next()
and before any enquiry about the current state.
The typical use case of done() is in a for
loop such as:
for (s->first(); !s->done(); s->next()) ...
It is incorrect to call done() if first() hasn't been called before. If done() returns true, it is invalid to call next(), cond(), acc(), or dst().
Implemented in spot::kripke_graph_succ_iterator< Graph >, spot::ta_explicit_succ_iterator, spot::ta_succ_iterator_product, spot::tgta_succ_iterator_product, spot::taa_succ_iterator, and spot::twa_graph_succ_iterator< Graph >.
|
pure virtual |
Get the destination state of the current edge.
Each call to dst() (even several times on the same edge) creates a new state that has to be destroyed (see state::destroy()) by the caller after it is no longer used.
Note that the same state may occur at different points in the iteration, as different outgoing edges (usually with different labels or acceptance membership) may go to the same state.
Implemented in spot::kripke_graph_succ_iterator< Graph >, spot::ta_explicit_succ_iterator, spot::ta_succ_iterator_product, spot::tgta_succ_iterator_product, spot::taa_succ_iterator, and spot::twa_graph_succ_iterator< Graph >.
|
pure virtual |
Position the iterator on the first successor (if any).
This method can be called several times in order to make multiple passes over successors.
done()
(or better: check the return value of first()) to ensure there is a successor, even after first()
. A common trap is to assume that there is at least one successor: this is wrong.If first() returns false, it is invalid to call next(), cond(), acc(), or dst().
Implemented in spot::kripke_graph_succ_iterator< Graph >, spot::ta_explicit_succ_iterator, spot::ta_succ_iterator_product, spot::tgta_succ_iterator_product, spot::taa_succ_iterator, and spot::twa_graph_succ_iterator< Graph >.
|
pure virtual |
Jump to the next successor (if any).
done()
(or better: check the return value of next()) to ensure there is a successor.If next() returns false, it is invalid to call next() again, or to call cond(), acc() or dst().
Implemented in spot::kripke_graph_succ_iterator< Graph >, spot::ta_explicit_succ_iterator, spot::ta_succ_iterator_product, spot::tgta_succ_iterator_product, spot::taa_succ_iterator, and spot::twa_graph_succ_iterator< Graph >.