DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
PlacementNameRegistry.hh
Go to the documentation of this file.
1#pragma once
2//
3// Created by Douglas S. Leonard on 6/17/25. All rights Reserved
4// See related files for license, if any is provided.
5//
6
7#ifndef PLACEMENTNAMEREGISTRY_HH
8#define PLACEMENTNAMEREGISTRY_HH
9#include <mutex>
10#include <string>
11#include <unordered_map>
12
13namespace DLG4::VolumeBuilders {
14 class PlacementNameRegistry {
15 static std::unordered_map<std::string, int> name_counts_;
16 static std::mutex registry_mutex_;
17
18 public
19 :
20 static int IncrementNameCount(const std::string &base_name) {
21 std::lock_guard<std::mutex> lock(registry_mutex_);
22 auto retval = ++name_counts_[base_name];
23 return retval;
24 }
25
26 static int GetNameCount(const std::string &base_name) {
27 std::lock_guard<std::mutex> lock(registry_mutex_);
28 auto it = name_counts_.find(base_name);
29 return (it != name_counts_.end()) ? it->second : 0;
30 }
31 };
32}
33
34#endif //PLACEMENTNAMEREGISTRY_HH