| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Map.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_MAP_H
2 #define GAUDIKERNEL_MAP_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // STD & STL
7 // ============================================================================
8 #include <map>
9 // ============================================================================
10 // GaudiKernel
11 // ============================================================================
12 #include "GaudiKernel/MapBase.h"
13 // ============================================================================
14 namespace GaudiUtils
15 {
16 // ==========================================================================
81 template <typename K, typename T, typename M = std::map<K, T>>
82 class Map : public Gaudi::Utils::MapBase
83 {
84 public:
85 // ========================================================================
86 // ---- types
87 typedef M map_type;
88 typedef K key_type;
89 typedef T mapped_type;
90
91 // -- from unary_function
92 typedef K argument_type;
93 typedef T result_type;
94 typedef std::pair<const K, T> value_type;
95 typedef const value_type& const_reference;
96
97 typedef typename map_type::size_type size_type;
98
99 typedef typename map_type::iterator iterator;
100 typedef typename map_type::const_iterator const_iterator;
101 // typedef typename map_type::reverse_iterator reverse_iterator;
102 // typedef typename map_type::const_reverse_iterator const_reverse_iterator;
103 // ========================================================================
104 protected:
105 // ========================================================================
106 map_type m_map;
107 static const result_type s_null_value;
108 // ========================================================================
109 public:
110 // ---- Constructors
111
113 Map() = default;
114
116 Map( const map_type& other ) : m_map( other ) {}
117
118 // /// Copy Constructor
119 // Map(const Map& other): m_map(other.m_map) {}
121 template <typename In>
122 Map( In&& first, In&& last ) : m_map( std::forward<In>( first ), std::forward<In>( last ) )
123 {
124 }
125
127 virtual ~Map() = default;
128
129 // ---- std::map interface
130
131 // -- iterators
132
133 inline iterator begin() { return m_map.begin(); }
134 inline iterator end() { return m_map.end(); }
135
136 inline const_iterator begin() const { return m_map.begin(); }
137 inline const_iterator end() const { return m_map.end(); }
138
139 // inline reverse_iterator rbegin() { return m_map.rbegin(); }
140 // inline reverse_iterator rend() { return m_map.rend(); }
141
142 // inline const_reverse_iterator rbegin() const { return m_map.rbegin(); }
143 // inline const_reverse_iterator rend() const { return m_map.rend(); }
144
145 // -- subscription
146
147 inline mapped_type& operator[]( const key_type& key ) { return m_map[key]; }
148
149 // -- map operations
150
151 inline iterator find( const key_type& key ) { return m_map.find( key ); }
152 inline const_iterator find( const key_type& key ) const { return m_map.find( key ); }
153
154 inline size_type count( const key_type& key ) const { return m_map.count( key ); }
155
156 inline iterator lower_bound( const key_type& key ) { return m_map.lower_bound( key ); }
157 inline const_iterator lower_bound( const key_type& key ) const { return m_map.lower_bound( key ); }
158 inline iterator upper_bound( const key_type& key ) { return m_map.upper_bound( key ); }
159 inline const_iterator upper_bound( const key_type& key ) const { return m_map.upper_bound( key ); }
160
161 inline std::pair<iterator, iterator> equal_range( const key_type& key ) { return m_map.equal_range( key ); }
162 inline std::pair<const_iterator, const_iterator> equal_range( const key_type& key ) const
163 {
164 return m_map.equal_range( key );
165 }
166
167 // -- list operations
168 template <class... Args>
169 std::pair<iterator, bool> emplace( Args&&... args )
170 {
171 return m_map.emplace( std::forward<Args>( args )... );
172 }
173 template <typename ValueType>
174 inline std::pair<iterator, bool> insert( ValueType&& val )
175 {
176 return m_map.insert( std::forward<ValueType>( val ) );
177 }
178 inline std::pair<iterator, bool> insert( value_type&& val )
179 {
180 return m_map.insert( std::forward<value_type>( val ) );
181 }
182 template <typename In>
183 inline void insert( In&& first, In&& last )
184 {
185 m_map.insert( std::forward<In>( first ), std::forward<In>( last ) );
186 }
187 template <typename ValueType>
188 inline iterator insert( iterator /* pos */, ValueType&& val )
189 {
190 return m_map.insert( /* pos, */ std::forward<ValueType>( val ) ).first;
191 }
192 inline iterator erase( const_iterator pos ) { return m_map.erase( pos ); }
193 inline size_type erase( const key_type& key ) { return m_map.erase( key ); }
194 inline iterator erase( const_iterator first, const_iterator last ) { return m_map.erase( first, last ); }
195 inline void clear() { m_map.clear(); }
196
197 // -- container operations
198
199 inline size_type size() const { return m_map.size(); }
200 inline size_type max_size() const { return m_map.max_size(); }
201 inline bool empty() const { return size() == 0; }
202 inline void swap( map_type& other ) { m_map.swap( other ); }
203
204 // ---- extra functionalities
205
228 inline const result_type& operator()( const argument_type& key ) const
229 {
230 // static const result_type s_null_value;
231 auto it = m_map.find( key );
233 return it != m_map.end() ? it->second : s_null_value;
234 }
235 // ========================================================================
258 inline const mapped_type& operator[]( const key_type& key ) const { return ( *this )( key ); }
259 // ========================================================================
265 inline const result_type& at( const argument_type& key ) const { return m_map.at( key ); }
266 // ========================================================================
268 inline Map& merge( const map_type& other )
269 {
270 m_map.insert( std::begin( other ), std::end( other ) );
271 return *this;
272 }
274 inline Map& merge( const Map& other )
275 {
276 m_map.insert( std::begin( other ), std::end( other ) );
277 return *this;
278 }
280 template <class K1, class K2, class K3>
281 inline Map& merge( const Map<K1, K2, K3>& other )
282 {
283 m_map.insert( std::begin( other ), std::end( other ) );
284 return *this;
285 }
286 // update the key
287 void update( const key_type& key, const mapped_type& mapped ) { ( *this )[key] = mapped; }
288 // ========================================================================
289 public:
290 // ========================================================================
292 inline operator map_type&() { return m_map; }
293 inline operator const map_type&() const { return m_map; }
294 // ========================================================================
295 public:
296 // ========================================================================
302 const key_type& key_at( const size_type index ) const
303 {
304 if ( index >= size() ) {
305 this->throw_out_of_range_exception();
306 }
307 return std::next( this->begin(), index )->first;
308 }
314 const mapped_type& value_at( const size_type index ) const
315 {
316 if ( index >= size() ) {
317 this->throw_out_of_range_exception();
318 }
319 return std::next( this->begin(), index )->second;
320 }
321 // ========================================================================
322 };
323 // ==========================================================================
324 template <typename K, typename T, typename M>
325 const typename Map<K, T, M>::result_type Map<K, T, M>::s_null_value = typename Map<K, T, M>::result_type();
326 // ==========================================================================
327 } // end of GaudiUtils namespace
328 // ============================================================================
329
330 // ============================================================================
331 // The END
332 // ============================================================================
333 #endif // GAUDIKERNEL_MAP_H
GaudiUtils::Map::insert
std::pair< iterator, bool > insert(value_type &&val)
Definition: Map.h:178
GaudiUtils::Map
Extension of the STL map.
Definition: Map.h:82
GaudiUtils::Map::argument_type
K argument_type
Definition: Map.h:92
GaudiUtils::Map::size
size_type size() const
Definition: Map.h:199
GaudiUtils::Map::end
const_iterator end() const
Definition: Map.h:137
gaudirun.args
args
Definition: gaudirun.py:244
GaudiUtils::Map::key_type
K key_type
Definition: Map.h:88
GaudiUtils::Map::s_null_value
static const result_type s_null_value
Definition: Map.h:107
std::unordered_map::swap
T swap(T...args)
GaudiUtils::Map::count
size_type count(const key_type &key) const
Definition: Map.h:154
GaudiUtils::Map::Map
Map(In &&first, In &&last)
Construct from a subset.
Definition: Map.h:122
std
STL namespace.
GaudiUtils::Map::at
const result_type & at(const argument_type &key) const
checked access to the map for missing keys
Definition: Map.h:265
GaudiUtils::Map::size_type
map_type::size_type size_type
Definition: Map.h:97
std::unordered_map::end
T end(T...args)
GaudiUtils::Map::erase
size_type erase(const key_type &key)
Definition: Map.h:193
GaudiUtils::Map::m_map
map_type m_map
Definition: Map.h:106
GaudiUtils::Map::insert
iterator insert(iterator, ValueType &&val)
Definition: Map.h:188
GaudiUtils::Map::update
void update(const key_type &key, const mapped_type &mapped)
Definition: Map.h:287
GaudiUtils::Map::find
const_iterator find(const key_type &key) const
Definition: Map.h:152
std::unordered_map::at
T at(T...args)
GaudiUtils::Map::insert
std::pair< iterator, bool > insert(ValueType &&val)
Definition: Map.h:174
GaudiUtils::Map::lower_bound
const_iterator lower_bound(const key_type &key) const
Definition: Map.h:157
GaudiUtils::Map::operator[]
mapped_type & operator[](const key_type &key)
Definition: Map.h:147
GaudiUtils::Map::end
iterator end()
Definition: Map.h:134
GaudiUtils::Map::map_type
M map_type
Definition: Map.h:87
GaudiUtils::Map::erase
iterator erase(const_iterator first, const_iterator last)
Definition: Map.h:194
GaudiUtils::Map::upper_bound
iterator upper_bound(const key_type &key)
Definition: Map.h:158
GaudiUtils::Map::operator()
const result_type & operator()(const argument_type &key) const
Allow to use Map as an unary function.
Definition: Map.h:228
std::next
T next(T...args)
GaudiUtils::Map::empty
bool empty() const
Definition: Map.h:201
GaudiUtils::Map::lower_bound
iterator lower_bound(const key_type &key)
Definition: Map.h:156
MapBase.h
std::unordered_map::erase
T erase(T...args)
GaudiUtils::Map::find
iterator find(const key_type &key)
Definition: Map.h:151
GaudiUtils::Map::value_at
const mapped_type & value_at(const size_type index) const
useful method for python decoration:
Definition: Map.h:314
GaudiUtils::Map::emplace
std::pair< iterator, bool > emplace(Args &&...args)
Definition: Map.h:169
GaudiUtils::Map::~Map
virtual ~Map()=default
Virtual destructor. You can inherit from this map type.
std::unordered_map::clear
T clear(T...args)
GaudiUtils::Map::const_iterator
map_type::const_iterator const_iterator
Definition: Map.h:100
std::unordered_map::count
T count(T...args)
GaudiUtils::Map::begin
iterator begin()
Definition: Map.h:133
std::pair
GaudiUtils::Map::merge
Map & merge(const Map &other)
Merge two maps.
Definition: Map.h:274
GaudiUtils::Map::insert
void insert(In &&first, In &&last)
Definition: Map.h:183
std::unordered_map::insert
T insert(T...args)
GaudiUtils::Map::mapped_type
T mapped_type
Definition: Map.h:89
std::unordered_map::find
T find(T...args)
std::unordered_map::size
T size(T...args)
GaudiUtils::Map::iterator
map_type::iterator iterator
Definition: Map.h:99
GaudiUtils::Map::erase
iterator erase(const_iterator pos)
Definition: Map.h:192
GaudiUtils::Map::swap
void swap(map_type &other)
Definition: Map.h:202
GaudiUtils::Map::key_at
const key_type & key_at(const size_type index) const
useful method for python decoration:
Definition: Map.h:302
std::unordered_map::begin
T begin(T...args)
GaudiUtils::Map::begin
const_iterator begin() const
Definition: Map.h:136
GaudiUtils::Map::Map
Map(const map_type &other)
Constructor from a standard map.
Definition: Map.h:116
GaudiUtils::Map::value_type
std::pair< const K, T > value_type
Definition: Map.h:94
GaudiUtils::Map::equal_range
std::pair< const_iterator, const_iterator > equal_range(const key_type &key) const
Definition: Map.h:162
GaudiUtils::Map::upper_bound
const_iterator upper_bound(const key_type &key) const
Definition: Map.h:159
GaudiUtils::Map::merge
Map & merge(const Map< K1, K2, K3 > &other)
Merge two maps.
Definition: Map.h:281
std::unordered_map::max_size
T max_size(T...args)
GaudiUtils
Forward declarations for the functions in SerializeSTL.h.
Definition: GaudiHistoID.h:140
std::unordered_map::emplace
T emplace(T...args)
GaudiUtils::Map::clear
void clear()
Definition: Map.h:195
Gaudi::Utils::MapBase::throw_out_of_range_exception
void throw_out_of_range_exception() const
throw std::out_of_range exception
Definition: MapBase.cpp:28
GaudiUtils::Map::operator[]
const mapped_type & operator[](const key_type &key) const
Access elements of a const Map.
Definition: Map.h:258
Gaudi::Utils::MapBase
Helper base-class to allow the generic Python-decoration for all "map-like" classes in Gaudi...
Definition: MapBase.h:44
GaudiUtils::Map::merge
Map & merge(const map_type &other)
Merge two maps.
Definition: Map.h:268
GaudiUtils::Map::const_reference
const value_type & const_reference
Definition: Map.h:95
GaudiUtils::Map::max_size
size_type max_size() const
Definition: Map.h:200
GaudiUtils::Map::result_type
T result_type
Definition: Map.h:93
GaudiUtils::Map::Map
Map()=default
Standard constructor.
std::unordered_map::equal_range
T equal_range(T...args)
GaudiUtils::Map::equal_range
std::pair< iterator, iterator > equal_range(const key_type &key)
Definition: Map.h:161