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. More... | |
typedef std::less< tKey > | tPredicator |
Comparison predicator of key. More... | |
typedef boost::shared_ptr< tBase > | tBaseSharedPtr |
Shared pointer to an object of baseclass type. More... | |
typedef tBaseSharedPtr(* | CreatorFunction )(BOOST_PP_ENUM_PARAMS(MAX_PARAM, tParam)) |
CreatorFunction type which takes parameter and returns base class shared pointer. More... | |
typedef std::map< tKey, ModuleEntry, tPredicator > | TMapFactory |
Factory map between key and module data. More... | |
typedef TMapFactory::iterator | TMapFactoryIterator |
Iterator for factory map. More... | |
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 . More... | |
tKey | RegisterCreatorFunction (tKey idKey, CreatorFunction classCreator, tDescription pDesc="") |
Register a class with the factory. More... | |
bool | ModuleExists (tKey idKey) |
Checks if a particular module is available. More... | |
void | PrintAvailableClasses (std::ostream &pOut=std::cout) |
Prints the available classes to stdout. More... | |
tKey | GetKey (tDescription pDesc) |
Retrieves a key, given a description. More... | |
std::string | GetClassDescription (tKey idKey) |
Returns the description of a class. More... | |
Protected Member Functions | |
TMapFactory * | getMapFactory () |
Ensure the factory's map is created. More... | |
Private Member Functions | |
NekFactory (const NekFactory &rhs) | |
NekFactory & | operator= (const NekFactory &rhs) |
Private Attributes | |
TMapFactory | mMapFactory |
boost::shared_mutex | m_mutex |
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 116 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 127 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 124 of file NekFactory.hpp.
typedef std::string Nektar::LibUtilities::NekFactory< tKey, tBase, >::tDescription |
Description datatype.
Definition at line 120 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 145 of file NekFactory.hpp.
typedef TMapFactory::iterator Nektar::LibUtilities::NekFactory< tKey, tBase, >::TMapFactoryIterator |
Iterator for factory map.
Definition at line 147 of file NekFactory.hpp.
typedef std::less<tKey> Nektar::LibUtilities::NekFactory< tKey, tBase, >::tPredicator |
Comparison predicator of key.
Definition at line 122 of file NekFactory.hpp.
|
inline |
Definition at line 151 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 162 of file NekFactory.hpp.
References ASSERTL0, Nektar::LibUtilities::NekFactory< tKey, tBase, >::getMapFactory(), Nektar::LibUtilities::NekFactory< tKey, tBase, >::ModuleEntry::m_func, Nektar::LibUtilities::NekFactory< tKey, tBase, >::m_mutex, MAX_PARAM, and Nektar::LibUtilities::NekFactory< tKey, tBase, >::PrintAvailableClasses().
Referenced by Nektar::SolverUtils::Advection3DHomogeneous1D::Advection3DHomogeneous1D(), Nektar::NekMeshUtils::FaceMesh::BuildLocalMesh(), Nektar::LibUtilities::SessionReader::CreateComm(), Nektar::Thread::ThreadMaster::CreateInstance(), Nektar::MultiRegions::GlobalLinSys::CreatePrecon(), Nektar::LinearisedAdvection::DFT(), Nektar::AdjointAdvection::DFT(), Nektar::NekMeshUtils::FaceMesh::DiagonalSwap(), Nektar::SolverUtils::Diffusion3DHomogeneous1D::Diffusion3DHomogeneous1D(), Nektar::VortexWaveInteraction::ExecuteRoll(), Nektar::VortexWaveInteraction::ExecuteStreak(), Nektar::VortexWaveInteraction::ExecuteWave(), Nektar::MultiRegions::ExpListHomogeneous1D::ExpListHomogeneous1D(), Nektar::MultiRegions::ExpListHomogeneous2D::ExpListHomogeneous2D(), Nektar::Utilities::InputTec::GenElement2D(), Nektar::Utilities::InputStar::GenElement2D(), Nektar::Utilities::InputTec::GenElement3D(), Nektar::Utilities::InputStar::GenElement3D(), Nektar::MultiRegions::ExpList::GenGlobalBndLinSys(), Nektar::MultiRegions::ExpList::GenGlobalLinSys(), Nektar::NekMeshUtils::Octree::GetOctreeMesh(), Nektar::LibUtilities::Import(), Nektar::ForcingMovingBody::InitialiseCableModel(), Nektar::Utilities::InputSem::insertEdge(), Nektar::GlobalMapping::Mapping::Load(), main(), Nektar::NekMeshUtils::BLMesh::Mesh(), Nektar::NekMeshUtils::TetMesh::Mesh(), Nektar::LibUtilities::SessionReader::PartitionMesh(), Nektar::Utilities::InputCAD::Process(), Nektar::Utilities::InputSem::Process(), Nektar::Utilities::InputFld::Process(), Nektar::Utilities::InputGmsh::Process(), Nektar::Utilities::InputNekpp::Process(), Nektar::Utilities::InputPts::Process(), Nektar::Utilities::OutputInfo::Process(), Nektar::Utilities::ProcessOptiExtract::Process(), Nektar::Utilities::InputSwan::Process(), Nektar::Utilities::InputVtk::Process(), Nektar::Utilities::ProcessSpherigon::Process(), Nektar::Utilities::InputNek::Process(), Nektar::Utilities::ProcessExtractSurf::Process(), Nektar::Utilities::ProcessExtractTetPrismInterface::Process(), Nektar::Utilities::ProcessBL::Process(), Nektar::Utilities::ProcessTetSplit::Process(), Nektar::Utilities::ProcessDetectSurf::Process(), Nektar::Utilities::InputPly::ReadPly(), Nektar::Utilities::Module::ReorderPrisms(), Nektar::PulseWavePropagation::SetPulseWaveBoundaryConditions(), Nektar::UnsteadyAdvectionDiffusion::SetUpSubSteppingTimeIntegration(), Nektar::Stimulus::Stimulus(), Nektar::VelocityCorrectionScheme::v_InitObject(), Nektar::VCSMapping::v_InitObject(), Nektar::LinearSWE::v_InitObject(), Nektar::NonlinearSWE::v_InitObject(), Nektar::BidomainRoth::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::NonlinearPeregrine::v_InitObject(), Nektar::UnsteadyInviscidBurger::v_InitObject(), Nektar::UnsteadyAdvection::v_InitObject(), Nektar::SolverUtils::Driver::v_InitObject(), Nektar::IncNavierStokes::v_InitObject(), Nektar::CompressibleFlowSystem::v_InitObject(), Nektar::CoupledLinearNS::v_InitObject(), Nektar::SubSteppingExtrapolate::v_SubSteppingTimeIntegration(), Nektar::VortexWaveInteraction::VortexWaveInteraction(), and Nektar::LibUtilities::Write().
|
inline |
Returns the description of a class.
Definition at line 299 of file NekFactory.hpp.
References ASSERTL0, Nektar::LibUtilities::NekFactory< tKey, tBase, >::getMapFactory(), and Nektar::LibUtilities::NekFactory< tKey, tBase, >::m_mutex.
|
inline |
Retrieves a key, given a description.
Definition at line 277 of file NekFactory.hpp.
References ASSERTL0, Nektar::LibUtilities::NekFactory< tKey, tBase, >::getMapFactory(), and Nektar::LibUtilities::NekFactory< tKey, tBase, >::m_mutex.
|
inlineprotected |
Ensure the factory's map is created.
Definition at line 317 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 229 of file NekFactory.hpp.
References Nektar::LibUtilities::NekFactory< tKey, tBase, >::getMapFactory(), and Nektar::LibUtilities::NekFactory< tKey, tBase, >::m_mutex.
Referenced by main().
|
private |
|
inline |
Prints the available classes to stdout.
Definition at line 247 of file NekFactory.hpp.
References Nektar::LibUtilities::NekFactory< tKey, tBase, >::getMapFactory(), and Nektar::LibUtilities::NekFactory< tKey, tBase, >::m_mutex.
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 215 of file NekFactory.hpp.
References Nektar::LibUtilities::NekFactory< tKey, tBase, >::getMapFactory(), and Nektar::LibUtilities::NekFactory< tKey, tBase, >::m_mutex.
|
private |
Definition at line 328 of file NekFactory.hpp.
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().
|
private |
Definition at line 326 of file NekFactory.hpp.
Referenced by Nektar::LibUtilities::NekFactory< tKey, tBase, >::getMapFactory().