00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkObjectStore_h
00018 #define __itkObjectStore_h
00019
00020 #include "itkObjectFactory.h"
00021 #include "itkObject.h"
00022 #include <vector>
00023
00024 namespace itk {
00025
00059 template < class TObjectType >
00060 class ITK_EXPORT ObjectStore : public Object
00061 {
00062 public:
00064 typedef ObjectStore Self;
00065 typedef Object Superclass;
00066 typedef SmartPointer<Self> Pointer;
00067 typedef SmartPointer<const Self> ConstPointer;
00068
00070 itkNewMacro(Self);
00071
00073 itkTypeMacro(ObjectStore, Object);
00074
00076 typedef TObjectType ObjectType;
00077
00079 typedef std::vector<ObjectType *> FreeListType;
00080
00082 typedef enum {LINEAR_GROWTH = 0, EXPONENTIAL_GROWTH = 1} GrowthStrategyType;
00083
00085 ObjectType *Borrow();
00086
00090 void Return(ObjectType *p);
00091
00094 itkGetMacro(Size, ::size_t);
00095
00099 void Reserve(::size_t n);
00100
00103 void Squeeze();
00104
00106 void Clear();
00107
00109 itkSetMacro(LinearGrowthSize, ::size_t);
00110 itkGetMacro(LinearGrowthSize, ::size_t);
00111
00113 itkSetMacro(GrowthStrategy, GrowthStrategyType);
00114 itkGetMacro(GrowthStrategy, GrowthStrategyType);
00115
00117 void SetGrowthStrategyToExponential()
00118 { this->SetGrowthStrategy(EXPONENTIAL_GROWTH); }
00119
00121 void SetGrowthStrategyToLinear()
00122 { this->SetGrowthStrategy(LINEAR_GROWTH); }
00123
00124 protected:
00125 ObjectStore();
00126 ~ObjectStore();
00127 virtual void PrintSelf(std::ostream& os, Indent indent) const;
00128
00130 ::size_t GetGrowthSize();
00131
00132 struct MemoryBlock
00133 {
00134 MemoryBlock(): Size(0), Begin(0) {}
00135
00136 MemoryBlock(::size_t n) : Size(n)
00137 { Begin = new ObjectType[n]; }
00138
00139 ~MemoryBlock() { }
00140
00141 void Delete()
00142 { if (Begin !=0) delete[] Begin; }
00143
00144 ObjectType *Begin;
00145 ::size_t Size;
00146 };
00147
00148 private:
00149 ObjectStore(const Self&);
00150 void operator=(const Self&);
00151
00152 GrowthStrategyType m_GrowthStrategy;
00153
00154 ::size_t m_Size;
00155 ::size_t m_LinearGrowthSize;
00156
00158 FreeListType m_FreeList;
00159
00161 std::vector<MemoryBlock> m_Store;
00162
00163 };
00164
00165
00166 }
00167
00168 #ifndef ITK_MANUAL_INSTANTIATION
00169 #include "itkObjectStore.txx"
00170 #endif
00171
00172 #endif