ITK  6.0.0
Insight Toolkit
itkObjectStore.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
26namespace itk
27{
35{
36public:
40 enum class GrowthStrategy : uint8_t
41 {
42 LINEAR_GROWTH = 0,
43 EXPONENTIAL_GROWTH = 1
44 };
45};
46extern ITKCommon_EXPORT std::ostream &
47 operator<<(std::ostream & out, const ObjectStoreEnums::GrowthStrategy value);
48
83template <typename TObjectType>
84class ITK_TEMPLATE_EXPORT ObjectStore : public Object
85{
86public:
87 ITK_DISALLOW_COPY_AND_MOVE(ObjectStore);
88
94
96 itkNewMacro(Self);
97
99 itkOverrideGetNameOfClassMacro(ObjectStore);
100
102 using ObjectType = TObjectType;
103
105 using FreeListType = std::vector<ObjectType *>;
106
108#if !defined(ITK_LEGACY_REMOVE)
109 // We need to expose the enum values at the class level
110 // for backwards compatibility
111 static constexpr GrowthStrategyEnum LINEAR_GROWTH = GrowthStrategyEnum::LINEAR_GROWTH;
112 static constexpr GrowthStrategyEnum EXPONENTIAL_GROWTH = GrowthStrategyEnum::EXPONENTIAL_GROWTH;
113#endif
115 ObjectType *
117
121 void
123
126 itkGetConstMacro(Size, SizeValueType);
127
131 void
133
136 void
138
140 void
142
144 itkSetMacro(LinearGrowthSize, SizeValueType);
145 itkGetConstMacro(LinearGrowthSize, SizeValueType);
149 itkSetEnumMacro(GrowthStrategy, GrowthStrategyEnum);
150 itkGetConstMacro(GrowthStrategy, GrowthStrategyEnum);
154 void
156 {
157 this->SetGrowthStrategy(GrowthStrategyEnum::EXPONENTIAL_GROWTH);
158 }
159
161 void
163 {
164 this->SetGrowthStrategy(GrowthStrategyEnum::LINEAR_GROWTH);
165 }
166
167protected:
168 ObjectStore() = default;
169 ~ObjectStore() override;
170 void
171 PrintSelf(std::ostream & os, Indent indent) const override;
172
176
178 {
179 MemoryBlock() = default;
180
182 : Size(n)
183 {
184 Begin = new ObjectType[n];
185 }
186
187 ~MemoryBlock() = default; // Purposely does *not* free memory
188
189 void
191 {
192 delete[] Begin;
193 }
194
195 ObjectType * Begin{};
197 };
198
199private:
200 GrowthStrategyEnum m_GrowthStrategy{ GrowthStrategyEnum::EXPONENTIAL_GROWTH };
201
203 SizeValueType m_LinearGrowthSize{ 1024 };
204
206 FreeListType m_FreeList{};
207
209 std::vector<MemoryBlock> m_Store{};
210};
211
212} // end namespace itk
213
214#ifndef ITK_MANUAL_INSTANTIATION
215# include "itkObjectStore.hxx"
216#endif
217
218#endif
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
enums for ObjectStore
A specialized memory management object for allocating and destroying contiguous blocks of objects.
void Return(ObjectType *p)
std::vector< ObjectType * > FreeListType
TObjectType ObjectType
void Reserve(SizeValueType n)
void PrintSelf(std::ostream &os, Indent indent) const override
~ObjectStore() override
ObjectType * Borrow()
SizeValueType GetGrowthSize()
ObjectStore()=default
void SetGrowthStrategyToExponential()
void SetGrowthStrategyToLinear()
Base class for most ITK classes.
Definition: itkObject.h:62
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
unsigned long SizeValueType
Definition: itkIntTypes.h:86
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:70