ITK  4.13.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:
67  typedef ObjectStore Self;
68  typedef Object Superclass;
71 
73  itkNewMacro(Self);
74 
76  itkTypeMacro(ObjectStore, Object);
77 
79  typedef TObjectType ObjectType;
80 
82  typedef std::vector< ObjectType * > FreeListType;
83 
85  typedef enum { LINEAR_GROWTH = 0, EXPONENTIAL_GROWTH = 1 } GrowthStrategyType;
86 
88  ObjectType * Borrow();
89 
93  void Return(ObjectType *p);
94 
97  itkGetConstMacro(Size, SizeValueType);
98 
102  void Reserve(SizeValueType n);
103 
106  void Squeeze();
107 
109  void Clear();
110 
112  itkSetMacro(LinearGrowthSize, SizeValueType);
113  itkGetConstMacro(LinearGrowthSize, SizeValueType);
115 
117  itkSetMacro(GrowthStrategy, GrowthStrategyType);
118  itkGetConstMacro(GrowthStrategy, GrowthStrategyType);
120 
123  { this->SetGrowthStrategy(EXPONENTIAL_GROWTH); }
124 
127  { this->SetGrowthStrategy(LINEAR_GROWTH); }
128 
129 protected:
130  ObjectStore();
131  ~ObjectStore() ITK_OVERRIDE;
132  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
133 
135  SizeValueType GetGrowthSize();
136 
137  struct MemoryBlock {
138  MemoryBlock():Size(0), Begin(0) {}
139 
141  { Begin = new ObjectType[n]; }
142 
143  ~MemoryBlock() {} // Purposely does *not* free memory
144 
145  void Delete()
146  {
147  delete[] Begin;
148  }
149 
152  };
153 
154 private:
155  ITK_DISALLOW_COPY_AND_ASSIGN(ObjectStore);
156 
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.
Represent the size (bounds) of a n-dimensional image.
Definition: itkSize.h:52
std::vector< ObjectType * > FreeListType
unsigned long SizeValueType
Definition: itkIntTypes.h:143
void SetGrowthStrategyToLinear()
SizeValueType m_LinearGrowthSize
SmartPointer< const Self > ConstPointer
void SetGrowthStrategyToExponential()
SmartPointer< Self > Pointer
GrowthStrategyType m_GrowthStrategy
ObjectStore Self
std::vector< MemoryBlock > m_Store
TObjectType ObjectType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
SizeValueType m_Size
Base class for most ITK classes.
Definition: itkObject.h:59
FreeListType m_FreeList
A specialized memory management object for allocating and destroying contiguous blocks of objects...