CEPS  24.01
Cardiac ElectroPhysiology Simulator
CepsMap.hpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
30 #pragma once
31 
32 #include <map>
33 #include <ostream>
34 
37 
39 namespace ceps
40 {
41 
43  template <typename _Key, typename _Tp, typename _Comp, typename _Alloc>
46  {
47  CepsVector<_Key> out = {};
48  out.reserve(m.size());
49  for (auto [key,obj] : m)
50  out.push_back(key);
51  return out;
52  }
53 
55  template <typename _Key, typename _Tp, typename _Comp, typename _Alloc>
58  {
59  CepsVector<_Tp> out = {};
60  out.reserve (m.size());
61  for (auto [key,obj] : m)
62  out.push_back(obj);
63  return out;
64  }
65 
67  template <typename _Key, typename _Tp, typename _Hash, typename _Eq, typename _Alloc>
70  {
71  CepsVector<_Key> out = {};
72  out.reserve(m.size());
73  for (auto [key,obj] : m)
74  out.push_back(key);
75  return out;
76  }
77 
79  template <typename _Key, typename _Tp, typename _Hash, typename _Eq, typename _Alloc>
82  {
83  CepsVector<_Tp> out = {};
84  out.reserve(m.size());
85  for (auto [key,obj] : m)
86  out.push_back(obj);
87  return out;
88  }
89 
91  template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
92  void
94  {
95  if (deleteAll)
96  for (auto [key, value] : map)
97  ceps::destroyObject (value);
98  return map.clear ();
99  }
100 
104  template<typename _Key, typename _Tp, typename _Key2>
106  getValues(const CepsMultiMap<_Key,_Tp>& m, const _Key2& key)
107  {
108  CepsVector<_Tp> out = {};
109  out.reserve(m.size());
110  auto range = m.equal_range(key);
111  for (auto it=range.first ; it!=range.second; ++it)
112  out.push_back(it->second);
113  return out;
114  }
115 
116 
117 } // namespace ceps
118 
120 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
121 std::ostream&
122 operator<<(std::ostream& os, const CepsMap<_Key,_Tp,_Compare,_Alloc>& m)
123 {
124 
125  os << "{";
126  for (auto [key,obj] : m)
127  os << "{" << key << ", " << obj << "} ";
128  os << "}" << std::flush;
129 
130  return os;
131 }
std::ostream & operator<<(std::ostream &os, const CepsMap< _Key, _Tp, _Compare, _Alloc > &m)
Displays the content of a map, if displayable.
Definition: CepsMap.hpp:122
std::map< _Key, _Tp, _Compare, _Alloc > CepsMap
C++ map.
Definition: CepsTypes.hpp:196
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
std::unordered_multimap< _Key, _Tp, _Hash, _KeyEqual, _Alloc > CepsMultiMap
C++ multimap.
Definition: CepsTypes.hpp:205
A namespace for all utility methods.
CepsVector< _Tp > getValues(const CepsMultiMap< _Key, _Tp > &m, const _Key2 &key)
extract values from multimap
Definition: CepsMap.hpp:106
void destroy(CepsMap< _Key, _Tp, _Compare, _Alloc > &map, CepsBool deleteAll=true)
Deletes all elements of the map properly, even if created with new.
Definition: CepsMap.hpp:93
CepsVector< _Tp > valuesOf(const CepsMap< _Key, _Tp, _Comp, _Alloc > &m)
Get the values of a map as a vector.
Definition: CepsMap.hpp:57
void destroyObject(_Type &)
Destroy[delete] any type.
Definition: CepsMemory.hpp:116
CepsVector< _Key > keysOf(const CepsMap< _Key, _Tp, _Comp, _Alloc > &m)
Get the keys of a map as a vector.
Definition: CepsMap.hpp:45