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: 2009-04-25 12:24:12 $
00007   Version:   $Revision: 1.5 $
00008 
00009   Copyright (c) Insight Software 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 
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   itkGetConstMacro(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   itkGetConstMacro(LinearGrowthSize, ::size_t);
00112 
00114   itkSetMacro(GrowthStrategy, GrowthStrategyType);
00115   itkGetConstMacro(GrowthStrategy, GrowthStrategyType);
00117 
00119   void SetGrowthStrategyToExponential()
00120     { this->SetGrowthStrategy(EXPONENTIAL_GROWTH); }
00121 
00123   void SetGrowthStrategyToLinear()
00124     { this->SetGrowthStrategy(LINEAR_GROWTH); }
00125 
00126 protected:
00127   ObjectStore();
00128   ~ObjectStore();
00129   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00130 
00132   ::size_t GetGrowthSize();
00133 
00134   struct MemoryBlock
00135     {
00136     MemoryBlock(): Size(0), Begin(0) {}
00137 
00138     MemoryBlock(::size_t n) : Size(n)
00139       { Begin = new ObjectType[n];  }
00140 
00141     ~MemoryBlock()  {  } // Purposely does *not* free memory
00142 
00143     void Delete()
00144       { if (Begin !=0) delete[] Begin; }
00145     
00146     ObjectType *Begin;
00147     ::size_t Size;
00148     };
00149   
00150 private:
00151   ObjectStore(const Self&);    //purposely not implemented
00152   void operator=(const Self&); //purposely not implemented
00153 
00154   GrowthStrategyType m_GrowthStrategy;
00155   
00156   ::size_t m_Size;
00157   ::size_t m_LinearGrowthSize;
00158   
00160   FreeListType  m_FreeList;
00161 
00163   std::vector<MemoryBlock>   m_Store;
00164 
00165 };
00166 
00167   
00168 } // end namespace itk
00169 
00170 #ifndef ITK_MANUAL_INSTANTIATION
00171 #include "itkObjectStore.txx"
00172 #endif
00173 
00174 #endif
00175 

Generated at Mon Jul 12 2010 19:20:03 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000