SheafSystem  0.0.0.0
group.cc
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 #include "SheafSystem/group.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/poset.h"
25 
26 using namespace std;
27 using namespace fiber_bundle; // Workaround for MS C++ bug.
28 
29 //==============================================================================
30 // CLASS GROUP_LITE
31 //==============================================================================
32 
33 //==============================================================================
34 // GROUP FACET
35 //==============================================================================
36 
37 // PUBLIC MEMBER FUNCTIONS
38 
41 {
42 
43  // Preconditions:
44 
45  // Body:
46 
47  // Postconditions:
48 
49  ensure(invariant());
50 
51  // Exit:
52 }
53 
55 group_lite(const group_lite& xother)
56 {
57  // Preconditions:
58 
59  // Body:
60 
61  *this = xother;
62 
63  // Postconditions:
64 
65  ensure(invariant());
66 
67  // Exit:
68 }
69 
72 operator=(const group_lite& xother)
73 {
74  // Preconditions:
75 
76  // Body:
77 
78  // Postconditions:
79 
80  ensure(invariant());
81 
82  // Exit:
83 
84  return *this;
85 }
86 
89 {
90  // Preconditions:
91 
92  // Body:
93 
94  // Postconditions:
95 
96  // Exit:
97 
98 }
99 
100 // PROTECTED MEMBER FUNCTIONS
101 
102 // PRIVATE MEMBER FUNCTIONS
103 
104 
105 //==============================================================================
106 // ABSTRACT POSET MEMBER FACET
107 //==============================================================================
108 
109 // PUBLIC MEMBER FUNCTIONS
110 
111 const std::string&
113 class_name() const
114 {
115  // Preconditions:
116 
117  // Body:
118 
119  const string& result = static_class_name();
120 
121  // Postconditions:
122 
123  ensure(!result.empty());
124 
125  // Exit:
126 
127  return result;
128 }
129 
130 const std::string&
133 {
134  // Preconditions:
135 
136  // Body:
137 
138  static const string result("group_lite");
139 
140  // Postconditions:
141 
142  ensure(!result.empty());
143 
144  // Exit:
145 
146  return result;
147 }
148 
151 clone() const
152 {
153  group_lite* result = 0;
154 
155  // Preconditions:
156 
157  // Body:
158 
159  is_abstract();
160 
161  // Postconditions:
162 
163  ensure(result != 0);
164  ensure(is_same_type(*result));
165 
166  // Exit:
167 
168  return result;
169 }
170 
171 // PROTECTED MEMBER FUNCTIONS
172 
173 // PRIVATE MEMBER FUNCTIONS
174 
175 
176 //==============================================================================
177 // ANY FACET
178 //==============================================================================
179 
180 // PUBLIC MEMBER FUNCTIONS
181 
182 bool
184 is_ancestor_of(const any_lite& xother) const
185 {
186  // Preconditions:
187 
188  require(&xother != 0);
189 
190  // Body:
191 
192  // True if other conforms to this.
193 
194  bool result = dynamic_cast<const group_lite*>(&xother) != 0;
195 
196  // Postconditions:
197 
198  return result;
199 }
200 
201 bool
203 invariant() const
204 {
205  bool result = true;
206 
207  if(invariant_check())
208  {
209  // Prevent recursive calls to invariant.
210 
211  disable_invariant_check();
212 
213  // Must satisfy base class invariant.
214 
215  invariance(any_lite::invariant());
216 
217  // Invariances for this class:
218 
219  // Finished, turn invariant checking back on.
220 
221  enable_invariant_check();
222  }
223 
224  // Exit
225 
226  return result;
227 }
228 
229 // PROTECTED MEMBER FUNCTIONS
230 
231 // PRIVATE MEMBER FUNCTIONS
232 
233 
234 //==============================================================================
235 // CLASS GROUP
236 //==============================================================================
237 
238 //==============================================================================
239 // GROUP FACET
240 //==============================================================================
241 
242 // PUBLIC MEMBER FUNCTIONS
243 
248 {
249  // Preconditions:
250 
251  require(is_ancestor_of(&xother));
252  require(precondition_of(attach_to_state(&xother)));
253 
254  // Body:
255 
256  attach_to_state(&xother);
257 
258  // Postconditions:
259 
260  ensure(postcondition_of(attach_to_state(&xother)));
261 
262  // Exit:
263 
264  return *this;
265 }
266 
270 operator=(const group& xother)
271 {
272  // Preconditions:
273 
274  require(precondition_of(attach_to_state(&xother)));
275 
276  // Body:
277 
278  attach_to_state(&xother);
279 
280  // Postconditions:
281 
282  ensure(postcondition_of(attach_to_state(&xother)));
283 
284  // Exit:
285 
286  return *this;
287 }
288 
291 {
292 
293  // Preconditions:
294 
295  // Body:
296 
297  // Postconditions:
298 
299  // Exit:
300 
301 }
302 
305 host() const
306 {
307  poset* result;
308 
309  // Preconditions:
310 
311  // Body:
312 
313  result = dynamic_cast<poset*>(_host);
314 
315  // Postconditions:
316 
317  ensure(is_basic_query);
318  ensure( (_host != 0) == (result != 0) );
319 
320  // Exit:
321 
322  return result;
323 }
324 
327 {
328 
329  // Preconditions:
330 
331  // Body:
332 
333  // Postconditions:
334 
335  ensure(invariant());
336 
337  // Exit:
338 
339  return;
340 }
341 
342 // PROTECTED MEMBER FUNCTIONS
343 
344 // PRIVATE MEMBER FUNCTIONS
345 
346 
347 //==============================================================================
348 // ABSTRACT POSET MEMBER FACET
349 //==============================================================================
350 
351 // PUBLIC MEMBER FUNCTIONS
352 
353 const std::string&
355 class_name() const
356 {
357  // Preconditions:
358 
359  // Body:
360 
361  const string& result = static_class_name();
362 
363  // Postconditions:
364 
365  ensure(!result.empty());
366 
367  // Exit:
368 
369  return result;
370 }
371 
372 const std::string&
375 {
376  // Preconditions:
377 
378  // Body:
379 
380  static const string result("group");
381 
382  // Postconditions:
383 
384  ensure(!result.empty());
385 
386  // Exit:
387 
388  return result;
389 }
390 
391 //@todo Clone functions?
392 
393 // PROTECTED MEMBER FUNCTIONS
394 
395 // PRIVATE MEMBER FUNCTIONS
396 
397 
398 //==============================================================================
399 // ANY FACET
400 //==============================================================================
401 
402 // PUBLIC MEMBER FUNCTIONS
403 
404 bool
406 invariant() const
407 {
408  bool result = true;
409 
410  // Preconditions:
411 
412  // Body:
413 
414  // Must satisfy base class invariant.
415 
416  invariance(total_poset_member::invariant());
417 
418  if (invariant_check())
419  {
420  // Prevent recursive calls to invariant.
421 
422  disable_invariant_check();
423 
424  // Finished, turn invariant checking back on.
425 
426  enable_invariant_check();
427  }
428 
429  // Postconditions:
430 
431  ensure(is_derived_query);
432 
433  // Exit:
434 
435  return result;
436 }
437 
438 bool
440 is_ancestor_of(const any* xother) const
441 {
442 
443  // Preconditions:
444 
445  require(xother != 0);
446 
447  // Body:
448 
449  // True if other conforms to this.
450 
451  bool result = dynamic_cast<const group*>(xother) != 0;
452 
453  // Postconditions:
454 
455  // ensure(invariant());
456 
457  // Exit:
458 
459  return result;
460 
461 }
462 
463 // PROTECTED MEMBER FUNCTIONS
464 
465 // PRIVATE MEMBER FUNCTIONS
virtual const std::string & class_name() const
The name of this class.
Definition: group.cc:113
group_lite()
Default constructor.
Definition: group.cc:40
The general, abstract mathematical group (volatile version).
Definition: group.h:64
group_lite & operator=(const group_lite &xother)
Assignment operator.
Definition: group.cc:72
virtual ~group()
Destructor.
Definition: group.cc:290
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
Definition: group.cc:440
STL namespace.
group()
Default constructor.
Definition: group.cc:326
Abstract base class with useful features for all volatile objects.
Definition: any_lite.h:48
Abstract base class with useful features for all objects.
Definition: any.h:39
A client handle for a mutable partially ordered set.
Definition: poset.h:40
The general, abstract mathematical group (persistent version)
Definition: group.h:158
bool invariant() const
Class invariant.
Definition: group.cc:203
static const std::string & static_class_name()
The name of this class.
Definition: group.cc:374
host_type * host() const
The poset this is a member of.
Definition: group.cc:305
static const std::string & static_class_name()
The name of this class.
Definition: group.cc:132
virtual bool is_ancestor_of(const any_lite &xother) const
Conformance test; true if other conforms to this.
Definition: group.cc:184
virtual group & operator=(const abstract_poset_member &xother)
Assignment operator; synonym for attach_to_state(&xother).
Definition: group.cc:247
virtual bool invariant() const
Class invariant.
Definition: group.cc:406
An abstract client handle for a member of a poset.
virtual group_lite * clone() const
Virtual constructor, makes a new instance of the same type as this.
Definition: group.cc:151
Namespace for the fiber_bundles component of the sheaf system.
virtual const std::string & class_name() const =0
The name of this class.
Definition: group.cc:355
virtual ~group_lite()
Destructor.
Definition: group.cc:88