LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
shims::map< Key, T, Compare, Allocator > Class Template Reference

#include "stdmap_shims.h"

Classes

struct  iter
 
struct  iterator_tuple
 
struct  maps_tuple
 

Public Types

using mapmap_t = std::map< const Key, T, Compare, Allocator >
 
using listmap_t = std::list< std::pair< const Key, T >, Allocator >
 
using size_type = typename mapmap_t::size_type
 
using iterator_tag = std::input_iterator_tag
 
using iterator = iter< iterator_tag, std::pair< Key const, T >>
 
using const_iterator = iter< iterator_tag, std::pair< Key const, T > const >
 

Public Member Functions

T & operator[] (Key const &key)
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
const_iterator cbegin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
T & at (Key const &key)
 
T const & at (Key const &key) const
 
iterator find (Key const &key)
 
const_iterator find (Key const &key) const
 
size_t erase (Key const &key)
 
bool empty () const noexcept
 
size_type size () const noexcept
 
iterator erase (iterator it)
 
iterator erase (const_iterator &it)
 
template<class... Args>
std::pair< iterator, bool > emplace (Args &&...args)
 

Public Attributes

maps_tuple _maps
 

Detailed Description

template<class Key, class T, class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
class shims::map< Key, T, Compare, Allocator >

Definition at line 21 of file stdmap_shims.h.

Member Typedef Documentation

template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
using shims::map< Key, T, Compare, Allocator >::const_iterator = iter<iterator_tag, std::pair<Key const, T> const>

Definition at line 140 of file stdmap_shims.h.

template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
using shims::map< Key, T, Compare, Allocator >::iterator = iter<iterator_tag, std::pair<Key const, T>>

Definition at line 139 of file stdmap_shims.h.

template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
using shims::map< Key, T, Compare, Allocator >::iterator_tag = std::input_iterator_tag

Definition at line 41 of file stdmap_shims.h.

template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
using shims::map< Key, T, Compare, Allocator >::listmap_t = std::list<std::pair<const Key, T>, Allocator>

Definition at line 24 of file stdmap_shims.h.

template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
using shims::map< Key, T, Compare, Allocator >::mapmap_t = std::map<const Key, T, Compare, Allocator>

Definition at line 23 of file stdmap_shims.h.

template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
using shims::map< Key, T, Compare, Allocator >::size_type = typename mapmap_t::size_type

Definition at line 39 of file stdmap_shims.h.

Member Function Documentation

template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
T& shims::map< Key, T, Compare, Allocator >::at ( Key const &  key)
inline

Definition at line 204 of file stdmap_shims.h.

References shims::map< Key, T, Compare, Allocator >::_maps, shims::isSnippetMode(), shims::map< Key, T, Compare, Allocator >::maps_tuple::listmap, and shims::map< Key, T, Compare, Allocator >::maps_tuple::mapmap.

205  {
206  if (isSnippetMode()) {
207  auto it =
208  std::find_if(_maps.listmap.begin(),
209  _maps.listmap.end(),
210  [&key](auto& element) { return element.first == key; });
211  if (it == _maps.listmap.end())
212  throw std::out_of_range("Key <" + key + "> not found.");
213  return it->second;
214  } else {
215  return _maps.mapmap.at(key);
216  }
217  }
maps_tuple _maps
Definition: stdmap_shims.h:330
bool isSnippetMode(bool m=false) noexcept
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
T const& shims::map< Key, T, Compare, Allocator >::at ( Key const &  key) const
inline

Definition at line 220 of file stdmap_shims.h.

References shims::map< Key, T, Compare, Allocator >::_maps, shims::isSnippetMode(), shims::map< Key, T, Compare, Allocator >::maps_tuple::listmap, and shims::map< Key, T, Compare, Allocator >::maps_tuple::mapmap.

221  {
222  if (isSnippetMode()) {
223  auto it = std::find_if(
224  _maps.listmap.cbegin(),
225  _maps.listmap.cend(),
226  [&key](auto const& element) { return element.first == key; });
227  if (it == _maps.listmap.cend())
228  throw std::out_of_range("Key <" + key + "> not found.");
229  return it->second;
230  } else {
231  return _maps.mapmap.at(key);
232  }
233  }
maps_tuple _maps
Definition: stdmap_shims.h:330
bool isSnippetMode(bool m=false) noexcept
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
iterator shims::map< Key, T, Compare, Allocator >::begin ( )
inlinenoexcept
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
const_iterator shims::map< Key, T, Compare, Allocator >::begin ( ) const
inlinenoexcept

Definition at line 169 of file stdmap_shims.h.

References shims::map< Key, T, Compare, Allocator >::_maps, util::begin(), and shims::isSnippetMode().

170  {
171  auto& maps = const_cast<maps_tuple&>(_maps);
172  return isSnippetMode() ? const_iterator{std::begin(maps.listmap)} :
173  const_iterator{std::begin(maps.mapmap)};
174  }
maps_tuple _maps
Definition: stdmap_shims.h:330
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
bool isSnippetMode(bool m=false) noexcept
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
const_iterator shims::map< Key, T, Compare, Allocator >::cbegin ( ) const
inlinenoexcept

Definition at line 177 of file stdmap_shims.h.

References shims::map< Key, T, Compare, Allocator >::begin().

178  {
179  return begin();
180  }
iterator begin() noexcept
Definition: stdmap_shims.h:162
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
const_iterator shims::map< Key, T, Compare, Allocator >::cend ( ) const
inlinenoexcept

Definition at line 198 of file stdmap_shims.h.

References shims::map< Key, T, Compare, Allocator >::end().

199  {
200  return end();
201  }
iterator end() noexcept
Definition: stdmap_shims.h:183
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
template<class... Args>
std::pair<iterator, bool> shims::map< Key, T, Compare, Allocator >::emplace ( Args &&...  args)
inline

Definition at line 319 of file stdmap_shims.h.

References shims::map< Key, T, Compare, Allocator >::_maps, shims::isSnippetMode(), shims::map< Key, T, Compare, Allocator >::maps_tuple::listmap, and shims::map< Key, T, Compare, Allocator >::maps_tuple::mapmap.

320  {
321  if (isSnippetMode()) {
322  _maps.listmap.emplace_back(std::forward<Args>(args)...);
323  return std::make_pair(iterator{std::prev(_maps.listmap.end())}, true);
324  } else {
325  auto result = _maps.mapmap.emplace(std::forward<Args>(args)...);
326  return std::make_pair(iterator{result.first}, result.second);
327  }
328  }
maps_tuple _maps
Definition: stdmap_shims.h:330
bool isSnippetMode(bool m=false) noexcept
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
bool shims::map< Key, T, Compare, Allocator >::empty ( ) const
inlinenoexcept
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
iterator shims::map< Key, T, Compare, Allocator >::end ( void  )
inlinenoexcept
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
const_iterator shims::map< Key, T, Compare, Allocator >::end ( void  ) const
inlinenoexcept

Definition at line 190 of file stdmap_shims.h.

References shims::map< Key, T, Compare, Allocator >::_maps, util::end(), and shims::isSnippetMode().

191  {
192  auto& maps = const_cast<maps_tuple&>(_maps);
193  return isSnippetMode() ? const_iterator{std::end(maps.listmap)} :
194  const_iterator{std::end(maps.mapmap)};
195  }
maps_tuple _maps
Definition: stdmap_shims.h:330
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
bool isSnippetMode(bool m=false) noexcept
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
size_t shims::map< Key, T, Compare, Allocator >::erase ( Key const &  key)
inline

Definition at line 264 of file stdmap_shims.h.

References shims::map< Key, T, Compare, Allocator >::_maps, e, shims::isSnippetMode(), shims::map< Key, T, Compare, Allocator >::maps_tuple::listmap, and shims::map< Key, T, Compare, Allocator >::maps_tuple::mapmap.

265  {
266  if (isSnippetMode()) {
267  auto erase_count = size_t{0};
268  auto i = _maps.listmap.begin();
269  auto e = _maps.listmap.end();
270 
271  while (i != e) {
272  if (key == i->first) {
273  i = _maps.listmap.erase(i);
274  ++erase_count;
275  } else {
276  i++;
277  }
278  }
279 
280  return erase_count;
281  } else {
282  return _maps.mapmap.erase(key);
283  }
284  }
maps_tuple _maps
Definition: stdmap_shims.h:330
bool isSnippetMode(bool m=false) noexcept
Float_t e
Definition: plot.C:35
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
iterator shims::map< Key, T, Compare, Allocator >::erase ( iterator  it)
inline

Definition at line 299 of file stdmap_shims.h.

References shims::map< Key, T, Compare, Allocator >::_maps, shims::map< Key, T, Compare, Allocator >::iter< Category, TT, Distance, Pointer, Reference >::get(), shims::isSnippetMode(), shims::map< Key, T, Compare, Allocator >::maps_tuple::listmap, and shims::map< Key, T, Compare, Allocator >::maps_tuple::mapmap.

300  {
301  if (isSnippetMode()) {
302  return _maps.listmap.erase(it.get(typename listmap_t::iterator{}));
303  }
304  return _maps.mapmap.erase(it.get(typename mapmap_t::iterator{}));
305  }
intermediate_table::iterator iterator
maps_tuple _maps
Definition: stdmap_shims.h:330
std::enable_if_t< std::is_same_v< typename mapmap_t::iterator, II >, II > get(II)
Definition: stdmap_shims.h:107
bool isSnippetMode(bool m=false) noexcept
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
iterator shims::map< Key, T, Compare, Allocator >::erase ( const_iterator it)
inline

Definition at line 308 of file stdmap_shims.h.

References shims::map< Key, T, Compare, Allocator >::_maps, shims::map< Key, T, Compare, Allocator >::iter< Category, TT, Distance, Pointer, Reference >::get(), shims::isSnippetMode(), shims::map< Key, T, Compare, Allocator >::maps_tuple::listmap, and shims::map< Key, T, Compare, Allocator >::maps_tuple::mapmap.

309  {
310  if (isSnippetMode()) {
311  return _maps.listmap.erase(it.get(typename listmap_t::iterator{}));
312  } else {
313  return _maps.mapmap.erase(it.get(typename mapmap_t::iterator{}));
314  }
315  }
intermediate_table::iterator iterator
maps_tuple _maps
Definition: stdmap_shims.h:330
std::enable_if_t< std::is_same_v< typename mapmap_t::iterator, II >, II > get(II)
Definition: stdmap_shims.h:107
bool isSnippetMode(bool m=false) noexcept
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
iterator shims::map< Key, T, Compare, Allocator >::find ( Key const &  key)
inline

Definition at line 236 of file stdmap_shims.h.

References shims::map< Key, T, Compare, Allocator >::_maps, shims::isSnippetMode(), shims::map< Key, T, Compare, Allocator >::maps_tuple::listmap, and shims::map< Key, T, Compare, Allocator >::maps_tuple::mapmap.

Referenced by fhicl::intermediate_table::erase(), fhicl::intermediate_table::exists(), and fhicl::intermediate_table::find().

237  {
238  if (isSnippetMode()) {
239  return std::find_if(
240  _maps.listmap.begin(), _maps.listmap.end(), [&key](auto& element) {
241  return element.first == key;
242  });
243  } else {
244  return _maps.mapmap.find(key);
245  }
246  }
maps_tuple _maps
Definition: stdmap_shims.h:330
bool isSnippetMode(bool m=false) noexcept
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
const_iterator shims::map< Key, T, Compare, Allocator >::find ( Key const &  key) const
inline

Definition at line 249 of file stdmap_shims.h.

References shims::map< Key, T, Compare, Allocator >::_maps, shims::isSnippetMode(), shims::map< Key, T, Compare, Allocator >::maps_tuple::listmap, and shims::map< Key, T, Compare, Allocator >::maps_tuple::mapmap.

250  {
251  maps_tuple& maps = *const_cast<maps_tuple*>(&_maps);
252 
253  if (isSnippetMode()) {
254  return std::find_if(
255  maps.listmap.begin(),
256  maps.listmap.end(),
257  [&key](auto const& element) { return element.first == key; });
258  } else {
259  return maps.mapmap.find(key);
260  }
261  }
maps_tuple _maps
Definition: stdmap_shims.h:330
bool isSnippetMode(bool m=false) noexcept
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
T& shims::map< Key, T, Compare, Allocator >::operator[] ( Key const &  key)
inline

Definition at line 148 of file stdmap_shims.h.

References shims::map< Key, T, Compare, Allocator >::_maps, shims::isSnippetMode(), shims::map< Key, T, Compare, Allocator >::maps_tuple::listmap, shims::map< Key, T, Compare, Allocator >::maps_tuple::mapmap, and value.

149  {
150  if (isSnippetMode()) {
151  for (auto& [stored_key, value] : _maps.listmap) {
152  if (stored_key == key)
153  return value;
154  }
155  _maps.listmap.emplace_back(key, T{});
156  return _maps.listmap.back().second;
157  }
158  return _maps.mapmap[key];
159  }
maps_tuple _maps
Definition: stdmap_shims.h:330
double value
Definition: spectrum.C:18
bool isSnippetMode(bool m=false) noexcept
template<class Key , class T , class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T>>>
size_type shims::map< Key, T, Compare, Allocator >::size ( void  ) const
inlinenoexcept

Member Data Documentation


The documentation for this class was generated from the following file: