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
00049 template < class TObjectType >
00050 class ITK_EXPORT ObjectStore : public Object
00051 {
00052 public:
00054 typedef ObjectStore Self;
00055 typedef Object Superclass;
00056 typedef SmartPointer<Self> Pointer;
00057 typedef SmartPointer<const Self> ConstPointer;
00058
00060 itkNewMacro(Self);
00061
00063 itkTypeMacro(ObjectStore, Object);
00064
00066 typedef TObjectType ObjectType;
00067
00069 typedef std::vector<ObjectType *> FreeListType;
00070
00072 typedef enum {LINEAR_GROWTH = 0, EXPONENTIAL_GROWTH = 1} GrowthStrategyType;
00073
00075 ObjectType *Borrow();
00076
00080 void Return(ObjectType *p);
00081
00084 itkGetMacro(Size, ::size_t);
00085
00089 void Reserve(::size_t n);
00090
00093 void Squeeze();
00094
00096 void Clear();
00097
00099 itkSetMacro(LinearGrowthSize, ::size_t);
00100 itkGetMacro(LinearGrowthSize, ::size_t);
00101
00103 itkSetMacro(GrowthStrategy, GrowthStrategyType);
00104 itkGetMacro(GrowthStrategy, GrowthStrategyType);
00105
00107 void SetGrowthStrategyToExponential()
00108 { this->SetGrowthStrategy(EXPONENTIAL_GROWTH); }
00109
00111 void SetGrowthStrategyToLinear()
00112 { this->SetGrowthStrategy(LINEAR_GROWTH); }
00113
00114 protected:
00115 ObjectStore();
00116 ~ObjectStore();
00117 virtual void PrintSelf(std::ostream& os, Indent indent) const;
00118
00120 ::size_t GetGrowthSize();
00121
00122 struct MemoryBlock
00123 {
00124 MemoryBlock(): Size(0), Begin(0) {}
00125
00126 MemoryBlock(::size_t n) : Size(n)
00127 { Begin = new ObjectType[n]; }
00128
00129 ~MemoryBlock() { }
00130
00131 void Delete()
00132 { if (Begin !=0) delete[] Begin; }
00133
00134 ObjectType *Begin;
00135 ::size_t Size;
00136 };
00137
00138 private:
00139 ObjectStore(const Self&);
00140 void operator=(const Self&);
00141
00142 GrowthStrategyType m_GrowthStrategy;
00143
00144 ::size_t m_Size;
00145 ::size_t m_LinearGrowthSize;
00146
00148 FreeListType m_FreeList;
00149
00151 std::vector<MemoryBlock> m_Store;
00152 };
00153
00154
00155 }
00156
00157 #ifndef ITK_MANUAL_INSTANTIATION
00158 #include "itkObjectStore.txx"
00159 #endif
00160
00161 #endif