File indexing completed on 2025-08-02 08:28:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #ifndef G4AccMap_h
0032 #define G4AccMap_h 1
0033
0034 #include "G4VAccumulable.hh"
0035 #include "G4MergeMode.hh"
0036
0037 #include "globals.hh"
0038
0039 #include <map>
0040
0041 template <class Key,
0042 class T,
0043 class Compare = std::less<Key>,
0044 class Allocator = std::allocator<std::pair<const Key, T>>>
0045 class G4AccMap : public G4VAccumulable
0046 {
0047 public:
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 G4AccMap(const G4String& name = "",
0098 G4MergeMode mergeMode = G4MergeMode::kAddition);
0099
0100
0101
0102 G4AccMap(const Compare& comp,
0103 G4MergeMode mergeMode = G4MergeMode::kAddition,
0104 const Allocator& alloc = Allocator());
0105
0106
0107
0108 G4AccMap(const G4String& name,
0109 const Compare& comp,
0110 G4MergeMode mergeMode = G4MergeMode::kAddition,
0111 const Allocator& alloc = Allocator());
0112
0113
0114
0115 G4AccMap(const Allocator& alloc,
0116 G4MergeMode mergeMode = G4MergeMode::kAddition);
0117
0118
0119
0120 G4AccMap(const G4String& name,
0121 const Allocator& alloc,
0122 G4MergeMode mergeMode = G4MergeMode::kAddition);
0123
0124
0125
0126 G4AccMap(std::initializer_list<std::pair<const Key,T>> init,
0127 G4MergeMode mergeMode = G4MergeMode::kAddition,
0128 const Compare& comp = Compare(),
0129 const Allocator& alloc = Allocator());
0130
0131
0132
0133 G4AccMap(const G4String& name,
0134 std::initializer_list<std::pair<const Key,T>> init,
0135 G4MergeMode mergeMode = G4MergeMode::kAddition,
0136 const Compare& comp = Compare(),
0137 const Allocator& alloc = Allocator());
0138
0139
0140 G4AccMap(const G4AccMap& rhs) = default;
0141 G4AccMap(const G4AccMap& rhs, const Allocator& allocator);
0142
0143 G4AccMap(G4AccMap&& rhs) = default;
0144 G4AccMap(G4AccMap&& rhs, const Allocator& allocator);
0145
0146
0147 ~G4AccMap() override = default;
0148
0149
0150
0151 inline T& operator[](const Key& key) { return fMap[key]; }
0152 inline T& operator[](Key&& key) { return fMap[std::move(key)]; }
0153
0154 inline T& at(const Key& key) { return fMap[key]; }
0155 inline const T& at(const Key& key ) const { return fMap[key]; }
0156
0157 inline typename std::map<Key, T, Compare, Allocator>::size_type size() const { return fMap.size(); }
0158
0159 inline typename std::map<Key, T, Compare, Allocator>::iterator begin() { return fMap.begin(); }
0160 inline typename std::map<Key, T, Compare, Allocator>::const_iterator begin() const { return fMap.begin(); }
0161 inline typename std::map<Key, T, Compare, Allocator>::const_iterator cbegin() const { return fMap.cbegin(); }
0162
0163 inline typename std::map<Key, T, Compare, Allocator>::iterator end() { return fMap.end(); }
0164 inline typename std::map<Key, T, Compare, Allocator>::const_iterator end() const { return fMap.end(); }
0165 inline typename std::map<Key, T, Compare, Allocator>::const_iterator cend() const { return fMap.cend(); }
0166
0167 inline void clear() { fMap.clear(); }
0168
0169 inline std::pair<typename std::map<Key, T, Compare, Allocator>::iterator, bool> insert(const T& value) { return fMap.insert(value); }
0170 template< class P >
0171 inline std::pair<typename std::map<Key, T, Compare, Allocator>::iterator, bool> insert( P&& value ) { return fMap.insert(std::move(value)); }
0172 inline std::pair<typename std::map<Key, T, Compare, Allocator>::iterator, bool> insert( T&& value ) { return fMap.insert(std::move(value)); }
0173
0174 inline typename std::map<Key, T, Compare, Allocator>::iterator find( const Key& key ) { return fMap.find(key); }
0175 inline typename std::map<Key, T, Compare, Allocator>::const_iterator find( const Key& key ) const { return fMap.find(key); }
0176
0177
0178 void Merge(const G4VAccumulable& other) final;
0179 void Reset() final;
0180 void Print(G4PrintOptions options = G4PrintOptions()) const final;
0181 void SetMergeMode(G4MergeMode value) final;
0182 void SetInitValue(const T& value);
0183
0184
0185 G4AccType GetType() const final { return G4AccType::kMap; }
0186 std::map<Key, T, Compare, Allocator>& GetMap() { return fMap; }
0187 const std::map<Key, T, Compare, Allocator>& GetMap() const { return fMap; }
0188
0189 private:
0190
0191 std::map<Key, T, Compare, Allocator> fMap {};
0192 T fInitValue = 0;
0193 G4MergeFunction<T> fMergeFunction;
0194 };
0195
0196
0197
0198 #include "G4AccMap.icc"
0199
0200 #endif