ITK  4.3.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< class TObjectType >
63 class ITK_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 
122  void SetGrowthStrategyToExponential()
123  { this->SetGrowthStrategy(EXPONENTIAL_GROWTH); }
124 
126  void SetGrowthStrategyToLinear()
127  { this->SetGrowthStrategy(LINEAR_GROWTH); }
128 
129 protected:
130  ObjectStore();
131  ~ObjectStore();
132  virtual void PrintSelf(std::ostream & os, Indent indent) const;
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  { if ( Begin != 0 ) { delete[] Begin; } }
147 
150  };
151 
152 private:
153  ObjectStore(const Self &); //purposely not implemented
154  void operator=(const Self &); //purposely not implemented
155 
157 
160 
163 
165  std::vector< MemoryBlock > m_Store;
166 };
167 } // end namespace itk
168 
169 #ifndef ITK_MANUAL_INSTANTIATION
170 #include "itkObjectStore.hxx"
171 #endif
172 
173 #endif
174