G4OCCT 0.1.0
Geant4 interface to Open CASCADE Technology (OCCT) geometry definitions
Loading...
Searching...
No Matches
G4OCCTAssemblyRegistry.cc
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2// Copyright (C) 2026 G4OCCT Contributors
3
6
8
10
11#include <stdexcept>
12
17
18G4OCCTAssemblyRegistry::~G4OCCTAssemblyRegistry() {
19 for (auto& [name, assembly] : fAssemblies) {
20 delete assembly;
21 }
22}
23
24void G4OCCTAssemblyRegistry::Register(const std::string& name, G4OCCTAssemblyVolume* assembly) {
25 if (!assembly) {
26 throw std::invalid_argument("G4OCCTAssemblyRegistry: null assembly passed for '" + name + "'.");
27 }
28 if (fAssemblies.count(name) != 0) {
29 throw std::runtime_error("G4OCCTAssemblyRegistry: assembly '" + name +
30 "' is already registered.");
31 }
32 fAssemblies[name] = assembly;
33}
34
35G4OCCTAssemblyVolume* G4OCCTAssemblyRegistry::Get(const std::string& name) const {
36 const auto it = fAssemblies.find(name);
37 return it != fAssemblies.end() ? it->second : nullptr;
38}
39
41 const auto it = fAssemblies.find(name);
42 if (it == fAssemblies.end()) {
43 return nullptr;
44 }
45 G4OCCTAssemblyVolume* assembly = it->second;
46 fAssemblies.erase(it);
47 return assembly;
48}
49
50std::size_t G4OCCTAssemblyRegistry::Size() const { return fAssemblies.size(); }
Declaration of G4OCCTAssemblyRegistry.
Declaration of G4OCCTAssemblyVolume.
Singleton registry for named G4OCCTAssemblyVolume instances.
G4OCCTAssemblyVolume * Get(const std::string &name) const
static G4OCCTAssemblyRegistry & Instance()
Return the singleton instance.
G4OCCTAssemblyVolume * Release(const std::string &name)
void Register(const std::string &name, G4OCCTAssemblyVolume *assembly)
Extends Geant4's G4AssemblyVolume with an OCCT XDE label reference.