SheafSystem  0.0.0.0
auto_block.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 auto_block.
19 
20 #ifndef AUTO_BLOCK_H
21 #define AUTO_BLOCK_H
22 
23 #ifndef SHEAF_DLL_SPEC_H
24 #include "SheafSystem/sheaf_dll_spec.h"
25 #endif
26 
27 #ifndef POD_TYPES_H
28 #include "SheafSystem/pod_types.h"
29 #endif
30 
31 #ifndef STD_IOSTREAM_H
32 #include "SheafSystem/std_iostream.h"
33 #endif
34 
35 namespace sheaf
36 {
37 
41 template <typename T>
43 {
44 public:
45 
49  static void initialize(T* xbegin, T* xend);
50 
54  static void initialize(T& xvalue);
55 };
56 
60 template <typename T>
62 {
63 public:
67  static void initialize(T* xbegin, T* xend);
68 
72  static void initialize(T& xvalue);
73 };
74 
75 // Specialization for float
76 
77 template <>
79 {
80 public:
81  static float invalid();
82  static void initialize(float* xbegin, float* xend);
83  static void initialize(float& xvalue);
84 };
85 
86 // Specialization for double
87 
88 template <>
90 {
91 public:
92  static double invalid();
93  static void initialize(double* xbegin, double* xend);
94  static void initialize(double& xvalue);
95 };
96 
97 
101 template <typename T>
103 {
104 public:
108  static void initialize(T* xbegin, T* xend);
109 
113  static void initialize(T& xvalue);
114 };
115 
116 
121 template <typename T, typename S = un_block_initialization_policy<T> >
122 class SHEAF_DLL_SPEC auto_block
123 {
124 
125 public:
126 
130  typedef T value_type;
131 
136 
140  typedef T& reference_type;
141 
145  typedef const T& const_reference_type;
146 
150  typedef T* pointer_type;
151 
155  typedef const T* const_pointer_type;
156 
161 
166  typedef signed long int difference_type;
167 
171  typedef unsigned long int size_type;
172 
176  pointer_type base() const;
177 
181  size_type ct() const;
182 
186  bool invariant() const;
187 
191  reference_type item(index_type xindex) const;
192 
196  reference_type operator [] (index_type xindex) const;
197 
202  index_type ub() const;
203 
208  auto_block(index_type xub = 0);
209 
214  auto_block(index_type xub, size_type xct, const T *xitems);
215 
219  auto_block(const auto_block& xother);
220 
224  auto_block& operator=(const auto_block& xother);
225 
229  virtual ~auto_block();
230 
235  void force_item(index_type xindex, const_reference_type xitem);
236 
241  void reserve(index_type xub);
242 
246  void set_ct(size_type xct);
247 
252  void set_item(index_type xindex, const_reference_type xitem);
253 
257  void assign(const_reference_type xitem);
258 
262  void assign(index_type xbegin, index_type xend, const_reference_type xitem);
263 
267  reference_type back() const;
268 
272  void push_back(const_reference_type item);
273 
277  void push_back(const auto_block& xother);
278 
282  void pop_back();
283 
287  void clear();
288 
292  void initialize(index_type xindex);
293 
297  void initialize(index_type xbegin, index_type xend);
298 
299 
300 
301 protected:
302 
306  pointer_type _base; // start of auto_block storage
307 
311  index_type _ub;
312 
316  size_type _ct;
317 
318 };
319 
320 // ===========================================================
321 // NON-MEMBER FUNCTIONS
322 // ===========================================================
323 
327 template <typename T, typename S>
328 bool operator==(const auto_block<T, S>& xblk1, const auto_block<T, S>& xblk2);
329 
333 template <typename T, typename S>
334 std::ostream& operator << (std::ostream& xos, const auto_block<T, S>& xblk);
335 
340 template <typename T, typename S>
341 size_t deep_size(const auto_block<T, S>& xp, bool xinclude_shallow = true);
342 
349 template <typename T, typename S>
350 size_t deep_size(const auto_block<T*, S>& xp, bool xinclude_shallow = true);
351 
352 } // namespace sheaf
353 
354 #endif // AUTO_BLOCK_H
An auto_block value initialization policy that leaves the values uninitialized.
Definition: auto_block.h:42
const T & const_reference_type
A type that behaves as a const reference to the container&#39;s value type.
Definition: auto_block.h:145
unsigned long int size_type
An unsigned integral type used to represent sizes and capacities.
Definition: auto_block.h:171
A contiguously allocated array of items of type T with size information and automatic resizing...
Definition: auto_block.h:122
T * pointer_type
A type that behaves as a pointer to the container&#39;s value type.
Definition: auto_block.h:150
S initialization_policy
The value initialization policy.
Definition: auto_block.h:135
SHEAF_DLL_SPEC void assign(sec_vd &x0, const sec_vd &x1, bool xauto_access)
Assignment to another section; makes x0 have the same value as x1 on the meet of their bases...
Definition: sec_vd.cc:2235
A auto_block initialization policy that initializes the values to zero.
Definition: auto_block.h:102
const T * const_pointer_type
A type that behaves as a const pointer to the container&#39;s value type.
Definition: auto_block.h:155
A auto_block initialization policy that initializes the values to invalid.
Definition: auto_block.h:61
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.
signed long int difference_type
A signed integral type used to represent the difference of two indices or iterators.
Definition: auto_block.h:166
size_type _ct
The number of items currently stored.
Definition: auto_block.h:316
bool operator==(const singly_linked_list< T, Alloc > &lhs, const singly_linked_list< T, Alloc > &rhs)
Checks if the contents of lhs and rhs are equal, that is, whether lhs.size() == rhs.size() and each element in lhs compares equal with the element in rhs at the same position.
index_type _ub
The index upper bound.
Definition: auto_block.h:311
sheaf::pod_index_type index_type
The containers index type.
Definition: auto_block.h:160
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
Namespace for the sheaves component of the sheaf system.
T value_type
The type of value stored in the container.
Definition: auto_block.h:130
pointer_type _base
Start of storage for this.
Definition: auto_block.h:306
T & reference_type
A type that behaves as a reference to the container&#39;s value type.
Definition: auto_block.h:140
static void initialize(T *xbegin, T *xend)
Initializes the range [xbegin, xend).