SheafSystem  0.0.0.0
list_pool.h
Go to the documentation of this file.
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 
20 
21 #ifndef LIST_POOL_H
22 #define LIST_POOL_H
23 
24 #ifndef SHEAF_DLL_SPEC_H
25 #include "SheafSystem/sheaf_dll_spec.h"
26 #endif
27 
28 #ifndef SINGLY_LINKED_LIST_H
29 #include "SheafSystem/singly_linked_list.h"
30 #endif
31 
32 #ifndef STD_UNORDERED_SET_H
33 #include "SheafSystem/std_unordered_set.h"
34 #endif
35 
36 namespace sheaf
37 {
38 
39 // Forward declarations to enable friend declaration.
40 
41 template <typename T>
42 class list_pool;
43 template <typename T>
44 size_t deep_size(const list_pool<T>& xpool, bool xinclude_shallow);
45 
49 template <typename T>
50 struct ptr_hash
51 {
52 public:
53  size_t operator()(const T& t) const
54  {
55  return (size_t) t;
56  }
57 };
58 
62 template <typename T>
64 {
65 public:
66  bool operator()(const T& t1, const T& t2) const
67  {
68  return (t1 == t2);
69  }
70 };
71 
78 template <typename T>
79 class list_pool
80 {
81 
82  friend size_t deep_size<T>(const list_pool<T>& xpool, bool xinclude_shallow);
83 
84  // ===========================================================
86  // ===========================================================
88 
89 public:
90 
94  typedef unsigned long int size_type;
95 
99  list_pool();
100 
104  virtual ~list_pool();
105 
109  T& get();
110 
114  void release(T& xobj);
115 
119  bool allocated(const T& xobj) const;
120 
122  // The number of allocated objects.
124  size_type ct() const;
125 
126 protected:
127 
128 private:
129 
134 
138  typedef unordered::unordered_set<T*, ptr_hash<T*>, ptr_key_test<T*> > allocated_type;
139 
143  list_pool(const list_pool& xother) { };
144 
148  free_list_type _free_list;
149 
153  allocated_type _allocated;
154 
156 };
157 
158 // ===========================================================
159 // NON-MEMBER FUNCTIONS
160 // ===========================================================
161 
165 template <typename T>
166 size_t deep_size(const list_pool<T>& xpool, bool xinclude_shallow);
167 
168 } // namespace sheaf
169 
170 #endif // ifndef LIST_POOL_H
Hash function for pointers.
Definition: list_pool.h:50
Hash set key test for a pointer to type T.
Definition: list_pool.h:63
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.
Namespace for the sheaves component of the sheaf system.
unsigned long int size_type
An unsigned integral type used to represent sizes and capacities.
Definition: list_pool.h:94
A reallocated pool of objects of type T. Objects in the pool are either allocated or stored in a free...
Definition: list_pool.h:42