ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkObjectStore.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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.txt
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 #ifndef itkObjectStore_h
19 #define itkObjectStore_h
20 
21 #include "itkObjectFactory.h"
22 #include "itkObject.h"
23 #include "itkIntTypes.h"
24 #include <vector>
25 
26 namespace itk
27 {
62 template< typename TObjectType >
63 class ITK_TEMPLATE_EXPORT ObjectStore:public Object
64 {
65 public:
66  ITK_DISALLOW_COPY_AND_ASSIGN(ObjectStore);
67 
69  using Self = ObjectStore;
70  using Superclass = Object;
73 
75  itkNewMacro(Self);
76 
78  itkTypeMacro(ObjectStore, Object);
79 
81  using ObjectType = TObjectType;
82 
84  using FreeListType = std::vector< ObjectType * >;
85 
87  typedef enum { LINEAR_GROWTH = 0, EXPONENTIAL_GROWTH = 1 } GrowthStrategyType;
88 
90  ObjectType * Borrow();
91 
95  void Return(ObjectType *p);
96 
99  itkGetConstMacro(Size, SizeValueType);
100 
104  void Reserve(SizeValueType n);
105 
108  void Squeeze();
109 
111  void Clear();
112 
114  itkSetMacro(LinearGrowthSize, SizeValueType);
115  itkGetConstMacro(LinearGrowthSize, SizeValueType);
117 
119  itkSetMacro(GrowthStrategy, GrowthStrategyType);
120  itkGetConstMacro(GrowthStrategy, GrowthStrategyType);
122 
125  { this->SetGrowthStrategy(EXPONENTIAL_GROWTH); }
126 
129  { this->SetGrowthStrategy(LINEAR_GROWTH); }
130 
131 protected:
132  ObjectStore();
133  ~ObjectStore() override;
134  void PrintSelf(std::ostream & os, Indent indent) const override;
135 
137  SizeValueType GetGrowthSize();
138 
139  struct MemoryBlock {
140  MemoryBlock(): Begin(0) {}
141 
143  { Begin = new ObjectType[n]; }
144 
145  ~MemoryBlock() = default; // Purposely does *not* free memory
146 
147  void Delete()
148  {
149  delete[] Begin;
150  }
151 
154  };
155 
156 private:
158 
161 
164 
166  std::vector< MemoryBlock > m_Store;
167 };
168 } // end namespace itk
169 
170 #ifndef ITK_MANUAL_INSTANTIATION
171 #include "itkObjectStore.hxx"
172 #endif
173 
174 #endif
Light weight base class for most itk classes.
std::vector< ObjectType * > FreeListType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
TObjectType ObjectType
void SetGrowthStrategyToLinear()
SizeValueType m_LinearGrowthSize
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:68
void SetGrowthStrategyToExponential()
GrowthStrategyType m_GrowthStrategy
std::vector< MemoryBlock > m_Store
Control indentation during Print() invocation.
Definition: itkIndent.h:49
SizeValueType m_Size
Base class for most ITK classes.
Definition: itkObject.h:60
FreeListType m_FreeList
A specialized memory management object for allocating and destroying contiguous blocks of objects...