SheafSystem  0.0.0.0
pool.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 POOL
19 
20 #ifndef POOL_H
21 #define POOL_H
22 
23 #ifndef SHEAF_DLL_SPEC_H
24 #include "SheafSystem/sheaf_dll_spec.h"
25 #endif
26 
27 #ifndef BLOCK_H
28 #include "SheafSystem/block.h"
29 #endif
30 
31 #ifndef INDEX_ITERATOR_H
32 #include "SheafSystem/index_iterator.h"
33 #endif
34 
35 #ifndef STD_IOSTREAM_H
36 #include "SheafSystem/std_iostream.h"
37 #endif
38 
39 #ifndef SINGLY_LINKED_LIST_H
40 #include "SheafSystem/singly_linked_list.h"
41 #endif
42 
43 #ifndef SINGLY_LINKED_LIST_H
44 #include "SheafSystem/singly_linked_list.h"
45 #endif
46 
47 namespace sheaf
48 {
49 
50 class zn_to_bool;
51 
52 // Forward declarations to enable friend declaration.
53 
54 template <class T, int EXTENSION_FACTOR>
55 class pool;
56 template <class T, int EXTENSION_FACTOR>
57  size_t deep_size(const pool<T, EXTENSION_FACTOR>& xpool, bool xinclude_shallow);
58 
59 
68 template <typename T, int EXTENSION_FACTOR=2>
69 class pool
70 {
71  friend size_t deep_size<T, EXTENSION_FACTOR>
72  (const pool<T,EXTENSION_FACTOR>& xpool, bool xinclude_shallow);
73 
74 public:
75 
79  typedef T value_type;
80 
84  typedef T& reference_type;
85 
89  typedef const T& const_reference_type;
90 
94  typedef T* pointer_type;
95 
99  typedef const T* const_pointer_type;
100 
105 
111 
115  typedef unsigned long int size_type;
116 
120  bool invariant() const;
121 
126  pod_index_type index_ub() const;
127 
131  bool index_in_bounds(pod_index_type xindex) const;
132 
136  int free_ct() const;
137 
141  pod_index_type free_list() const;
142 
146  int allocated_ct() const;
147 
151  bool is_allocated(pod_index_type xindex) const;
152 
156  T& item(pod_index_type xindex);
157 
161  T & operator[](pod_index_type xindex);
162 
167 
172 
176  void deallocate(pod_index_type xindex);
177 
182  void print() const;
183 
188  void print(std::ostream &out) const;
189 
193  pool(pod_index_type xub);
194 
198  ~pool();
199 
200 
201 private:
202 
206  int _allocated_ct;
207 
211  int _free_ct;
212 
216  pod_index_type _free_list;
217 
221  typedef block<T*> pool_type;
222 
226  pool_type _pool;
227 
231  singly_linked_list<T*> _chunk_list;
232 
236  zn_to_bool* _is_allocated;
237 
241  void extend_to(pod_index_type xub);
242 
243 };
244 
245 // ===========================================================
246 // NON-MEMBER FUNCTIONS
247 // ===========================================================
248 
252 template <typename T, int EXTENSION_FACTOR>
253 size_t
254 deep_size(const pool<T, EXTENSION_FACTOR>& xpool, bool xinclude_shallow);
255 
256 } // namespace sheaf
257 
258 #endif // ifndef POOL_H
int free_ct() const
The size of free list.
Definition: pool.impl.h:93
index_iterator allocated_iterator() const
An iterator over allocated items in the pool.
Definition: pool.impl.h:139
T & reference_type
A type that behaves as a reference to the container&#39;s value type.
Definition: pool.h:84
bool is_allocated(pod_index_type xindex) const
True if xindex is allocated.
Definition: pool.impl.h:117
bool invariant() const
Class invariant.
Definition: pool.impl.h:49
pod_index_type difference_type
A signed integral type used to represent the difference of two indices or iterators.
Definition: pool.h:110
unsigned long int size_type
An unsigned integral type used to represent sizes and capacities.
Definition: pool.h:115
T * pointer_type
A type that behaves as a pointer to the container&#39;s value type.
Definition: pool.h:94
A map from Zn (the integers mod n) to bools. A characteristic function used to represent subsets of Z...
Definition: zn_to_bool.h:52
T value_type
The container&#39;s value type.
Definition: pool.h:79
void deallocate(pod_index_type xindex)
Deallocate item at xindex.
Definition: pool.impl.h:200
int allocated_ct() const
The size of allocated list.
Definition: pool.impl.h:109
pod_index_type index_ub() const
The upper bound on the index for members of the pool.
Definition: pool.impl.h:65
A reallocatable pool of objects of type T. Objects in the pool are either "allocated" or linked toget...
Definition: pool.h:55
~pool()
Destructor.
Definition: pool.impl.h:258
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.
const T * const_pointer_type
A type that behaves as a const pointer to the container&#39;s value type.
Definition: pool.h:99
const T & const_reference_type
A type that behaves as a const reference to the container&#39;s value type.
Definition: pool.h:89
Iterates over the subset of Zn defined by the characteristic function host().
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
pod_index_type index_type
The containers index type.
Definition: pool.h:104
void print() const
Prints the data members of this on cout. Intended for use debugging.
Definition: pool.impl.h:409
T & item(pod_index_type xindex)
A pointer to the pool item at xindex.
Definition: pool.impl.h:278
Namespace for the sheaves component of the sheaf system.
bool index_in_bounds(pod_index_type xindex) const
True if xindex is in bounds.
Definition: pool.impl.h:85
pool(pod_index_type xub)
Creates an instance with xub upper bound.
Definition: pool.impl.h:229
pod_index_type free_list() const
The head of the free list.
Definition: pool.impl.h:101
T & operator[](pod_index_type xindex)
A reference to the pool item at xindex.
Definition: pool.impl.h:297
pod_index_type allocate()
Allocate next available index from free list.
Definition: pool.impl.h:159
friend size_t deep_size(const pool< T, EXTENSION_FACTOR > &xpool, bool xinclude_shallow)
The deep size of the referenced object of type pool<T, int>.
Definition: pool.impl.h:453