src/G4OCCTAssemblyRegistry.cc
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: LGPL-2.1-or-later | ||
| 2 | // Copyright (C) 2026 G4OCCT Contributors | ||
| 3 | |||
| 4 | /// @file G4OCCTAssemblyRegistry.cc | ||
| 5 | /// @brief Implementation of G4OCCTAssemblyRegistry. | ||
| 6 | |||
| 7 | #include "G4OCCT/G4OCCTAssemblyRegistry.hh" | ||
| 8 | |||
| 9 | #include "G4OCCT/G4OCCTAssemblyVolume.hh" | ||
| 10 | |||
| 11 | #include <stdexcept> | ||
| 12 | |||
| 13 | 19 | G4OCCTAssemblyRegistry& G4OCCTAssemblyRegistry::Instance() { | |
| 14 |
3/4✓ Branch 0 taken 6 times.
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
19 | static G4OCCTAssemblyRegistry instance; |
| 15 | 19 | return instance; | |
| 16 | } | ||
| 17 | |||
| 18 | 6 | G4OCCTAssemblyRegistry::~G4OCCTAssemblyRegistry() { | |
| 19 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | for (auto& [name, assembly] : fAssemblies) { |
| 20 | ✗ | delete assembly; | |
| 21 | } | ||
| 22 | 6 | } | |
| 23 | |||
| 24 | 6 | void G4OCCTAssemblyRegistry::Register(const std::string& name, G4OCCTAssemblyVolume* assembly) { | |
| 25 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (!assembly) { |
| 26 |
0/8✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
1 | throw std::invalid_argument("G4OCCTAssemblyRegistry: null assembly passed for '" + name + "'."); |
| 27 | } | ||
| 28 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 time.
|
6 | if (fAssemblies.count(name) != 0) { |
| 29 |
4/8✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 7 not taken.
|
1 | throw std::runtime_error("G4OCCTAssemblyRegistry: assembly '" + name + |
| 30 | "' is already registered."); | ||
| 31 | } | ||
| 32 | 5 | fAssemblies[name] = assembly; | |
| 33 | 6 | } | |
| 34 | |||
| 35 | 3 | G4OCCTAssemblyVolume* G4OCCTAssemblyRegistry::Get(const std::string& name) const { | |
| 36 | 3 | const auto it = fAssemblies.find(name); | |
| 37 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 2 times.
|
3 | return it != fAssemblies.end() ? it->second : nullptr; |
| 38 | } | ||
| 39 | |||
| 40 | 6 | G4OCCTAssemblyVolume* G4OCCTAssemblyRegistry::Release(const std::string& name) { | |
| 41 | 6 | const auto it = fAssemblies.find(name); | |
| 42 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 5 times.
|
6 | if (it == fAssemblies.end()) { |
| 43 | 1 | return nullptr; | |
| 44 | } | ||
| 45 | 5 | G4OCCTAssemblyVolume* assembly = it->second; | |
| 46 | 5 | fAssemblies.erase(it); | |
| 47 | 5 | return assembly; | |
| 48 | 6 | } | |
| 49 | |||
| 50 | 4 | std::size_t G4OCCTAssemblyRegistry::Size() const { return fAssemblies.size(); } | |
| 51 |