00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef TEUCHOS_ABSTRACT_FACTORY_STD_HPP
00030 #define TEUCHOS_ABSTRACT_FACTORY_STD_HPP
00031
00032 #include "Teuchos_AbstractFactory.hpp"
00033
00034 namespace Teuchos {
00035
00039 template<class T_impl>
00040 class PostModNothing {
00041 public:
00043 void initialize(T_impl* p) const {}
00044 };
00045
00049 template<class T_impl>
00050 class AllocatorNew {
00051 public:
00053 typedef Teuchos::RefCountPtr<T_impl> ptr_t;
00055 const ptr_t allocate() const { return Teuchos::rcp(new T_impl()); }
00056 };
00057
00125 template<class T_itfc, class T_impl
00126 ,class T_PostMod = PostModNothing<T_impl>
00127 ,class T_Allocator = AllocatorNew<T_impl>
00128 >
00129 class AbstractFactoryStd : public AbstractFactory<T_itfc> {
00130 public:
00131
00132 typedef typename Teuchos::AbstractFactory<T_itfc>::obj_ptr_t obj_ptr_t;
00133
00134
00135
00136
00137
00138
00139
00140
00142 AbstractFactoryStd( const T_PostMod& post_mod = T_PostMod(), const T_Allocator& alloc = T_Allocator() );
00143
00147 obj_ptr_t create() const;
00149
00150 private:
00151 T_PostMod post_mod_;
00152 T_Allocator alloc_;
00153
00154 };
00155
00157 template<class T_itfc, class T_impl, class T_Allocator >
00158 const Teuchos::RefCountPtr<const AbstractFactory<T_itfc> >
00159 abstract_factory_std_alloc(
00160 const T_Allocator& alloc = T_Allocator()
00161 )
00162 {
00163 return rcp(
00164 new AbstractFactoryStd<T_itfc,T_impl,PostModNothing<T_impl>,T_Allocator>(
00165 PostModNothing<T_impl>(), alloc )
00166 );
00167 }
00168
00169
00170
00171
00172 template<class T_itfc, class T_impl, class T_PostMod, class T_Allocator>
00173 inline
00174 AbstractFactoryStd<T_itfc,T_impl,T_PostMod,T_Allocator>::AbstractFactoryStd(
00175 const T_PostMod& post_mod, const T_Allocator& alloc
00176 )
00177 :post_mod_(post_mod)
00178 ,alloc_(alloc)
00179 {}
00180
00181 template<class T_itfc, class T_impl, class T_PostMod, class T_Allocator>
00182 inline
00183 typename AbstractFactoryStd<T_itfc,T_impl,T_PostMod,T_Allocator>::obj_ptr_t
00184 AbstractFactoryStd<T_itfc,T_impl,T_PostMod,T_Allocator>::create() const
00185 {
00186 typename T_Allocator::ptr_t
00187 ptr = alloc_.allocate();
00188 post_mod_.initialize(ptr.get());
00189 return ptr;
00190 }
00191
00192 }
00193
00194 #endif // TEUCHOS_ABSTRACT_FACTORY_STD_HPP