ITK  4.6.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 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 
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 
124 
127  { this->SetGrowthStrategy(LINEAR_GROWTH); }
128 
129 protected:
130  ObjectStore();
131  ~ObjectStore();
132  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
133 
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  ObjectStore(const Self &); //purposely not implemented
156  void operator=(const Self &); //purposely not implemented
157 
159 
162 
165 
167  std::vector< MemoryBlock > m_Store;
168 };
169 } // end namespace itk
170 
171 #ifndef ITK_MANUAL_INSTANTIATION
172 #include "itkObjectStore.hxx"
173 #endif
174 
175 #endif
SizeValueType GetGrowthSize()
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
ObjectType * Borrow()
unsigned long SizeValueType
Definition: itkIntTypes.h:143
void SetGrowthStrategyToLinear()
virtual void SetGrowthStrategy(GrowthStrategyType _arg)
SizeValueType m_LinearGrowthSize
SmartPointer< const Self > ConstPointer
void SetGrowthStrategyToExponential()
void operator=(const Self &)
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
SmartPointer< Self > Pointer
GrowthStrategyType m_GrowthStrategy
ObjectStore Self
std::vector< MemoryBlock > m_Store
TObjectType ObjectType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void Reserve(SizeValueType n)
SizeValueType m_Size
Base class for most ITK classes.
Definition: itkObject.h:57
FreeListType m_FreeList
A specialized memory management object for allocating and destroying contiguous blocks of objects...
void Return(ObjectType *p)