BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSComponentFactoryUser.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "BDSComponentConstructor.hh"
19#include "BDSComponentFactoryUser.hh"
20
21#include "G4Types.hh"
22
23#include <map>
24
25BDSComponentFactoryUser::BDSComponentFactoryUser()
26{;}
27
28BDSComponentFactoryUser::~BDSComponentFactoryUser()
29{
30 for (auto& constructor : userFunctions)
31 {delete constructor.second;}
32}
33
34void BDSComponentFactoryUser::RegisterComponent(const G4String& componentTypeName,
35 BDSComponentConstructor* componentConstructor)
36{
37 userFunctions[componentTypeName] = componentConstructor;
38}
39
40G4bool BDSComponentFactoryUser::CanConstructComponentByName(const G4String& componentTypeName) const
41{
42 return userFunctions.find(componentTypeName) != userFunctions.end();
43}
44
46 GMAD::Element const* elementIn,
47 GMAD::Element const* prevElementIn,
48 GMAD::Element const* nextElementIn,
49 const BDSBeamlineIntegral& integral)
50{
51 return userFunctions[componentTypeName]->Construct(elementIn,
52 prevElementIn,
53 nextElementIn,
54 integral);
55}
Abstract class that represents a component of an accelerator.
A class that holds the current integrated quantities along a beam line.
Interface class the developer should derive to construct their element.
G4bool CanConstructComponentByName(const G4String &componentTypeName) const
Check whether a component can be constructed - ie if the name exists.
void RegisterComponent(const G4String &componentTypeName, BDSComponentConstructor *componentConstructor)
Register a constructor instance by a given name.
std::map< G4String, BDSComponentConstructor * > userFunctions
Map of user component name with constructors to build a component.
BDSAcceleratorComponent * ConstructComponent(const G4String &componentTypeName, GMAD::Element const *elementIn, GMAD::Element const *prevElementIn, GMAD::Element const *nextElementIn, const BDSBeamlineIntegral &integral)
Element class.
Definition element.h:47