223 inline bool on_enter_node(
base_ptr) {
return false; }
224 inline bool on_leave_node(
base_ptr) {
return false; }
225 inline bool on_enter_children(
group_ptr) {
return false; }
226 inline bool on_leave_children(
group_ptr) {
return false; }
227 inline bool on_enter_parent(
node_ptr) {
return false; }
228 inline bool on_leave_parent(
node_ptr) {
return false; }
232template <
typename TCH>
235 if (tch.on_enter_node(
dest)) {
248 bool success =
false;
252 switch (visit_order[
i]) {
258 if (!tch.on_enter_parent(n))
260 if (tch.on_leave_parent(n))
269 if (!tch.on_enter_children(g)) {
271 if (focus != -1 && focus < (
int)g->get_nr_children() && tp->
get_policy() != TP_ALL) {
276 for (
int i=0;
i < (
int)g->get_nr_children(); ++
i)
287 if (tch.on_leave_children(g))
328 std::cerr <<
"attempt to call end method before begin in tree traversal ignored!" << std::endl;
332 std::cerr <<
"unknown character " << visit_order[
i] <<
" in traversal order" << std::endl;
348 if (tch.on_leave_node(
dest))
354template <
typename TCH>
The action class is used in tree traversals together with the traverser.
virtual bool implements_action() const
check if the current object implements the interface needed for this action
virtual bool has_begin_only() const
check whether the action has registered a single begin method or both begin and end methods
virtual bool end()
perform the leave part of the action on the current object
virtual bool begin()
perform the enter part of the action on the current object
virtual traverse_policy * get_policy() const
return the traverse_policy of the current object if available or 0 otherwise
virtual void select(base_ptr p)
make the passed object current
The group class is a node with children.
The node class keeps a pointer to its parent.
complete implementation of method actions that only call one method when entering a node
interface of a handler for traverse callbacks
virtual bool on_enter_children(group_ptr g)
called before the children of a group node g are processed, return whether these should be skipped....
virtual bool on_enter_parent(node_ptr n)
called before the parent of a node n is processed, return whether this should be skipped....
virtual bool on_enter_node(base_ptr b)
called before a node b is processed, return, whether to skip this node. If the node is skipped,...
virtual bool on_leave_node(base_ptr b)
called when a node b is left, return whether to terminate traversal
virtual bool on_leave_parent(node_ptr n)
called when the parent of a node n has been left, return whether to terminate traversal
virtual bool on_leave_children(group_ptr g)
called when the children of a group node g have been left, return whether to terminate traversal
nodes should inherit from this policy class to allow selective tree traversals
bool get_active() const
return whether the current node is active
int get_policy() const
return the policy without the stop on success flag
void set_policy(int _policy)
set a new policy, always add stop on success flag if needed
bool stop_on_failure() const
return whether to stop on failure
void set_focused_child(int _focused_child)
set the focused child
void set_active(bool _active)
set the active flag of the current node
bool stop_on_success() const
return whether to stop on success
int get_focused_child() const
return the focused child or -1 if none is focused
traverse_policy(int _policy=TP_ALL+TP_STOP_ON_SUCCESS, bool _active=true, int _focus=-1)
construct default traverse policy that visits everything
bool traverse_tmp_1(base_ptr dest, base_ptr src, bool &force_termination, TCH &tch)
traverse a single object, template over a static traverse callback handler interface
traverser(action &_a, const std::string &_visit_order="pnc", TraverseStrategy _strategy=TS_DEPTH_FIRST, bool _stop_if_not_implemented=false, bool _ignore_activation_state=false)
construct from reference on action and traversal order string
bool ignore_activation_state
whether to ignore the active flag of the traverse policy of the traversed object
bool traverse(base_ptr start, traverse_callback_handler *tch=0)
traverse a tree starting at given node according to set strategy, order and dest and previously comin...
bool traverse_tmp_2(base_ptr p, base_ptr dest, base_ptr src, traverse_policy *tp, bool &force_termination, TCH &tch)
helper method encapsulating common functionality
bool empty() const
check if pointer is not yet set
TraverseStrategy
not yet implemented
data::ref_ptr< base, true > base_ptr
ref counted pointer to base
TraversePolicy
different traversal policies
@ TP_AUTO_FOCUS
first traverse focused and then the remaining children
@ TP_STOP_ON_FAILURE
this is an optional flag for traversals with methods that return a bool. If the returned bool is true...
@ TP_STOP_ON_SUCCESS
like previous but change focus to the child, where traversal succeeded