Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkObjectStore.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkObjectStore.h,v $
00005   Language:  C++
00006   Date:      $Date: 2002/05/15 17:13:45 $
00007   Version:   $Revision: 1.1 $
00008 
00009   Copyright (c) 2002 Insight Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
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()  {  } // Purposely does *not* free memory
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&);    //purposely not implemented
00140   void operator=(const Self&); //purposely not implemented
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 } // end namespace itk
00156 
00157 #ifndef ITK_MANUAL_INSTANTIATION
00158 #include "itkObjectStore.txx"
00159 #endif
00160 
00161 #endif

Generated at Fri May 21 01:15:09 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000