SheafSystem  0.0.0.0
wsv_block.impl.h
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 // Interface for class wsv_block
19 
20 #ifndef WSV_BLOCK_IMPL_H
21 #define WSV_BLOCK_IMPL_H
22 
23 #ifndef SHEAF_DLL_SPEC_H
24 #include "SheafSystem/sheaf_dll_spec.h"
25 #endif
26 
27 #ifndef WSV_BLOCK_H
28 #include "SheafSystem/wsv_block.h"
29 #endif
30 
31 #ifndef ASSERT_CONTRACT_H
32 #include "SheafSystem/assert_contract.h"
33 #endif
34 
35 #ifndef BLOCK_H
36 #include "SheafSystem/block_impl.h"
37 #endif
38 
39 #ifndef STD_CSTRING_H
40 #include "SheafSystem/std_cstring.h"
41 #endif
42 
43 #ifndef STD_SSTREAM_H
44 #include "SheafSystem/std_sstream.h"
45 #endif
46 
47 namespace sheaf
48 {
49 
50 template <typename T>
53 {
54  // Preconditions:
55 
56  // None.
57 
58  // Body:
59 
60  // Nothing to do.
61 
62  // Postconditions:
63 
64  ensure(invariant());
65  ensure(this->ub() == 0);
66 
67  // Exit:
68 
69  return;
70 };
71 
72 template <typename T>
74 wsv_block(const wsv_block& xother)
75  : block<T>(xother)
76 {
77  // Preconditions:
78 
79  require(precondition_of(block_xother));
80 
81  // Body:
82 
83  // Nothing to do.
84 
85  // Postconditions:
86 
87  ensure(postcondition_of(block(xother)));
88 
89  // Exit:
90 
91  return;
92 };
93 
94 
95 template <typename T>
98 {}
99 ;
100 
101 template <typename T>
103 wsv_block(const char* xlist)
104 {
105  // Preconditions:
106 
107 
108  // Body:
109 
110  *this = xlist;
111 
112  // Postconditions:
113 
114  ensure(strlen(xlist) > 0 ? this->ct() > 0 : true);
115 
116  // Exit:
117 
118  return;
119 };
120 
121 template <typename T>
123 wsv_block(const std::string& xlist)
124 {
125  // Preconditions:
126 
127 
128  // Body:
129 
130  *this = xlist;
131 
132  // Postconditions:
133 
134  ensure(!xlist.empty() ? this->ct() > 0 : true);
135 
136  // Exit:
137 
138  return;
139 };
140 
141 template <typename T>
144 operator=(const wsv_block& xother)
145 {
146  // Preconditions:
147 
148 
149  // Body:
150 
151  block<T>::operator=(xother);
152 
153  // Postconditions:
154 
155 
156  // Exit:
157 
158  return *this;
159 };
160 
161 template <typename T>
164 operator=(const std::string& xlist)
165 {
166  // Preconditions:
167 
168  // Body:
169 
170  std::stringstream lval_stream;
171  lval_stream.str(xlist);
172 
173  T lval;
174  while(lval_stream >> lval)
175  {
176  push_back(lval);
177  }
178 
179 
180  // Postconditions:
181 
182  ensure(!xlist.empty() ? this->ct() > 0 : true);
183 
184  // Exit:
185 
186  return *this;
187 };
188 
189 template <typename T>
192 operator=(const char* xlist)
193 {
194  // Preconditions:
195 
196 
197  // Body:
198 
199  this->operator=(std::string(xlist));
200 
201  // Postconditions:
202 
203  ensure(strlen(xlist) > 0 ? this->ct() > 0 : true);
204 
205  // Exit:
206 
207  return *this;
208 };
209 
210 template <typename T>
211 bool
213 invariant() const
214 {
215  // Preconditions:
216 
217  // Body:
218 
219  // Postconditions:
220 
221  bool result = block<T>::invariant();
222 
223  // Return:
224 
225  return result;
226 }
227 
228 template <typename T>
229 void
231 push_back(const wsv_block& xother)
232 {
233  // Preconditions:
234 
235  // Body:
236 
237  define_old_variable(int old_ct = this->ct());
238 
239 
240  for(int i=0; i<xother.ct(); ++i)
241  {
242  push_back(xother[i]);
243  }
244 
245  // Postconditions:
246 
247  ensure(this->ct() == old_ct + xother.ct());
248  ensure_for_all(i, 0, xother.ct(), ((*this)[i + old_ct] == xother[i]) );
249 
250  // Exit:
251 
252  return;
253 }
254 
255 
256 // ===========================================================
257 // NON-MEMBER FUNCTIONS
258 // ===========================================================
259 
260 
261 } //namespace sheaf
262 
263 #endif // ifndef WSV_BLOCK_IMPL_H
size_type ct() const
The number of items currently in use.
wsv_block()
Default constructor.
Namespace for the sheaves component of the sheaf system.
An auto_block with a no-initialization initialization policy.
Whitespace-separated-value block; A block of objects of type T that can be conveniently initialized b...
Definition: tuple.h:62