SheafSystem  0.0.0.0
sheaves_namespace.cc
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 // Implementation for class sheaves_namespace
19 
20 #include "SheafSystem/abstract_poset_member.h"
21 #include "SheafSystem/arg_list.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/index_iterator.h"
24 #include "SheafSystem/namespace_poset_member.h"
25 #include "SheafSystem/poset_member_iterator.h"
26 #include "SheafSystem/postorder_iterator.h"
27 #include "SheafSystem/primitives_poset.h"
28 #include "SheafSystem/primitives_poset_schema.h"
29 #include "SheafSystem/schema_poset_member.h"
30 #include "SheafSystem/sheaves_namespace.h"
31 #include "SheafSystem/refinable_poset.h"
32 
33 // ===========================================================
34 // SHEAVES_NAMESPACE FACET
35 // ===========================================================
36 
37 // PUBLIC MEMBER FUNCTIONS
38 
40 sheaves_namespace(const std::string& xname)
41  : namespace_poset(xname)
42 {
43  // Preconditions:
44 
45  // Pre- and poscondtions repeated here from namespace_poset::new_state
46  // for convenience of Programmer's Guide tutorial.
47 
48  require(poset_path::is_valid_name(xname));
49 
50  // Body:
51 
52  // Create the state.
53 
54  new_state(xname);
55 
56  // Postconditions:
57 
59 
60  ensure(invariant());
61  ensure(name() == xname);
62  ensure(!in_jim_edit_mode());
63  ensure(host() == 0);
64  ensure(!index().is_valid());
65  ensure(index().same_scope(member_hub_id_space(false)));
66  ensure(has_standard_subposet_ct());
67  ensure(current_namespace() == this);
68 
70 
72 
73  // Exit
74 
75  return;
76 
77 }
78 
82 {
83 
84  // Preconditions:
85 
86  require(is_attached() ? state_is_read_write_accessible() : true);
87 
88  // Body:
89 
90  // Postconditions:
91 }
92 
94 void
97 {
98  // Preconditions:
99 
100  require(xns != 0);
101 
102  // Body:
103 
104  // make a triangle
105 
106 
107  // t
108  // *
109  // ***
110  // * * *
111  // * * *
112  // * * *
113  // e0 e1 e2
114  // * * *
115  // ** *** **
116  // * * * * * * *
117  // * * * * *
118  // * * * * * * *
119  // ** *** **
120  // * * *
121  // v0 v1 v2
122 
123  // Get read-write access to the namespace
124 
125  xns->get_read_write_access(true);
126 
128 
129  abstract_poset_member& ref_type = primitives.int_type();
130 
131  poset& cells = refinable_poset::new_table(*xns, "cells", ref_type.path(true), false);
132 
133  cells.begin_jim_edit_mode();
134 
135  total_poset_member* t = new total_poset_member(&cells, 0, false, false);
136  t->put_name("standard triangle", true, false);
137  int dof = 4;
138  t->put_dof_tuple(&dof,sizeof(dof));
139 
140  total_poset_member* e0 = new total_poset_member(&cells, 0, false, false);
141  e0->put_name("e0", true, false);
142  dof = 3;
143  e0->put_dof_tuple(&dof,sizeof(dof));
144 
145  total_poset_member* e1 = new total_poset_member(&cells, 0, false, false);
146  e1->put_name("e1", true, false);
147  dof = 3;
148  e1->put_dof_tuple(&dof,sizeof(dof));
149 
150  total_poset_member* e2 = new total_poset_member(&cells, 0, false, false);
151  e2->put_name("e2", true, false);
152  dof = 3;
153  e2->put_dof_tuple(&dof,sizeof(dof));
154 
155  total_poset_member* v0 = new total_poset_member(&cells, 0, false, false);
156  v0->put_name("v0", true, false);
157  dof = 2;
158  v0->put_dof_tuple(&dof,sizeof(dof));
159 
160  total_poset_member* v1 = new total_poset_member(&cells, 0, false, false);
161  v1->put_name("v1", true, false);
162  dof = 2;
163  v1->put_dof_tuple(&dof,sizeof(dof));
164 
165  total_poset_member* v2 = new total_poset_member(&cells, 0, false, false);
166  v2->put_name("v2", true, false);
167  dof = 2;
168  v2->put_dof_tuple(&dof,sizeof(dof));
169 
170  t->create_cover_link(e0);
171  t->create_cover_link(e1);
172  t->create_cover_link(e2);
173 
174  e0->create_cover_link(v0);
175  e0->create_cover_link(v1);
176 
177  e1->create_cover_link(v0);
178  e1->create_cover_link(v2);
179 
180  e2->create_cover_link(v1);
181  e2->create_cover_link(v2);
182 
183  cells.end_jim_edit_mode();
184 
185  // Output the cells poset.
186 
187  //cout << cells << endl;
188 
189  // release access to namespace
190 
191  xns->release_access();
192 
193 
194  // Postconditions:
195 
196  // Exit
197 
198  return;
199 }
200 
201 // PROTECTED MEMBER FUNCTIONS
202 
206 {
207  // Preconditions:
208 
209 
210  // Body:
211 
212  // Nothing to do.
213 
214  // Postconditions:
215 
216  // Exit:
217 
218  return;
219 }
220 
224  : namespace_poset(xtop, xbottom)
225 {
226  // Preconditions:
227 
228  require(precondition_of(namespace_poset(xtop, xbottom)));
229 
230  // Body:
231 
232  // Nothing to do.
233 
234  // Postconditions:
235 
236  ensure(postcondition_of(namespace_poset(xtop, xbottom)));
237 
238  // Exit:
239 
240  return;
241 }
242 
243 // PRIVATE MEMBER FUNCTIONS
244 
245 
246 // ===========================================================
247 // STATE FACET
248 // ===========================================================
249 
250 // PUBLIC MEMBER FUNCTIONS
251 
252 
256 type_id() const
257 {
258  return SHEAVES_NAMESPACE_ID;
259 }
260 
262 const char*
264 class_name() const
265 {
266  // Preconditions:
267 
268 
269  // Body:
270 
271  static const char* result = "sheaves_namespace";
272 
273  // Postconditions:
274 
275  // Exit:
276 
277  return result;
278 }
279 
280 // PROTECTED MEMBER FUNCTIONS
281 
282 // PRIVATE MEMBER FUNCTIONS
283 
virtual ~sheaves_namespace()
Destructor.
virtual void create_cover_link(abstract_poset_member *xlesser)
Insert a link from this to lesser; make lesser <= this.
sheaves_namespace()
Default constructor; creates an unattached handle.
const scoped_index & index() const
The member index of this poset within the namespace host()
static void make_triangle(sheaves_namespace *xns)
Creates a triangle schema using the primatives poset; used for test drivers.
poset_path path(bool xauto_access=true) const
A path to this component.
The default name space; a poset which contains other posets as members.
poset_type
Identifiers for poset types.
Definition: poset_type.h:41
primitives_poset & primitives()
The poset of primitives for this namespace (mutable version)
virtual void get_read_write_access(bool xrelease_read_only_access=false)
Get read write access to the state associated with this. If release_read_only_access is requested...
abstract_poset_member & int_type()
Poset member representing primitive type int (mutable version)
The standard sheaves name space.
namespace_poset * host() const
The namespace this poset resides in. Obsolete; use name_space() instead.
static namespace_poset * current_namespace()
The current default namespace.
void put_dof_tuple(const void *xbuf, size_t xbuflen)
Copies the entire dof tuple between xbuf and internal storage.
A client handle for a member of a namespace poset.
The poset containing the primitive type definitions.
virtual const char * class_name() const
The name of this class.
void new_state(const std::string &xname)
Creates a new namespace state with name xname and attaches this to it.
bool has_standard_subposet_ct() const
True if poset is in its initial state, that is, it contains just the standard subposets.
A client handle for a mutable partially ordered set.
Definition: poset.h:40
bool state_is_read_write_accessible() const
True if this is attached and if the state is accessible for read and write or access control is disab...
virtual void get_read_access() const
Get read access to the state associated with this.
virtual void put_name(const std::string &xname, bool xunique, bool xauto_access)
Make xname a name for this; if xunique, make xname the only name.
static refinable_poset & new_table(namespace_type &xhost, const poset_path &xpath, const poset_path &xschema_path, bool xauto_access)
Creates a new poset in namespace xns with path xpath and schema specified by xschema_path.
const hub_index_space_handle & member_hub_id_space(bool xauto_access) const
The member hub id space.
virtual poset_type type_id() const
Identifier for the type of this poset.
virtual bool is_attached() const
True if this is attached to a state.
bool invariant() const
Class invariant.
virtual std::string name() const
The name of this poset.
virtual void end_jim_edit_mode(bool xensure_lattice_invariant=true, bool xauto_access=true)
Prevent editing of jims and jim order relation.
Definition: poset.cc:253
static bool is_valid_name(const std::string &xname)
True if xname is not empty and contains only name legal characters.
Definition: poset_path.cc:331
An abstract client handle for a member of a poset.
bool in_jim_edit_mode() const
True if editing jims and jim order relation is allowed.
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
Definition: pod_types.cc:37
bool state_is_not_read_accessible() const
True if this is attached and if the state is accessible for read or if access control is disabled...
namespace_poset()
Default constructor; creates an unattached namespace handle.
virtual void release_access(bool xall=false) const
Release access. If xall is true, release all levels of access. Otherwise, release one level of access...
A client handle for an unrestricted member of a poset. A total_poset_member is guaranteed not to be r...
virtual void begin_jim_edit_mode(bool xauto_access=true)
Allow editing of jims and jim order relation.
Definition: poset.cc:230