File indexing completed on 2026-01-10 10:05:49
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <memory>
0010 #include <string>
0011 #include <unordered_map>
0012 #include <vector>
0013
0014 #include "corecel/data/AuxStateVec.hh"
0015
0016 #include "GeneratorInterface.hh"
0017
0018 namespace celeritas
0019 {
0020
0021
0022
0023
0024
0025
0026 class GeneratorRegistry
0027 {
0028 public:
0029
0030
0031 using SPGenerator = std::shared_ptr<GeneratorInterface>;
0032 using SPConstGenerator = std::shared_ptr<GeneratorInterface const>;
0033
0034
0035 public:
0036
0037 GeneratorRegistry() = default;
0038
0039
0040
0041
0042 GeneratorId next_id() const { return GeneratorId(generators_.size()); }
0043
0044
0045 void insert(SPGenerator generator);
0046
0047
0048
0049
0050 GeneratorId::size_type size() const { return generators_.size(); }
0051
0052
0053 bool empty() const { return generators_.empty(); }
0054
0055
0056 inline SPGenerator const& at(GeneratorId);
0057 inline SPConstGenerator at(GeneratorId) const;
0058
0059
0060 inline std::string const& id_to_label(GeneratorId id) const;
0061
0062
0063 GeneratorId find(std::string const& label) const;
0064
0065
0066 void reset(AuxStateVec&) const;
0067
0068 private:
0069 std::vector<SPGenerator> generators_;
0070 std::vector<std::string> labels_;
0071 std::unordered_map<std::string, GeneratorId> gen_ids_;
0072 };
0073
0074
0075
0076
0077
0078
0079
0080 auto GeneratorRegistry::at(GeneratorId id) -> SPGenerator const&
0081 {
0082 CELER_EXPECT(id < this->size());
0083 return generators_[id.unchecked_get()];
0084 }
0085
0086
0087
0088
0089
0090 auto GeneratorRegistry::at(GeneratorId id) const -> SPConstGenerator
0091 {
0092 CELER_EXPECT(id < this->size());
0093 return generators_[id.unchecked_get()];
0094 }
0095
0096
0097
0098
0099
0100 std::string const& GeneratorRegistry::id_to_label(GeneratorId id) const
0101 {
0102 CELER_EXPECT(id < this->size());
0103 return labels_[id.unchecked_get()];
0104 }
0105
0106
0107 }