SheafSystem  0.0.0.0
depth_first_iterator.h
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
18 // Interface for class depth_first_iterator
19 
20 
21 #ifndef DEPTH_FIRST_ITERATOR_H
22 #define DEPTH_FIRST_ITERATOR_H
23 
24 #ifndef SHEAF_DLL_SPEC_H
25 #include "SheafSystem/sheaf_dll_spec.h"
26 #endif
27 
28 #ifndef ANY_H
29 #include "SheafSystem/any.h"
30 #endif
31 
32 #ifndef POSET_STATE_HANDLE_H
33 #include "SheafSystem/poset_state_handle.h"
34 #endif
35 
36 #ifndef STD_STACK_H
37 #include "SheafSystem/std_stack.h"
38 #endif
39 
40 #ifndef SUBPOSET_H
41 #include "SheafSystem/subposet.h"
42 #endif
43 
44 #ifndef TOTAL_POSET_MEMBER_H
45 #include "SheafSystem/total_poset_member.h"
46 #endif
47 
48 namespace sheaf
49 {
50 
51 class zn_to_bool;
52 
79 class SHEAF_DLL_SPEC depth_first_iterator : public any
80 {
81 
82 
83 public:
84 
85  // CANONICAL MEMBERS
86 
90  depth_first_iterator& operator=(const depth_first_iterator& xother);
91 
95  virtual ~depth_first_iterator();
96 
100  virtual bool is_ancestor_of(const any* other) const;
101 
105  virtual depth_first_iterator* clone() const;
106 
110  bool invariant() const;
111 
112  // SOME USEFUL CONSTANTS
113 
117  static const char* NULL_FILTER;
118 
119 /* /// */
120 /* /// Iteration directions */
121 /* /// */
122 /* static const bool DOWN; */
123 
124 /* /// */
125 /* /// Iteration directions */
126 /* /// */
127 /* static const bool UP; */
128 
129 /* /// */
130 /* /// Iteration marker reset control */
131 /* /// */
132 /* static const bool RESET; */
133 
134 /* /// */
135 /* /// Iteration marker reset control */
136 /* /// */
137 /* static const bool NO_RESET; */
138 
139 /* /// */
140 /* /// Iteration strictness control */
141 /* /// */
142 /* static const bool STRICT; */
143 
144 /* /// */
145 /* /// Iteration strictness control */
146 /* /// */
147 /* static const bool NOT_STRICT; */
148 
155  {
156  PREORDER, // Member is visited before its inferiors, exports PREVISIT_ACTION.
157  POSTORDER, // Member is visited after its inferiors, exports POSTVISIT_ACTION.
158  LINKORDER, // Visits links; exports LINK_ACTION.
159  BIORDER, // Exports PREVISIT_ACTION and POSTVISIT_ACTION.
160  TRIORDER, // Exports PREVISIT_ACTION, POSTVISIT_ACTION, and LINK_ACTION.
161  NOT_AN_ORDER
162  };
163 
169  {
170  PREVISIT_ACTION,
171  LINK_ACTION,
172  POSTVISIT_ACTION,
173  NOT_AN_ACTION
174  };
175 
176  // ITERATOR FACET
177 
182  order_type order() const;
183 
184  //$$SCRIBBLE jebutler const correctness
185 
190  virtual bool is_initialized() const;
191 
196  virtual abstract_poset_member& anchor();
197 
202  virtual const abstract_poset_member& anchor() const;
203 
207  virtual bool anchor_is_ancestor_of(const abstract_poset_member& xmbr) const;
208 
212  bool descending() const;
213 
217  bool strict() const;
218 
223  subposet& filter();
224 
228  bool is_done() const;
229 
233  virtual void force_is_done();
234 
238  inline void next()
239  {
240  next(false);
241  };
242 
249  inline void truncate()
250  {
251  next(true);
252  };
253 
262  virtual void next(bool xtruncate);
263 
267  virtual void reset(bool xreset_markers = true);
268 
273  int ct(bool xreset = false);
274 
278  bool has_visited(pod_index_type xhub_id) const;
279 
283  bool has_visited(const scoped_index& xid) const;
284 
288  bool has_visited(const abstract_poset_member* xmbr) const;
289 
295  void put_has_visited(pod_index_type xhub_id, bool xvalue);
296 
302  void put_has_visited(const scoped_index& xid, bool xvalue);
303 
308  bool visit_once() const;
309 
313  void put_visit_once(bool xvisit_once);
314 
319  bool is_maximal() const;
320 
324  const scoped_index& greater_index() const;
325 
329  const scoped_index& lesser_index() const;
330 
335  action_type action() const;
336 
345  void erase_cover();
346 
347  // INDEX ITERATOR FACET
348 
352  const scoped_index& index() const;
353 
357  size_t depth() const;
358 
359 protected:
360 
365 
370 
374  void first();
375 
382  void mark_visited(abstract_poset_member* xmbr);
383 
390  void mark_not_visited(abstract_poset_member* xmbr);
391 
396  virtual void attach_item();
397 
402  virtual void detach_item();
403 
407  void initialize_order(order_type xorder);
408 
412  void initialize_traversal(const abstract_poset_member& xanchor);
413 
417  void initialize_traversal(pod_index_type xanchor_hub_id);
418 
422  void initialize_traversal(const scoped_index& xanchor_id);
423 
427  void initialize_anchor(const abstract_poset_member& xanchor);
428 
432  virtual void initialize_has_visited(const abstract_poset_member& xanchor);
433 
440  zn_to_bool* has_visited() const;
441 
448  void put_has_visited(zn_to_bool* xhas_visited);
449 
450 
454  bool filter(pod_index_type xhub_id) const
455  {
456  return (*_filter)[xhub_id];
457  };
458 
462  bool filter(const scoped_index& xid) const
463  {
464  return (*_filter)[xid.hub_pod()];
465  };
466 
470  void initialize_filter();
471 
476  void initialize_filter(const subposet& xfilter);
477 
482  void initialize_filter(pod_index_type xfilter_hub_id);
483 
488  void initialize_filter(const scoped_index& xfilter_id);
489 
494  void initialize_filter(const std::string& xfilter_name);
495 
499  void release_cover_id_space_iterators();
500 
505 
511 
517 
522 
527 
532 
537 
542 
546  bool _strict;
547 
552 
557  {
558  FIRST,
559  INIT_COVER_ITERATOR,
560  TEST_HAS_VISITED,
561  INC_COVER_ITERATOR,
562  ERASE_COVER_ITERATOR,
563  DESCEND,
564  TEST_PATH_TAIL,
565  ASCEND,
566  EXECUTE_PREVISIT_ACTION,
567  EXECUTE_LINK_ACTION,
568  EXECUTE_POSTVISIT_ACTION,
569  FINISH,
570  NOT_A_STATE // Must be last; used for array bounds.
571  };
572 
577  {
578  PASS,
579  FAIL
580  };
581 
585  static const char* iterator_state_names[NOT_A_STATE+1];
586 
591  const iterator_state (*_transition_fcn)[FAIL+1];
592 
598  static const iterator_state PREORDER_TRANSITION_FCN[NOT_A_STATE-1][FAIL+1];
599 
605  static const iterator_state POSTORDER_TRANSITION_FCN[NOT_A_STATE-1][FAIL+1];
606 
612  static const iterator_state LINKORDER_TRANSITION_FCN[NOT_A_STATE-1][FAIL+1];
613 
619  static const iterator_state BIORDER_TRANSITION_FCN[NOT_A_STATE-1][FAIL+1];
620 
626  static const iterator_state TRIORDER_TRANSITION_FCN[NOT_A_STATE-1][FAIL+1];
627 
628  typedef const iterator_state (*transition_fcn_type)[FAIL+1];
629 
633  static const transition_fcn_type STD_TRANSITION_FCNS[NOT_AN_ORDER+1];
634 
639 
645 
651 
656  std::stack<index_space_iterator*> _path_tail;
657 
663  std::stack<pod_index_type> _filtered_path_tail;
664 
670 
671 private:
672 
679  zn_to_bool* _has_visited;
680 
688  zn_to_bool* _filter;
689 
690 };
691 
692 } // namespace sheaf
693 
694 #endif // ifndef DEPTH_FIRST_ITERATOR_H
A client handle for a subposet.
Definition: subposet.h:86
void truncate()
Makes this the next member of the subset which is not less than old this, i.e. the depth-first descen...
An abstract iterator over the ids of an id space.
abstract_poset_member * _anchor
The top member of the down set being iterated over.
static const char * NULL_FILTER
Placeholder for null filter.
action_type _action
The type of action the client should take; the state of the iterator.
std::stack< pod_index_type > _filtered_path_tail
The tail of the filtered path to the current member of the iteration. Contains only members which pas...
bool _visit_once
True if traversal should only visit a member once; that is, it should not revisit members it has alre...
order_type
The types of order in which the iterator will visit the members of the poset. Determines which action...
subposet _client_filter
The filter specified by the client.
Abstract base class with useful features for all objects.
Definition: any.h:39
A map from Zn (the integers mod n) to bools. A characteristic function used to represent subsets of Z...
Definition: zn_to_bool.h:52
iterator_token
The input tokens for the finite state machine.
action_type
The types of action a client should take when the iterator returns control to the client...
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
scoped_index _lesser_index
The index of the lesser member of the current link.
bool filter(pod_index_type xhub_id) const
The value of the filter at hub id xhub_id.
bool _new_filter
True if this allocated a new filter;.
void next()
Makes this the next member of the subset.
scoped_index _greater_index
The index of the greater member of the current link.
index_space_iterator * _path_head
The head of the path to the current member of the iteration lesser_index() == this->index() == **_pat...
index_space_iterator * _path_head_lc
The lower cover iterator for the head of the path to the current member of the iteration.
bool _descending
True if iterating over the up/down set of anchor.
iterator_state _state
The current state of iteration.
std::stack< index_space_iterator * > _path_tail
The tail of the path to the current member of the iteration greater_index() == **(_path_tail.top()) == greater member of current link.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
iterator_state
The states for the finite state machine that controls iteration.
Namespace for the sheaves component of the sheaf system.
bool _strict
True if iterating over the strict up/down set of anchor.
An abstract client handle for a member of a poset.
bool filter(const scoped_index &xid) const
The value of the filter at id xid.
scoped_index _index
The index of the lesser end of the current link; the current item in the iteration.
order_type _order
The order of the iteration.
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710