Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
|
Simple, templated concrete subclass of universal "Abstract Factory" interface for the creation of objects. More...
#include <Teuchos_AbstractFactoryStd.hpp>
Public Types | |
typedef Teuchos::AbstractFactory < T_itfc >::obj_ptr_t | obj_ptr_t |
Public Member Functions | |
AbstractFactoryStd (const T_PostMod &post_mod=T_PostMod(), const T_Allocator &alloc=T_Allocator()) | |
Public Member Functions inherited from Teuchos::AbstractFactory< T_itfc > | |
virtual | ~AbstractFactory () |
Private Attributes | |
T_PostMod | post_mod_ |
T_Allocator | alloc_ |
Related Functions | |
(Note that these are not member functions.) | |
template<class T_itfc , class T_impl , class T_Allocator > | |
RCP< const AbstractFactory< T_itfc > > | |
Nonmember constructor for an standar abstract factory object. More... | |
template<class T_itfc , class T_impl > | |
RCP< const AbstractFactory < T_itfc > > | abstractFactoryStd () |
Nonmember constructor for an standar abstract factory object. More... | |
Overriden from AbstractFactory | |
obj_ptr_t | create () const |
Simple, templated concrete subclass of universal "Abstract Factory" interface for the creation of objects.
This concrete subclass represents a general AbstractFactory
subclass that can be modified through policy template parameters. This class is templated on the interface type T_itfc
that is exposed by the AbstractFactory<T_itfc>
base interface and by a (concrete) implementation type T_impl
. The most typical use of this subclass is to use a concrete, default-constructable subclass for T_impl
and then to simply instantiate a concrete abstract factory for that class using:
Teuchos::AbstractFactoryStd<T_itfc,T_impl> abstractFactory;
For this default usage, The only requirements for the derived classes type T_impl
is that it allow the default constructor T_impl::T_impl()
(i.e. dont make T_impl::T_impl()
private) and that it allow T_impl::new()
and T_impl::delete
(i.e. don't make them private functions, see Meyers, More Effective C++, Item 27).
However, this subclass is also templated on two other policy types that allow a modification on how objects are created and destroyed. The first templated policy type, T_PostMod
, defines how an object is modified after it is initially created. The second templated policy type, T_Allocator
, defines exactly how an object is created (and therefore also how it is destroyed). These type two policy classes are described in more detail below.
The type T_PostMod
is responsible for performing any post modifications on a dynamically allocated object before returning it from create()
. The requirements for the type T_PostMod
are that it has a default constructor, a copy constructor and a method T_PostMod::initialize(T_itfc2*) const
that will perform any required post modifications (initializations). The type T_itfc2
argument for this function must be a base class of T_impl
of course. The default type for T_PostMod
is PostModNothing
<T_impl>
which does nothing.
The type T_Allocator
allows for specialized memory allocation and cleanup. This type must allow the default constructor and copy constructor and have a method Teuchos::RCP<T_impl> T_Allocator::allocate() const
which creates a smart reference-counted pointer to the allocated object. Also, in returning a RCP<>
object, the client can set a deallocatioin policy object that can specialize the deallocation of the object (see RCP
). In defining a specialized T_Allocator
class, the client can all initialize the object using more than just the default constructor. Therefore, if the client provides a specialized T_Allocator
class, there are no restrictions on the class T_impl
(i.e. does not have to have a default constructor or allow new
or delete
). The default class for T_Allocator
is AllocatorNew
<T_impl>
who's allocate()
function just returns rcp(new T_impl())
.
Since the T_Allocator
class can specialize both the memory management and can initialize the object using more that the default constructor, the class T_PostMod
may seem unecessary. However, it is more likely that the client will want to define an initialization for a set of classes through an abstract interface and can not for a particular concrete subclass. Also the initialization for an object can be orthogonal to how it is created and destroyed, thus the two classes T_PostMod
and T_Allocator
are both needed for a more general implementation.
Definition at line 110 of file Teuchos_AbstractFactoryStd.hpp.
typedef Teuchos::AbstractFactory<T_itfc>::obj_ptr_t Teuchos::AbstractFactoryStd< T_itfc, T_impl, T_PostMod, T_Allocator >::obj_ptr_t |
Definition at line 113 of file Teuchos_AbstractFactoryStd.hpp.
|
inline |
Definition at line 166 of file Teuchos_AbstractFactoryStd.hpp.
|
inlinevirtual |
Implements Teuchos::AbstractFactory< T_itfc >.
Definition at line 176 of file Teuchos_AbstractFactoryStd.hpp.
|
related |
Nonmember constructor for an standar abstract factory object.
Definition at line 152 of file Teuchos_AbstractFactoryStd.hpp.
|
related |
Nonmember constructor for an standar abstract factory object.
Definition at line 137 of file Teuchos_AbstractFactoryStd.hpp.
|
private |
Definition at line 125 of file Teuchos_AbstractFactoryStd.hpp.
|
private |
Definition at line 126 of file Teuchos_AbstractFactoryStd.hpp.