ObjectPool.h

00001 #ifndef SCTDATA_OBJECTPOOL_H
00002 #define SCTDATA_OBJECTPOOL_H
00003 
00004 #include <list>
00005 #include <boost/shared_ptr.hpp>
00006 #include <boost/thread/mutex.hpp>
00007 
00008 using boost::shared_ptr;
00009 using boost::mutex;
00010 using std::list;
00011 
00012 namespace SctData {
00013  
00014 template<typename T> class ObjectPoolDeleter;
00015     
00031 template<typename T>
00032     class ObjectPool {
00033 public:
00034     ~ObjectPool();
00035     
00040     shared_ptr<T> get();
00041     
00047     void clear();
00048     
00053     unsigned int poolSize() const;
00054     
00059     void resize(unsigned int n);
00060     
00061 private:    
00066     shared_ptr<T> wrap(T* ptr);
00067     
00071     T* create();
00072     
00073     friend class ObjectPoolDeleter<T>;  
00074     list<T*> pool;      
00075     mutex poolMutex;        
00076 };
00077     
00078     
00079 }
00080 #include "ObjectPool.inl"
00081 
00082 #endif //SCTDATA_OBJECTPOOL_H

Generated on Mon Feb 6 14:01:24 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6