SheafSystem  0.0.0.0
ptr_linked_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 PTR_LINKED_POOL
19 
20 #ifndef PTR_LINKED_POOL_H
21 #define PTR_LINKED_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 STD_IOSTREAM_H
32 #include "SheafSystem/std_iostream.h"
33 #endif
34 
35 #ifndef SINGLY_LINKED_LIST_H
36 #include "SheafSystem/singly_linked_list.h"
37 #endif
38 
39 namespace sheaf
40 {
41 
50 template <typename T>
51 class SHEAF_DLL_SPEC ptr_linked_pool
52 {
53 public:
54 
55 
60  size_t capacity() const;
61 
65  size_t free_size() const;
66 
70  size_t allocated_size() const;
71 
75  void reserve(size_t xcapacity);
76 
80  void clear();
81 
85  T* allocate();
86 
90  void deallocate(T* xobject);
91 
96  void print() const;
97 
102  void print(std::ostream& xos) const;
103 
107  ptr_linked_pool(size_t xcapacity = 1024);
108 
112  ~ptr_linked_pool();
113 
114 
115 private:
116 
120  size_t _capacity;
121 
125  size_t _free_size;
126 
130  T* _free_list;
131 
135  singly_linked_list<block<T>*> _chunk_list;
136 
137 };
138 
139 
140 //==============================================================================
141 // NON-MEMBER FUNCTIONS
142 //==============================================================================
143 
147 template <typename T>
148 std::ostream& operator<< (std::ostream& xos, const ptr_linked_pool<T>& xp);
149 
150 
151 } // namespace sheaf
152 
153 #endif // ifndef PTR_LINKED_POOL_H
Namespace for the sheaves component of the sheaf system.