File indexing completed on 2026-09-26 09:15:35
0001
0002
0003
0004 #ifndef VECGEOM_BASE_TYPEMAP_H_
0005 #define VECGEOM_BASE_TYPEMAP_H_
0006
0007 #include "VecGeom/base/Global.h"
0008 #include "VecGeom/base/Assert.h"
0009
0010 #include <map>
0011
0012 namespace vecgeom {
0013 inline namespace VECGEOM_IMPL_NAMESPACE {
0014
0015
0016
0017
0018
0019
0020
0021 template <typename TypeA, typename TypeB>
0022 class BidirectionalTypeMap {
0023
0024 private:
0025 std::map<TypeA, TypeB> a_to_b;
0026 std::map<TypeB, TypeA> b_to_a;
0027
0028 public:
0029 BidirectionalTypeMap() : a_to_b(), b_to_a() {}
0030 BidirectionalTypeMap(BidirectionalTypeMap const &other);
0031 BidirectionalTypeMap &operator=(BidirectionalTypeMap const &other);
0032
0033
0034
0035
0036
0037
0038
0039 TypeB const &operator[](TypeA const &a) const
0040 {
0041 const typename std::map<TypeA, TypeB>::const_iterator i = a_to_b.find(a);
0042
0043 VECGEOM_ASSERT(i != a_to_b.end());
0044 return i->second;
0045 }
0046
0047
0048
0049
0050
0051
0052
0053 TypeA const &operator[](TypeB const &b) const
0054 {
0055 const typename std::map<TypeB, TypeA>::const_iterator i = b_to_a.find(b);
0056
0057 VECGEOM_ASSERT(i != b_to_a.end());
0058 return i->second;
0059 }
0060
0061
0062
0063
0064
0065 void Set(TypeA const &a, TypeB const &b)
0066 {
0067 a_to_b[a] = b;
0068 b_to_a[b] = a;
0069 }
0070
0071
0072
0073
0074
0075 void Set(TypeB const &b, TypeA const &a)
0076 {
0077 a_to_b[a] = b;
0078 b_to_a[b] = a;
0079 }
0080
0081
0082
0083
0084
0085
0086 typename std::map<TypeA, TypeB>::const_iterator begin() const { return a_to_b.begin(); }
0087
0088
0089
0090
0091
0092
0093 typename std::map<TypeA, TypeB>::const_iterator end() const { return a_to_b.end(); }
0094
0095
0096
0097
0098
0099 bool Contains(TypeA const &a) const { return a_to_b.find(a) != a_to_b.end(); }
0100
0101
0102
0103
0104
0105 bool Contains(TypeB const &b) const { return b_to_a.find(b) != b_to_a.end(); }
0106
0107
0108
0109
0110 void Clear()
0111 {
0112 b_to_a.clear();
0113 a_to_b.clear();
0114 }
0115 };
0116 }
0117 }
0118
0119 #endif