SheafSystem  0.0.0.0
schema_descriptor.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 schema_descriptor
19 
20 #include "SheafSystem/schema_descriptor.h"
21 #include "SheafSystem/assert_contract.h"
22 #include "SheafSystem/std_string.h"
23 
24 using namespace std;
25 
26 // ===========================================================
27 // ANY FACET
28 // ===========================================================
29 
30 
32 bool
34 is_ancestor_of(const any* other) const
35 {
36 
37  // Preconditions:
38 
39  require(other != 0);
40 
41  // Body:
42 
43  // True if other conforms to this
44 
45  bool result = dynamic_cast<const schema_descriptor*>(other) != 0;
46 
47  // Postconditions:
48 
49  return result;
50 }
51 
55 clone() const
56 {
57  schema_descriptor* result;
58 
59  // Preconditions:
60 
61  // Body:
62 
63  result = new schema_descriptor();
64 
65  // Postconditions:
66 
67  ensure(result != 0);
68  ensure(is_same_type(result));
69 
70  // Exit:
71 
72  return result;
73 }
74 
75 
76 
78 bool
80 operator==(const schema_descriptor& xother) const
81 {
82  bool result;
83 
84  // Preconditions:
85 
86 
87  // Body:
88 
89  result =
90  (name == xother.name) &&
91  (type == xother.type) &&
92  (is_table_dof == xother.is_table_dof);
93 
94  // Postconditions:
95 
96 
97  // Exit:
98 
99  return result;
100 }
101 
103 bool
105 invariant() const
106 {
107  bool result = true;
108 
109  if(invariant_check())
110  {
111  // Prevent recursive calls to invariant
112 
113  disable_invariant_check();
114 
115  // Must satisfy base class invariant
116 
117  invariance(any::invariant());
118 
119  // Invariances for this class:
120 
121 
122 
123  // Finished, turn invariant checking back on.
124 
125  enable_invariant_check();
126  }
127 
128  // Exit
129 
130  return result;
131 }
132 
133 
134 
135 // ===========================================================
136 // SCHEMA_DESCRIPTOR FACET
137 // ===========================================================
138 
142 {
143 
144  // Preconditions:
145 
146 
147  // Body:
148 
149  type = NOT_A_PRIMITIVE_TYPE;
150  is_table_dof = false;
151 
152  // Postconditions:
153 
154  ensure(invariant());
155  ensure(name.empty());
156  ensure(type == NOT_A_PRIMITIVE_TYPE);
157  ensure(!is_table_dof);
158 
159  // Exit:
160 
161  return;
162 }
163 
164 
168 {
169 
170  // Preconditions:
171 
172 
173  // Body:
174 
175  *this = xother;
176 
177  // Postconditions:
178 
179  ensure(invariant());
180  ensure(*this == xother);
181 
182  // Exit:
183 
184  return;
185 }
186 
189 schema_descriptor(const std::string& xname, primitive_type xtype, bool xis_table_dof)
190 {
191  // Preconditions:
192 
193 
194  // Body:
195 
196  name = xname;
197  type = xtype;
198  is_table_dof = xis_table_dof;
199 
200  // Postconditions:
201 
202  ensure(name == xname);
203  ensure(type == xtype);
204  ensure(is_table_dof == xis_table_dof);
205 
206  // Exit:
207 
208  return;
209 }
210 
211 
215 {
216  // Preconditions:
217 
218 
219  // Body:
220 
221  // Nothing to do.
222 
223  // Postconditions:
224 
225  // Exit:
226 
227  return;
228 }
229 
230 // ===========================================================
231 // NON-MEMBER FUNCTIONS
232 // ===========================================================
233 
235 std::ostream&
236 sheaf::operator<<(std::ostream& os, const schema_descriptor& xsd)
237 {
238  // Preconditions:
239 
240 
241  // Body:
242 
243  os << " " << xsd.name
244  << " " << xsd.type
245  << " " << boolalpha << xsd.is_table_dof << noboolalpha;
246 
247  // Postconditions:
248 
249 
250  // Exit:
251 
252  return os;
253 }
254 
255 
257 std::istream&
258 sheaf::operator>>(std::istream& is, schema_descriptor& xsd)
259 {
260  // Preconditions:
261 
262 
263  // Body:
264 
265  if(is)
266  {
267  is >> xsd.name;
268  if(is)
269  {
270  is >> xsd.type;
271  if(is)
272  {
273  is >> boolalpha >> xsd.is_table_dof >> noboolalpha;
274  }
275  }
276  }
277 
278  // Postconditions:
279 
280  // Exit:
281 
282  return is;
283 }
284 
285 size_t
286 sheaf::
287 deep_size(const schema_descriptor& xsd, bool xinclude_shallow)
288 {
289  size_t result;
290 
291  // Preconditions:
292 
293  // Body:
294 
297 
298  result = 0;
299 
300  // Postconditions:
301 
302  ensure(result == 0);
303  //ensure(result >= 0);
304 
305  // Exit
306 
307  return result;
308 }
309 
schema_descriptor()
Default constructor.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
STL namespace.
virtual ~schema_descriptor()
Destructor.
Abstract base class with useful features for all objects.
Definition: any.h:39
primitive_type
Type ids for sheaf primitives.
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
bool operator==(const schema_descriptor &xother) const
Equality operator.
A description of a dof in a schema.
virtual bool invariant() const
Class invariant.
virtual schema_descriptor * clone() const
Virtual constructor, makes a new instance of the same type as this.
std::string name
The name of the dof described by this.
SHEAF_DLL_SPEC std::istream & operator>>(std::istream &is, dof_tuple_type &xdt)
Extract dof_tuple_type xdt from istream& is.
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
bool is_table_dof
The role of the dof described by this; true if this describes a table dof.
primitive_type type
The type of the dof described by this.