SheafSystem  0.0.0.0
poset_traverser.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 // Interface for class POSET_TRAVERSER
18 
19 #ifndef POSET_TRAVERSER_H
20 #define POSET_TRAVERSER_H
21 
22 #ifndef SHEAF_DLL_SPEC_H
23 #include "SheafSystem/sheaf_dll_spec.h"
24 #endif
25 
26 #ifndef ANY_H
27 #include "SheafSystem/any.h"
28 #endif
29 
30 #ifndef SCOPED_INDEX_H
31 #include "SheafSystem/scoped_index.h"
32 #endif
33 
34 #ifndef ZN_TO_BOOL_H
35 #include "SheafSystem/zn_to_bool.h"
36 #endif
37 
38 namespace sheaf
39 {
40 
41 class abstract_poset_member;
42 class poset_state_handle;
43 class poset_component;
44 class total_poset_member;
45 
49 class SHEAF_DLL_SPEC poset_traverser: public any
50 {
51 
53 
54 public:
55 
56  // constructors:
57 
61  poset_traverser(const poset_state_handle* xanchor);
62 
66  ~poset_traverser();
67 
68  // queries:
69 
73  virtual bool invariant() const;
74 
79  {
80  return _host;
81  };
82 
86  inline const poset_state_handle* host() const
87  {
88  return _host;
89  };
90 
94  bool has_same_host(const poset_component* other) const;
95 
99  virtual abstract_poset_member* anchor();
100 
104  virtual const abstract_poset_member* anchor() const;
105 
106 
107 
111  inline bool in_down_set() const
112  {
113  return _in_down_set;
114  };
115 
120  void traverse(const abstract_poset_member* xanchor, bool down, bool reset_markers = true);
121 
122 protected:
123 
128 
133 
138 
143 
147  bool has_been_visited(const abstract_poset_member* xmbr) const;
148 
149 
150 
154  inline bool has_been_visited(int xindex) const
155  {
156  return (*_visited)[xindex];
157  };
158 
162  scoped_index member_index_ub() const;
163 
167  bool no_members_visited() const;
168 
172  bool all_members_visited() const;
173 
177  void mark_members_not_visited();
178 
182  void mark_visited(const abstract_poset_member* xmbr);
183 
187  inline void mark_visited(int xindex)
188  {
189  _visited->force(xindex, true);
190  };
191 
195  inline void mark_not_visited(int xindex)
196  {
197  _visited->force(xindex, false);
198  };
199 
203  virtual void private_traverse() = 0;
204 
208  inline void ensure_visited_ub()
209  {
210  if(_visited->ub() < member_index_ub().pod())
211  _visited->extend_to(member_index_ub().pod());
212  }
213 
214 };
215 
216 } // namespace sheaf
217 
218 #endif
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
Definition: scoped_index.h:672
zn_to_bool * _visited
The markers for previously visited members.
bool in_down_set() const
True if traversing down from anchor().
bool _in_down_set
True if traversing down from anchor().
A client handle for a general, abstract partially order set.
Abstract traverser (internal iterator) for poset.
int ub() const
The upper bound for the domain index.
Definition: zn_to_bool.cc:214
Features shared by poset_member and subposet. Subposet and poset_member objects can be attached...
void mark_visited(int xindex)
Sets the visited markers true for the emebr with index xindex.
void ensure_visited_ub()
Ensures the visited bit vector is large enough.
bool has_been_visited(int xindex) const
True if the member with index xindex has been previously visited.
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
void mark_not_visited(int xindex)
Sets the visited markers false for the emebr with index xindex.
const poset_state_handle * host() const
The poset being traversed (const version).
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
abstract_poset_member * _anchor
The member which is the starting point of this traversal.
poset_state_handle * host()
The poset being traversed (mutable version).
Namespace for the sheaves component of the sheaf system.
poset_state_handle * _host
The poset being traversed.
An abstract client handle for a member of a poset.
void extend_to(int xub)
Make the upper bound at least xub.
Definition: zn_to_bool.cc:362
void force(int i, bool value)
Sets the i-th member to value, extends the upper bound if necessary.
Definition: zn_to_bool.cc:607