Teuchos_AbstractFactoryStd.hpp
Go to the documentation of this file.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::RCP<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
00135 AbstractFactoryStd( const T_PostMod& post_mod = T_PostMod(), const T_Allocator& alloc = T_Allocator() );
00136
00140 obj_ptr_t create() const;
00142
00143 private:
00144 T_PostMod post_mod_;
00145 T_Allocator alloc_;
00146
00147 };
00148
00149
00154 template<class T_itfc, class T_impl>
00155 RCP<const AbstractFactory<T_itfc> >
00156 abstractFactoryStd()
00157 {
00158 return rcp(
00159 new AbstractFactoryStd<T_itfc,T_impl,PostModNothing<T_impl>,AllocatorNew<T_impl> >()
00160 );
00161 }
00162
00163
00168 template<class T_itfc, class T_impl, class T_Allocator>
00169 RCP<const AbstractFactory<T_itfc> >
00170 abstractFactoryStd( const T_Allocator& alloc = T_Allocator() )
00171 {
00172 return rcp(
00173 new AbstractFactoryStd<T_itfc,T_impl,PostModNothing<T_impl>,T_Allocator>(
00174 PostModNothing<T_impl>(), alloc
00175 )
00176 );
00177 }
00178
00179
00180
00181
00182
00183 template<class T_itfc, class T_impl, class T_PostMod, class T_Allocator>
00184 inline
00185 AbstractFactoryStd<T_itfc,T_impl,T_PostMod,T_Allocator>::AbstractFactoryStd(
00186 const T_PostMod& post_mod, const T_Allocator& alloc
00187 )
00188 :post_mod_(post_mod)
00189 ,alloc_(alloc)
00190 {}
00191
00192 template<class T_itfc, class T_impl, class T_PostMod, class T_Allocator>
00193 inline
00194 typename AbstractFactoryStd<T_itfc,T_impl,T_PostMod,T_Allocator>::obj_ptr_t
00195 AbstractFactoryStd<T_itfc,T_impl,T_PostMod,T_Allocator>::create() const
00196 {
00197 typename T_Allocator::ptr_t
00198 ptr = alloc_.allocate();
00199 post_mod_.initialize(ptr.get());
00200 return ptr;
00201 }
00202
00203 }
00204
00205 #endif // TEUCHOS_ABSTRACT_FACTORY_STD_HPP