SheafSystem  0.0.0.0
data_type_map.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 data_type_map
19 
20 
21 
22 #include "SheafSystem/data_type_map.h"
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/sheaf_file.h"
25 
26 #include "SheafSystem/data_converter.h"
27 
28 // ===========================================================
29 // ANY FACET
30 // ===========================================================
31 
32 // PUBLIC MEMBER FUNCTIONS
33 
34 // CANONICAL MEMBERS
35 
36 
40 clone() const
41 {
42  data_type_map* result;
43 
44  // Preconditions:
45 
46  // Body:
47 
48  result = new data_type_map(*this);
49 
50  // Postconditions:
51 
52  ensure(result != 0);
53  ensure(is_same_type(result));
54 
55  // Exit:
56 
57  return result;
58 }
59 
61 bool
63 invariant() const
64 {
65  bool result = true;
66 
67  // Preconditions:
68 
69  // Body:
70 
71  // Must satisfy base class invariant
72 
73  result = result && any::invariant();
74 
75  if(invariant_check())
76  {
77  // Prevent recursive calls to invariant
78 
80 
81  // Finished, turn invariant checking back on.
82 
84  }
85 
86  // Postconditions:
87 
88  // Exit
89 
90  return result;
91 }
92 
94 bool
96 is_ancestor_of(const any* other) const
97 {
98 
99  // Preconditions:
100 
101  require(other != 0);
102 
103  // Body:
104 
105  // True if other conforms to this
106 
107  bool result = dynamic_cast<const data_type_map*>(other) != 0;
108 
109  // Postconditions:
110 
111  return result;
112 
113 }
114 
115 
116 
117 // ===========================================================
118 // DATA_TYPE_MAP FACET
119 // ===========================================================
120 
124 {
125 
126  // Preconditions:
127 
128  // Body:
129 
130  // Do nothing.
131  // All the data converters and HDF objects are deleted in
132  // descendant file_data_type_map.
133 
134  // Postconditions:
135 
136  // Exit:
137 
138  return;
139 }
140 
144 operator[](int xi) const
145 {
146  data_converter* result;
147 
148  // Preconditions:
149 
150  require(is_primitive_index(xi));
151 
152  // Body:
153 
154  result = _converters[xi];
155 
156  // Postconditions:
157 
158  ensure(result != 0);
159 
160  // Exit
161 
162  return result;
163 }
164 
165 // ===========================================================
166 // PROTECTED MEMBER FUNCTIONS
167 // ===========================================================
168 
171 {
172 
173  // Preconditions:
174 
175 
176  // Body:
177 
178  _file = -1;
179  _max_internal_size = 0;
180  _max_external_size = 0;
181 
182  // Postconditions:
183 
184  // Exit:
185 
186  return;
187 }
188 
192 {
193 
194  // Preconditions:
195 
196  // Body:
197 
198  for(int i=PRIMITIVE_TYPE_BEGIN; i<PRIMITIVE_TYPE_END; i++)
199  {
200  _converters[i] = xother._converters[i];
201  }
202 
203  _file = xother._file;
206 
207  // Postconditions:
208 
209  ensure(invariant());
210 }
211 
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
Definition: any.cc:153
hid_t _file
The hdf file handle.
virtual data_type_map * clone() const
Virtual constructor; makes a new instance of the same type as this.
size_t _max_external_size
The external size of the largest fixed length type.
data_type_map()
Default constructor.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
Abstract base class with useful features for all objects.
Definition: any.h:39
size_t _max_internal_size
The internal size of the largest fixed length type.
SHEAF_DLL_SPEC bool is_primitive_index(pod_index_type xindex)
True if xindex is a valid primitive index.
data_converter * operator[](int xi) const
The data converter for the type with index xi.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
Function object to convert between internal and external data formats.
data_converter * _converters[PRIMITIVE_TYPE_END]
Table of converters, one for each type defined in the file.
A collection of data converters that map data types between internal and external representations...
Definition: data_type_map.h:49
virtual ~data_type_map()
Destructor.
virtual bool invariant() const
Class invariant.
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87