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::less< tKey > | tPredicator |
Comparison predicator of key. More... | |
typedef std::shared_ptr< tBase > | tBaseSharedPtr |
Shared pointer to an object of baseclass type. More... | |
typedef std::function< tBaseSharedPtr(tParam...)> | CreatorFunction |
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... | |
Public Member Functions | |
NekFactory ()=default | |
tBaseSharedPtr | CreateInstance (tKey idKey, tParam... args) |
Create an instance of the class referred to by idKey . More... | |
tKey | RegisterCreatorFunction (tKey idKey, CreatorFunction classCreator, std::string 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... | |
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)=delete | |
NekFactory & | operator= (const NekFactory &rhs)=delete |
Private Attributes | |
TMapFactory | mMapFactory |
Provides a generic Factory class.
Implements a generic object factory. Class-types which use an arbitrary number of parameters may be used via C++ variadic templating.
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 103 of file BasicUtils/NekFactory.hpp.
typedef std::function<tBaseSharedPtr(tParam...)> Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::CreatorFunction |
CreatorFunction type which takes parameter and returns base class shared pointer.
Definition at line 112 of file BasicUtils/NekFactory.hpp.
typedef std::shared_ptr<tBase> Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::tBaseSharedPtr |
Shared pointer to an object of baseclass type.
Definition at line 109 of file BasicUtils/NekFactory.hpp.
typedef std::map<tKey, ModuleEntry, tPredicator> Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::TMapFactory |
Factory map between key and module data.
Definition at line 129 of file BasicUtils/NekFactory.hpp.
typedef std::less<tKey> Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::tPredicator |
Comparison predicator of key.
Definition at line 107 of file BasicUtils/NekFactory.hpp.
|
default |
|
privatedelete |
|
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. |
args | Parameter to pass to class constructor. |
Definition at line 143 of file BasicUtils/NekFactory.hpp.
References Nektar::ErrorUtil::efatal, Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::getMapFactory(), Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::ModuleEntry::m_func, NEKERROR, and Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::PrintAvailableClasses().
Referenced by Nektar::SolverUtils::Advection3DHomogeneous1D::Advection3DHomogeneous1D(), Nektar::ArtificialDiffusion::ArtificialDiffusion(), Nektar::Collections::BwdTrans_MatrixFree::BwdTrans_MatrixFree(), Nektar::CompressibleSolver::CompressibleSolver(), Nektar::LibUtilities::SessionReader::CreateComm(), Nektar::LibUtilities::FieldIO::CreateDefault(), Nektar::LibUtilities::FieldIO::CreateForFile(), Nektar::Thread::ThreadMaster::CreateInstance(), Nektar::SolverUtils::FilterFieldConvert::CreateModules(), Nektar::MultiRegions::GlobalLinSys::CreatePrecon(), Nektar::LinearisedAdvection::DFT(), Nektar::SolverUtils::FileFieldInterpolator::DFT(), Nektar::SolverUtils::Diffusion3DHomogeneous1D::Diffusion3DHomogeneous1D(), EquationSystem_Create(), Nektar::VortexWaveInteraction::ExecuteRoll(), Nektar::VortexWaveInteraction::ExecuteStreak(), Nektar::MultiRegions::ExpListHomogeneous1D::ExpListHomogeneous1D(), Nektar::MultiRegions::ExpListHomogeneous2D::ExpListHomogeneous2D(), Nektar::MultiRegions::ExpList::ExtractCoeffsFromFile(), Field_Init(), Nektar::FieldUtils::Field::FieldIOForFile(), Filter_Create(), Nektar::SolverUtils::FilterPython::FilterPython(), Nektar::MultiRegions::ExpList::GenGlobalBndLinSys(), Nektar::MultiRegions::ExpList::GenGlobalLinSys(), Nektar::Collections::Helmholtz_MatrixFree::Helmholtz_MatrixFree(), Nektar::LibUtilities::Import(), Nektar::CompressibleFlowSystem::InitAdvection(), Nektar::Collections::Collection::Initialise(), Nektar::ForcingMovingBody::InitialiseCableModel(), Nektar::CFSImplicit::InitialiseNonlinSysSolver(), Nektar::ShallowWaterSystem::InitialiseNonlinSysSolver(), Nektar::IncBoundaryConditions::Initialize(), Nektar::NavierStokesCFE::InitObject_Explicit(), Nektar::Collections::IProductWRTBase_MatrixFree::IProductWRTBase_MatrixFree(), Nektar::Collections::IProductWRTDerivBase_MatrixFree::IProductWRTDerivBase_MatrixFree(), Nektar::Collections::LinearAdvectionDiffusionReaction_MatrixFree::LinearAdvectionDiffusionReaction_MatrixFree(), Nektar::GlobalMapping::Mapping::Load(), main(), MeshGraphIO_Create(), Module_Create(), Nektar::LibUtilities::NekNonlinSysIter::NekNonlinSysIter(), Nektar::Collections::PhysDeriv_MatrixFree::PhysDeriv_MatrixFree(), Nektar::Collections::PhysInterp1DScaled_MatrixFree::PhysInterp1DScaled_MatrixFree(), Nektar::SpatialDomains::MeshGraphIO::Read(), Nektar::SpatialDomains::MeshPartition::ReadExpansions(), Nektar::UpwindPulseSolver::RiemannSolverUpwind(), SessionReader_CreateInstance(), Nektar::SolverUtils::DriverParallelInTime::SetParallelInTimeEquationSystem(), Nektar::PulseWavePropagation::SetPulseWaveBoundaryConditions(), Nektar::VelocityCorrectionScheme::SetUpExtrapolation(), Nektar::UnsteadyAdvectionDiffusion::SetUpSubSteppingTimeIntegration(), Nektar::Stimulus::Stimulus(), Diffusion::TimeIntegrate(), Nektar::MultiRegions::PreconditionerLinearWithBlock::v_InitObject(), Nektar::MultiRegions::PreconditionerLinearWithDiag::v_InitObject(), Nektar::MultiRegions::PreconditionerLinearWithLowEnergy::v_InitObject(), Nektar::PulseWavePropagation::v_InitObject(), Nektar::PulseWaveSystem::v_InitObject(), Nektar::SolverUtils::UnsteadySystem::v_InitObject(), Nektar::Bidomain::v_InitObject(), Nektar::BidomainRoth::v_InitObject(), Nektar::Monodomain::v_InitObject(), Nektar::ImageWarpingSystem::v_InitObject(), Nektar::CoupledLinearNS::v_InitObject(), Nektar::IncNavierStokes::v_InitObject(), Nektar::VCSMapping::v_InitObject(), Nektar::APE::v_InitObject(), Nektar::LEE::v_InitObject(), Nektar::EigenValuesAdvection::v_InitObject(), Nektar::MMFAdvection::v_InitObject(), Nektar::UnsteadyAdvection::v_InitObject(), Nektar::UnsteadyAdvectionDiffusion::v_InitObject(), Nektar::UnsteadyDiffusion::v_InitObject(), Nektar::UnsteadyInviscidBurgers::v_InitObject(), Nektar::UnsteadyViscousBurgers::v_InitObject(), Nektar::CompressibleFlowSystem::v_InitObject(), Nektar::LinearSWE::v_InitObject(), Nektar::NonlinearSWE::v_InitObject(), Nektar::DiffusionLDGNS::v_InitObject(), Nektar::SolverUtils::Driver::v_InitObject(), Nektar::FieldUtils::OutputFld::v_OutputFromData(), Nektar::FieldUtils::OutputFld::v_OutputFromExp(), Nektar::SpatialDomains::MeshGraphIOHDF5::v_PartitionMesh(), Nektar::SpatialDomains::MeshGraphIOXml::v_PartitionMesh(), Nektar::FieldUtils::OutputXml::v_Process(), Nektar::FieldUtils::ProcessPointDataToFld::v_Process(), Nektar::MultiRegions::GlobalLinSysIterativeFull::v_SolveLinearSystem(), Nektar::MultiRegions::GlobalLinSysIterativeStaticCond::v_SolveLinearSystem(), Nektar::SubSteppingExtrapolate::v_SubSteppingTimeIntegration(), Nektar::VariableConverter::VariableConverter(), Nektar::VortexWaveInteraction::VortexWaveInteraction(), Nektar::LibUtilities::Write(), Nektar::FieldUtils::OutputFileBase::WriteFile(), and Nektar::IterativeElasticSystem::WriteGeometry().
|
inline |
Returns the description of a class.
Definition at line 256 of file BasicUtils/NekFactory.hpp.
References ASSERTL0, and Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::getMapFactory().
|
inlineprotected |
Ensure the factory's map is created.
Definition at line 276 of file BasicUtils/NekFactory.hpp.
References Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::mMapFactory.
Referenced by Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::CreateInstance(), Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::GetClassDescription(), Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::ModuleExists(), Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::PrintAvailableClasses(), and Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::RegisterCreatorFunction().
|
inline |
Checks if a particular module is available.
Definition at line 212 of file BasicUtils/NekFactory.hpp.
References Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::getMapFactory().
Referenced by Nektar::SpatialDomains::MeshGraphIOXml::v_PartitionMesh().
|
privatedelete |
|
inline |
Prints the available classes to stdout.
Definition at line 231 of file BasicUtils/NekFactory.hpp.
References Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::getMapFactory().
Referenced by Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::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 197 of file BasicUtils/NekFactory.hpp.
References Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::getMapFactory().
Referenced by Module_Register().
|
private |
Definition at line 285 of file BasicUtils/NekFactory.hpp.
Referenced by Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::getMapFactory().