SheafSystem  0.0.0.0
poset_crg_state.impl.h
Go to the documentation of this file.
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 
20 
21 #ifndef POSET_CRG_STATE_IMPL_H
22 #define POSET_CRG_STATE_IMPL_H
23 
24 #ifndef SHEAF_DLL_SPEC_H
25 #include "SheafSystem/sheaf_dll_spec.h"
26 #endif
27 
28 #ifndef POSET_CRG_STATE_H
29 #include "SheafSystem/poset_crg_state.h"
30 #endif
31 
32 #ifndef ASSERT_CONTRACT_H
33 #include "SheafSystem/assert_contract.h"
34 #endif
35 
36 #ifndef CRG_INTERVAL_H
37 #include "SheafSystem/crg_interval.h"
38 #endif
39 
40 #ifndef INDEX_SPACE_ITERATOR_H
41 #include "SheafSystem/index_space_iterator.h"
42 #endif
43 
44 using namespace std;
45 
46 
47 // ===========================================================
48 // POSET_CRG_STATE FACET
49 // ===========================================================
50 
51 template<typename handle_type>
52 handle_type&
54 get_cover_id_space(bool xlower, pod_index_type xmbr_index) const
55 {
56  // Preconditions:
57 
58  require(contains_member(xmbr_index));
59  require(cover_id_space_handle_conforms_to<handle_type>(xlower, xmbr_index));
60 
61  // Body:
62 
63  pod_index_type lid_space_id = cover_id_space_id(xlower, xmbr_index);
64  handle_type& result = _id_spaces.get_id_space<handle_type>(lid_space_id);
65 
66  // Postconditions:
67 
68  ensure(result.is_attached());
69 
70  // Exit:
71 
72  return result;
73 }
74 
75 template<typename handle_type>
76 bool
78 cover_id_space_handle_conforms_to(bool xlower, pod_index_type xmbr_index) const
79 {
80  // cout << endl << "Entering poset_crg_state::cover_id_space_handle_conforms_to." << endl;
81 
82  // Preconditions:
83 
84  require(contains_member(xmbr_index));
85 
86  // Body:
87 
88  pod_index_type lid_space_id = cover_id_space_id(xlower, xmbr_index);
89  bool result = _id_spaces.handle_conforms_to_state<handle_type>(lid_space_id);
90 
91  // Postconditions:
92 
93 
94  // Exit:
95 
96  // cout << "Leaving poset_crg_state::cover_id_space_handle_conforms_to." << endl;
97  return result;
98 }
99 
100 
101 
102 template<typename filter_type>
103 void
105 remove_cover_members(const filter_type& xfilter, bool xlower, pod_index_type xmbr_index)
106 {
107  // Preconditions:
108 
109  require(contains_member(xmbr_index));
110 
111  // Body:
112 
116 
117  // Gather members that need removed for the cover into a set.
118 
119  set<pod_index_type> lmbrs_to_remove;
120  index_space_iterator& litr = get_cover_id_space_iterator(xlower, xmbr_index);
121  while(!litr.is_done())
122  {
123  if(xfilter(litr.hub_pod()))
124  {
125  // Remove the current item from the cover.
126 
127  lmbrs_to_remove.insert(litr.hub_pod());
128  }
129 
130  litr.next();
131  }
132  release_cover_id_space_iterator(litr);
133 
134  if(!lmbrs_to_remove.empty())
135  {
136  // There are members to be removed. Force the cover to be explicit
137  // and remove the members.
138 
139  pod_index_type lspace_id = force_explicit_cover(xlower, xmbr_index, true);
140 
143 
144  set<pod_index_type>::iterator lmbr_itr;
145  for(lmbr_itr = lmbrs_to_remove.begin();
146  lmbr_itr != lmbrs_to_remove.end();
147  ++lmbr_itr)
148  {
149  lcover.remove_hub(*lmbr_itr, false);
150  }
151 
152  lcover.update_extrema();
153 
154  lcover.release_id_space();
155  }
156  // Postconditions:
157 
158  ensure_for_iterator(index_space_iterator& i=get_cover_id_space_iterator(xlower, xmbr_index),
159  !i.is_done(),
160  i.next(),
161  !xfilter(i.hub_pod()),
162  release_cover_id_space_iterator(i));
163 
164  // Exit:
165 
166  return;
167 }
168 
169 #endif // ifndef POSET_CRG_STATE_IMPL_H
index_space_handle & get_cover_id_space(bool xlower, pod_index_type xmbr_index) const
Allocates an handle for the lower (xlower true) or upper (xlower false) cover of member with index xm...
An abstract iterator over the ids of an id space.
void remove_cover_members(const filter_type &xfilter, bool xlower, pod_index_type xmbr_index)
Removes all members for which functor xfilter(xmbr.index().top_pod()) is true from the lower (xlower ...
STL namespace.
virtual void release_id_space() const
Returns this id space handle to the handle pool.
virtual void next()=0
Makes id() the next id in the iteration.
bool is_done() const
True if iteration is finished.
virtual index_space_handle & get_id_space() const
Allocates an id space handle from the handle pool.
size_type remove_hub(pod_type xhub_id, bool update_extrema)
Removes the equivalence associated with hub id xhub_id. Returns the number of entries actually remove...
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
A handle for a scattered_insertion_index_space_state.
bool cover_id_space_handle_conforms_to(bool xlower, pod_index_type xmbr_index) const
True if a handle for the lower (xlower true) or upper (xlower false) cover id space of the member wit...
pod_type hub_pod() const
The current unglued hub id in the iteration. synonym for unglued_hub_pod().