Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_AbstractFactoryStd.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TEUCHOS_ABSTRACT_FACTORY_STD_HPP
11 #define TEUCHOS_ABSTRACT_FACTORY_STD_HPP
12 
14 
15 namespace Teuchos {
16 
20 template<class T_impl>
22 public:
24  void initialize(T_impl* /* p */) const {} // required!
25 };
26 
30 template<class T_impl>
31 class AllocatorNew {
32 public:
34  typedef Teuchos::RCP<T_impl> ptr_t; // required!
36  const ptr_t allocate() const { return Teuchos::rcp(new T_impl()); } // required!
37 };
38 
106 template<class T_itfc, class T_impl
107  ,class T_PostMod = PostModNothing<T_impl>
108  ,class T_Allocator = AllocatorNew<T_impl>
109  >
110 class AbstractFactoryStd : public AbstractFactory<T_itfc> {
111 public:
112 
113  typedef typename Teuchos::AbstractFactory<T_itfc>::obj_ptr_t obj_ptr_t; // RAB: 20030916: G++ 3.2 complains without this
114 
116  AbstractFactoryStd( const T_PostMod& post_mod = T_PostMod(), const T_Allocator& alloc = T_Allocator() );
117 
121  obj_ptr_t create() const;
123 
124 private:
125  T_PostMod post_mod_;
126  T_Allocator alloc_;
127 
128 };
129 
130 
135 template<class T_itfc, class T_impl>
138 {
139  return rcp(
141  );
142 }
143 
144 
149 template<class T_itfc, class T_impl, class T_Allocator>
151 abstractFactoryStd( const T_Allocator& alloc = T_Allocator() )
152 {
153  return rcp(
154  new AbstractFactoryStd<T_itfc,T_impl,PostModNothing<T_impl>,T_Allocator>(
155  PostModNothing<T_impl>(), alloc
156  )
157  );
158 }
159 
160 
161 // ///////////////////////////////////////////////////////
162 // Template member definitions
163 
164 template<class T_itfc, class T_impl, class T_PostMod, class T_Allocator>
165 inline
167  const T_PostMod& post_mod, const T_Allocator& alloc
168  )
169  :post_mod_(post_mod)
170  ,alloc_(alloc)
171 {}
172 
173 template<class T_itfc, class T_impl, class T_PostMod, class T_Allocator>
174 inline
177 {
178  typename T_Allocator::ptr_t
179  ptr = alloc_.allocate();
180  post_mod_.initialize(ptr.get());
181  return ptr;
182 }
183 
184 } // end Teuchos
185 
186 #endif // TEUCHOS_ABSTRACT_FACTORY_STD_HPP
AbstractFactoryStd(const T_PostMod &post_mod=T_PostMod(), const T_Allocator &alloc=T_Allocator())
Simple, templated concrete subclass of universal &quot;Abstract Factory&quot; interface for the creation of o...
Teuchos::AbstractFactory< T_itfc >::obj_ptr_t obj_ptr_t
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
RCP< const AbstractFactory< T_itfc > > abstractFactoryStd()
Nonmember constructor for an standar abstract factory object.
Smart reference counting pointer class for automatic garbage collection.
Default post-modification policy class for AbstractFactorStd which does nothing!
Simple, universal &quot;Abstract Factory&quot; interface for the dynamic creation of objects.
Default allocation policy class for AbstractFactoryStd which returns new T_impl().