SheafSystem  0.0.0.0
any_lite.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/any_lite.h"
22 #include "SheafSystem/assert_contract.h"
23 
24 using namespace std;
25 using namespace fiber_bundle; // Workaround for MS C++ bug.
26 
27 //==============================================================================
28 // CLASS ANY_LITE
29 //==============================================================================
30 
31 //==============================================================================
32 // ANY FACET
33 //==============================================================================
34 
35 // PUBLIC MEMBER FUNCTIONS
36 
39 {
40  // Preconditions:
41 
42  // Body:
43 
44  // Nothing to do in this class.
45  // Destructor defined just to make it virtual in all descendants.
46 
47  // Postconditions:
48 
49  // Exit:
50 
51  return;
52 }
53 
54 const std::string&
56 class_name() const
57 {
58  // Preconditions:
59 
60  // Body:
61 
62  const string& result = static_class_name();
63 
64  // Postconditions:
65 
66  ensure(!result.empty());
67 
68  // Exit:
69 
70  return result;
71 }
72 
73 const std::string&
76 {
77  // Preconditions:
78 
79  // Body:
80 
81  static const string result("any_lite");
82 
83  // Postconditions:
84 
85  ensure(!result.empty());
86 
87  // Exit:
88 
89  return result;
90 }
91 
94 clone() const
95 {
96  any_lite* result = 0;
97 
98  // Preconditions:
99 
100  // Body:
101 
102  // Does nothing here, since any_lite is abstract,
103  // just establishes the postcondition.
104 
105  // Should never be called, but just in case,
106  // make it fail an assertion.
107 
108  is_abstract();
109 
110  // Postconditions:
111 
112  ensure(result != 0);
113  ensure(is_same_type(*result));
114 
115  // Exit
116 
117  return result;
118 }
119 
120 bool
122 is_ancestor_of(const any_lite& xother) const
123 {
124  // Preconditions:
125 
126  require(&xother != 0);
127 
128  // Body:
129 
130  // True if other conforms to this.
131 
132  bool result = dynamic_cast<const any_lite*>(&xother) != 0;
133 
134  // Postconditions:
135 
136  return result;
137 
138 }
139 
140 bool
142 is_same_type(const any_lite& xother) const
143 {
144 
145  // Preconditions:
146 
147  require(&xother != 0);
148 
149  // Body:
150 
151  // True if xother is same type as this.
152 
153  bool result = this->is_ancestor_of(xother) && xother.is_ancestor_of(*this);
154 
155  // Note: Could use typeid, but this implementation
156  // doesn't require <typeinfo>.
157 
158  // Postconditions:
159 
160  return result;
161 
162 }
163 
164 // PROTECTED MEMBER FUNCTIONS
165 
168 {
169  // Preconditions:
170 
171  // Body:
172 
173  // Invariant checking enabled unless specifically disabled.
174 
175  _disable_invariance_check_request_depth = 0;
176 
177  // Postconditions:
178 
179  ensure(invariant_check());
180 
181  // Exit:
182 
183  return;
184 }
185 
186 // PRIVATE MEMBER FUNCTIONS
187 
188 
189 //==============================================================================
190 // CONTROLLABLE INVARIANT INTERFACE
191 //==============================================================================
192 
193 // PUBLIC MEMBER FUNCTIONS
194 
195 bool
197 invariant() const
198 {
199  // Preconditions:
200 
201  // Body:
202 
203  invariance(disable_invariance_check_request_depth() >= 0);
204 
205  // Postconditions:
206 
207  // Exit
208 
209  return true;
210 }
211 
212 // PROTECTED MEMBER FUNCTIONS
213 
214 // PRIVATE MEMBER FUNCTIONS
215 
216 
217 //==============================================================================
218 // DOF ACCESS FACET
219 //==============================================================================
220 
221 // PUBLIC MEMBER FUNCTIONS
222 
223 void*
226 {
227  void* result = 0;
228 
229  // Preconditions:
230 
231  // Body:
232 
233  is_abstract();
234 
235  // Postconditions:
236 
237  ensure(result != 0);
238 
239  // Exit:
240 
241  return result;
242 }
243 
244 const void*
246 row_dofs() const
247 {
248  void* result = 0;
249 
250  // Preconditions:
251 
252  // Body:
253 
254  is_abstract();
255 
256  // Postconditions:
257 
258  ensure(result != 0);
259 
260  // Exit:
261 
262  return result;
263 }
264 
265 // PROTECTED MEMBER FUNCTIONS
266 
267 // PRIVATE MEMBER FUNCTIONS
268 
virtual void * row_dofs()
The row dofs for this instance (mutable version).
Definition: any_lite.cc:225
bool is_same_type(const any_lite &xother) const
True if other is the same type as this.
Definition: any_lite.cc:142
STL namespace.
virtual const std::string & class_name() const =0
The name of this class.
Definition: any_lite.cc:56
bool invariant() const
Class invariant, intended to be redefined in each descendant.
Definition: any_lite.cc:197
any_lite()
Default constructor.
Definition: any_lite.cc:167
Abstract base class with useful features for all volatile objects.
Definition: any_lite.h:48
static const std::string & static_class_name()
The name of this class.
Definition: any_lite.cc:75
virtual any_lite * clone() const
Virtual constructor, makes a new instance of the same type as this.
Definition: any_lite.cc:94
virtual ~any_lite()
Destructor.
Definition: any_lite.cc:38
virtual bool is_ancestor_of(const any_lite &xother) const
True if other conforms to this.
Definition: any_lite.cc:122
Namespace for the fiber_bundles component of the sheaf system.