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