19#ifndef BDSACCELERATORCOMPONENTREGISTRY_H
20#define BDSACCELERATORCOMPONENTREGISTRY_H
29#include <unordered_map>
49 ACRegistryKey(
const std::string& componentNameIn, G4double rigidityIn);
53 friend std::ostream& operator<<(std::ostream &out,
ACRegistryKey const &k);
57 static G4double tolerance;
69 std::size_t h2 = std::hash<double>()(k.rigidity);
70 std::size_t ht = h1 ^ (h2 + 0x9e3779b9 + (h1<<6) + (h1>>2));
99 typedef std::unordered_map<ACRegistryKey, BDSAcceleratorComponent*>
RegistryMap;
123 G4double rigidtyAtConstructionTime,
124 bool isModified =
false);
130 G4bool
IsRegistered(
const G4String& componentName, G4double rigidtyAtConstructionTime);
152 G4int AlreadyRegisteredNameCount(
const G4String& name)
const;
192 std::set<BDSAcceleratorComponent*> tunnelComponents;
custom key class for pair of <name,rigidity>.
std::string componentName
Has to be std::string for hashing as G4String doesn't provide one.
A registry of constructed BDSAcceleratorComponent instances that can be searched.
void RegisterCurvilinearComponent(BDSAcceleratorComponent *component)
static BDSAcceleratorComponentRegistry * Instance()
Singleton accessor.
void RegisterTunnelComponent(BDSAcceleratorComponent *component)
const_iterator end() const
std::set< BDSAcceleratorComponent * > allocatedComponents
Set of created components not in registry, for memory management.
std::set< BDSAcceleratorComponent * > curvilinearComponents
Set of curvilinear components - purely for memory management.
friend std::ostream & operator<<(std::ostream &out, BDSAcceleratorComponentRegistry const &r)
Output stream.
static BDSAcceleratorComponentRegistry * instance
The singleton instance.
std::unordered_map< ACRegistryKey, BDSAcceleratorComponent * > RegistryMap
G4bool IsRegisteredAllocated(const BDSAcceleratorComponent *componentName) const
Check if a unique component is registered in the allocatedComponents.
std::unordered_map< ACRegistryKey, BDSAcceleratorComponent * > AllComponentsIncludingUnique() const
void PrintNumberOfEachType() const
Print out the number of each type of component registered.
const_iterator begin() const
std::unordered_map< std::string, int > typeCounter
size_t size() const
Size of registry.
BDSAcceleratorComponent * GetComponent(const G4String &name, G4double rigidtyAtConstructionTime)
void RegisterComponent(BDSAcceleratorComponent *component, G4double rigidtyAtConstructionTime, bool isModified=false)
RegistryMap::const_iterator const_iterator
G4bool IsRegistered(BDSAcceleratorComponent *component, G4double rigidtyAtConstructionTime)
Check whether an accelerator component is already registered.
BDSAcceleratorComponentRegistry()
Default constructor is private as singleton.
RegistryMap::iterator iterator
~BDSAcceleratorComponentRegistry()
std::unordered_map< std::string, int > nameCounter
BDSAcceleratorComponentRegistry & operator=(const BDSAcceleratorComponentRegistry &)
assignment and copy constructor not implemented nor used
RegistryMap registry
Registry is a map - note 'register' is a protected keyword.
RegistryMap registryForAllocated
A map for absolutely everything including components that are unique.
Abstract class that represents a component of an accelerator.
std::size_t operator()(const ACRegistryKey &k) const