Nektar++
|
Provides a generic Factory class. More...
#include <NekFactory.hpp>
Classes | |
struct | ModuleEntry |
Define a struct to hold the information about a module. More... |
Public Types | |
typedef std::string | tDescription |
Description datatype. | |
typedef std::less< tKey > | tPredicator |
Comparison predicator of key. | |
typedef boost::shared_ptr< tBase > | tBaseSharedPtr |
Shared pointer to an object of baseclass type. | |
typedef tBaseSharedPtr(* | CreatorFunction )(BOOST_PP_ENUM_PARAMS(MAX_PARAM, tParam)) |
CreatorFunction type which takes parameter and returns base class shared pointer. | |
typedef std::map< tKey, ModuleEntry, tPredicator > | TMapFactory |
Factory map between key and module data. | |
typedef TMapFactory::iterator | TMapFactoryIterator |
Iterator for factory map. |
Public Member Functions | |
NekFactory () | |
tBaseSharedPtr | CreateInstance (tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x)) |
Create an instance of the class referred to by idKey . | |
tKey | RegisterCreatorFunction (tKey idKey, CreatorFunction classCreator, tDescription pDesc="") |
Register a class with the factory. | |
bool | ModuleExists (tKey idKey) |
Checks if a particular module is available. | |
void | PrintAvailableClasses (std::ostream &pOut=std::cout) |
Prints the available classes to stdout. | |
tKey | GetKey (tDescription pDesc) |
Retrieves a key, given a description. | |
std::string | GetClassDescription (tKey idKey) |
Returns the description of a class. |
Protected Member Functions | |
TMapFactory * | getMapFactory () |
Ensure the factory's map is created. |
Private Member Functions | |
NekFactory (const NekFactory &rhs) | |
NekFactory & | operator= (const NekFactory &rhs) |
Private Attributes | |
TMapFactory | mMapFactory |
Provides a generic Factory class.
Implements a generic object factory. Class-types which use a potentially arbitrary number of parameters may be used with specialised forms of the NekFactory. An upper limit on the number of parameters is imposed by the MAX_PARAM preprocessor definition in the NekFactory.hpp file. The specialisations are generated at compile type using Boost preprocessor by through repeated inclusion of the NekFactory.hpp file.
To allow a class to be instantiated by the factory, the following are required in each class definition (in the case of a single parameter):
and outside the class definition in the implementation:
The assignment of the static variable className is done through the call to RegisterCreatorFunction, which registers the class with the factory prior to the start of the main() routine.
To create an instance of a derived class, for instance:
Definition at line 112 of file NekFactory.hpp.
typedef tBaseSharedPtr(* Nektar::LibUtilities::NekFactory< tKey, tBase, >::CreatorFunction)(BOOST_PP_ENUM_PARAMS(MAX_PARAM, tParam)) |
CreatorFunction type which takes parameter and returns base class shared pointer.
Definition at line 123 of file NekFactory.hpp.
typedef boost::shared_ptr<tBase> Nektar::LibUtilities::NekFactory< tKey, tBase, >::tBaseSharedPtr |
Shared pointer to an object of baseclass type.
Definition at line 120 of file NekFactory.hpp.
typedef std::string Nektar::LibUtilities::NekFactory< tKey, tBase, >::tDescription |
Description datatype.
Definition at line 116 of file NekFactory.hpp.
typedef std::map<tKey, ModuleEntry, tPredicator> Nektar::LibUtilities::NekFactory< tKey, tBase, >::TMapFactory |
Factory map between key and module data.
Definition at line 141 of file NekFactory.hpp.
typedef TMapFactory::iterator Nektar::LibUtilities::NekFactory< tKey, tBase, >::TMapFactoryIterator |
Iterator for factory map.
Definition at line 143 of file NekFactory.hpp.
typedef std::less<tKey> Nektar::LibUtilities::NekFactory< tKey, tBase, >::tPredicator |
Comparison predicator of key.
Definition at line 118 of file NekFactory.hpp.
|
inline |
Definition at line 147 of file NekFactory.hpp.
|
private |
|
inline |
Create an instance of the class referred to by idKey
.
Searches the factory's map for the given key and returns a shared base class pointer to a new instance of the associated class.
idKey | Key of class to create. |
x | Parameter to pass to class constructor. |
Definition at line 158 of file NekFactory.hpp.
References ASSERTL0, Nektar::LibUtilities::NekFactory< tKey, tBase, >::getMapFactory(), MAX_PARAM, and Nektar::LibUtilities::NekFactory< tKey, tBase, >::PrintAvailableClasses().
Referenced by Nektar::SolverUtils::Advection3DHomogeneous1D::Advection3DHomogeneous1D(), Nektar::LibUtilities::SessionReader::CreateComm(), Nektar::AdjointAdvection::DFT(), Nektar::LinearisedAdvection::DFT(), Nektar::SolverUtils::Diffusion3DHomogeneous1D::Diffusion3DHomogeneous1D(), Nektar::MultiRegions::GlobalLinSysIterative::DoConjugateGradient(), Nektar::VortexWaveInteraction::ExecuteRoll(), Nektar::VortexWaveInteraction::ExecuteStreak(), Nektar::VortexWaveInteraction::ExecuteWave(), Nektar::MultiRegions::ExpListHomogeneous1D::ExpListHomogeneous1D(), Nektar::MultiRegions::ExpListHomogeneous2D::ExpListHomogeneous2D(), Nektar::Utilities::InputTec::GenElement2D(), Nektar::Utilities::InputTec::GenElement3D(), Nektar::MultiRegions::ExpList::GenGlobalBndLinSys(), Nektar::MultiRegions::ExpList::GenGlobalLinSys(), Nektar::LibUtilities::Import(), main(), Nektar::LibUtilities::SessionReader::PartitionMesh(), Nektar::Utilities::InputFld::Process(), Nektar::Utilities::OutputInfo::Process(), Nektar::Utilities::Module::ReorderPrisms(), Nektar::PulseWavePropagation::SetPulseWaveBoundaryConditions(), Nektar::Stimulus::Stimulus(), Nektar::MultiRegions::GlobalLinSysIterativeStaticCond::v_AssembleSchurComplement(), Nektar::LinearSWE::v_InitObject(), Nektar::NonlinearSWE::v_InitObject(), Nektar::Bidomain::v_InitObject(), Nektar::Monodomain::v_InitObject(), Nektar::MultiRegions::PreconditionerLinearWithBlock::v_InitObject(), Nektar::PulseWavePropagation::v_InitObject(), Nektar::MultiRegions::PreconditionerLinearWithLowEnergy::v_InitObject(), Nektar::MultiRegions::PreconditionerLinearWithDiag::v_InitObject(), Nektar::APE::v_InitObject(), Nektar::UnsteadyInviscidBurger::v_InitObject(), Nektar::SolverUtils::Driver::v_InitObject(), Nektar::UnsteadyAdvection::v_InitObject(), Nektar::IncNavierStokes::v_InitObject(), Nektar::CompressibleFlowSystem::v_InitObject(), Nektar::MultiRegions::GlobalLinSysIterativeStaticCond::v_InitObject(), Nektar::SubSteppingExtrapolate::v_SubSteppingTimeIntegration(), Nektar::VortexWaveInteraction::VortexWaveInteraction(), and Nektar::LibUtilities::Write().
|
inline |
Returns the description of a class.
Definition at line 281 of file NekFactory.hpp.
References ASSERTL0, and Nektar::LibUtilities::NekFactory< tKey, tBase, >::getMapFactory().
|
inline |
Retrieves a key, given a description.
Definition at line 261 of file NekFactory.hpp.
References ASSERTL0, and Nektar::LibUtilities::NekFactory< tKey, tBase, >::getMapFactory().
|
inlineprotected |
Ensure the factory's map is created.
Definition at line 297 of file NekFactory.hpp.
References Nektar::LibUtilities::NekFactory< tKey, tBase, >::mMapFactory.
Referenced by Nektar::LibUtilities::NekFactory< tKey, tBase, >::CreateInstance(), Nektar::LibUtilities::NekFactory< tKey, tBase, >::GetClassDescription(), Nektar::LibUtilities::NekFactory< tKey, tBase, >::GetKey(), Nektar::LibUtilities::NekFactory< tKey, tBase, >::ModuleExists(), Nektar::LibUtilities::NekFactory< tKey, tBase, >::PrintAvailableClasses(), and Nektar::LibUtilities::NekFactory< tKey, tBase, >::RegisterCreatorFunction().
|
inline |
Checks if a particular module is available.
Definition at line 217 of file NekFactory.hpp.
References Nektar::LibUtilities::NekFactory< tKey, tBase, >::getMapFactory().
Referenced by main(), and Nektar::LibUtilities::SessionReader::PartitionMesh().
|
private |
|
inline |
Prints the available classes to stdout.
Definition at line 233 of file NekFactory.hpp.
References Nektar::LibUtilities::NekFactory< tKey, tBase, >::getMapFactory().
Referenced by Nektar::LibUtilities::NekFactory< tKey, tBase, >::CreateInstance(), and main().
|
inline |
Register a class with the factory.
This function is called by each class in a static context (prior to the execution of main()) and creates an entry for the class in the factory's map.
idKey | Key used to reference the class. |
classCreator | Function to call to create an instance of this class. |
pDesc | Optional description of class. |
idKey
. Definition at line 205 of file NekFactory.hpp.
References Nektar::LibUtilities::NekFactory< tKey, tBase, >::getMapFactory().
|
private |
Definition at line 306 of file NekFactory.hpp.
Referenced by Nektar::LibUtilities::NekFactory< tKey, tBase, >::getMapFactory().