00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef LUMIERA_FACTORY_H
00025 #define LUMIERA_FACTORY_H
00026
00027 #include <tr1/memory>
00028
00029
00030
00031 namespace lumiera
00032 {
00033 namespace factory
00034 {
00042 template
00043 < class T,
00044 class SMP =std::auto_ptr<T>
00045 >
00046 class Wrapper
00047 {
00048 protected:
00049 SMP wrap (T* product) { return SMP (product); }
00050
00051 public:
00052 typedef SMP PType;
00053 };
00054
00055
00065 template
00066 < class T,
00067 class WR = Wrapper<T>
00068 >
00069 class Factory : public WR
00070 {
00071 public:
00078 typename WR::PType operator() () { return wrap (new T ); }
00079
00080 };
00081
00082
00083
00084
00085
00086
00087
00088 using std::tr1::shared_ptr;
00089
00094 template<class T>
00095 class Wrapper<T, shared_ptr<T> >
00096 {
00097 protected:
00098 shared_ptr<T> wrap (T* product) { return shared_ptr<T> (product); }
00099
00100 public:
00101 typedef shared_ptr<T> PType;
00102 };
00103
00104
00110 template<class T>
00111 class RefcountPtr : public Factory<T, Wrapper<T,shared_ptr<T> > >
00112 {
00113 public:
00114 typedef shared_ptr<T> PType;
00115 };
00116
00117
00124 template
00125 < class T,
00126 class TImpl
00127 >
00128 class PImplPtr : public Factory<T, Wrapper<T> >
00129 {
00130 public:
00131 typedef std::auto_ptr<T> PType;
00132
00133 PType operator() (){ return wrap (static_cast<T*> (new TImpl)); };
00134 };
00135
00136
00137
00138 }
00139
00141 using factory::Factory;
00142
00143
00144 }
00145 #endif