ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkObjectStore_h 00019 #define __itkObjectStore_h 00020 00021 #include "itkObjectFactory.h" 00022 #include "itkObject.h" 00023 #include "itkIntTypes.h" 00024 #include <vector> 00025 00026 namespace itk 00027 { 00062 template< class TObjectType > 00063 class ITK_EXPORT ObjectStore:public Object 00064 { 00065 public: 00067 typedef ObjectStore Self; 00068 typedef Object Superclass; 00069 typedef SmartPointer< Self > Pointer; 00070 typedef SmartPointer< const Self > ConstPointer; 00071 00073 itkNewMacro(Self); 00074 00076 itkTypeMacro(ObjectStore, Object); 00077 00079 typedef TObjectType ObjectType; 00080 00082 typedef std::vector< ObjectType * > FreeListType; 00083 00085 typedef enum { LINEAR_GROWTH = 0, EXPONENTIAL_GROWTH = 1 } GrowthStrategyType; 00086 00088 ObjectType * Borrow(); 00089 00093 void Return(ObjectType *p); 00094 00097 itkGetConstMacro(Size, SizeValueType); 00098 00102 void Reserve(SizeValueType n); 00103 00106 void Squeeze(); 00107 00109 void Clear(); 00110 00112 itkSetMacro(LinearGrowthSize, SizeValueType); 00113 itkGetConstMacro(LinearGrowthSize, SizeValueType); 00115 00117 itkSetMacro(GrowthStrategy, GrowthStrategyType); 00118 itkGetConstMacro(GrowthStrategy, GrowthStrategyType); 00120 00122 void SetGrowthStrategyToExponential() 00123 { this->SetGrowthStrategy(EXPONENTIAL_GROWTH); } 00124 00126 void SetGrowthStrategyToLinear() 00127 { this->SetGrowthStrategy(LINEAR_GROWTH); } 00128 protected: 00129 ObjectStore(); 00130 ~ObjectStore(); 00131 virtual void PrintSelf(std::ostream & os, Indent indent) const; 00133 00135 SizeValueType GetGrowthSize(); 00136 00137 struct MemoryBlock { 00138 MemoryBlock():Size(0), Begin(0) {} 00139 00140 MemoryBlock(SizeValueType n):Size(n) 00141 { Begin = new ObjectType[n]; } 00142 00143 ~MemoryBlock() {} // Purposely does *not* free memory 00144 00145 void Delete() 00146 { if ( Begin != 0 ) { delete[] Begin; } } 00147 00148 ObjectType *Begin; 00149 SizeValueType Size; 00150 }; 00151 private: 00152 ObjectStore(const Self &); //purposely not implemented 00153 void operator=(const Self &); //purposely not implemented 00154 00155 GrowthStrategyType m_GrowthStrategy; 00156 00157 SizeValueType m_Size; 00158 SizeValueType m_LinearGrowthSize; 00159 00161 FreeListType m_FreeList; 00162 00164 std::vector< MemoryBlock > m_Store; 00165 }; 00166 } // end namespace itk 00167 00168 #ifndef ITK_MANUAL_INSTANTIATION 00169 #include "itkObjectStore.hxx" 00170 #endif 00171 00172 #endif 00173