BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_OrderedMap.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California,
4 * through Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12#ifndef BELFEM_CL_ORDEREDMAP_HPP
13#define BELFEM_CL_ORDEREDMAP_HPP
14
15#include <map>
16
17
18#include "cl_Map.hpp"
19
20namespace belfem
21{
22//------------------------------------------------------------------------------
23
30 template< typename Key, typename Value >
32 {
33
34 std::map< Key, Value > mMap;
35
36//------------------------------------------------------------------------------
37 public:
38//------------------------------------------------------------------------------
39
40
41 using const_iterator = typename std::map< Key, Value >::const_iterator ;
42
46 explicit OrderedMap() = default;
47
48//------------------------------------------------------------------------------
49
53 OrderedMap( const OrderedMap< Key, Value > & aMap ) = default;
54
55//------------------------------------------------------------------------------
56
60 OrderedMap(OrderedMap<Key, Value>&& other) noexcept = default;
61
62//------------------------------------------------------------------------------
63
68
69//------------------------------------------------------------------------------
70
75
76//------------------------------------------------------------------------------
77
81 ~OrderedMap() = default;
82
83//------------------------------------------------------------------------------
84
88 void
90 {
91 mMap.clear();
92 }
93
94//------------------------------------------------------------------------------
95
99 size_t
100 size() const
101 {
102 return mMap.size();
103 }
104
105//------------------------------------------------------------------------------
106
110 Value &
111 operator[]( const Key & aKey )
112 {
113 return mMap[ aKey ];
114 }
115
116//------------------------------------------------------------------------------
117
118 bool
119 key_exists( const Key & aKey ) const
120 {
121 return mMap.find( aKey ) != mMap.end();
122 }
123
124//------------------------------------------------------------------------------
125
126 auto
127 begin() const -> decltype( mMap.begin() )
128 {
129 return mMap.begin();
130 }
131
132 auto
133 end() const -> decltype( mMap.end() )
134 {
135 return mMap.end();
136 }
137
138 auto
139 find ( const Key & tKey ) const -> decltype( mMap.find(tKey) )
140 {
141 return mMap.find( tKey );
142 }
143
144 auto
145 empty() const -> decltype( mMap.empty() )
146 {
147 return mMap.empty();
148 }
149
150//------------------------------------------------------------------------------
151
152 void
153 erase_key( const Key & aKey )
154 {
155 // remove key from map
156 mMap.erase( aKey );
157 }
158//------------------------------------------------------------------------------
159
160 // expose the data container
161 auto
162 map_data() -> decltype( mMap ) &
163 {
164 return mMap ;
165 }
166
167//------------------------------------------------------------------------------
168
172 Value &
173 operator()( const Key & aKey )
174 {
175 // check if key exists
176 auto tIterator = mMap.find( aKey );
177
178#if !defined( NDEBUG ) || defined( DEBUG )
179 BELFEM_ASSERT( tIterator != mMap.end(),
180 "Key %s not found in map.",
181 map::KeyToString( aKey ).c_str() );
182
183#else
184 BELFEM_ERROR( tIterator != mMap.end(),
185 "Key not found in map." );
186#endif
187
188 return tIterator->second;
189 }
190
191//------------------------------------------------------------------------------
192
196 const Value &
197 operator()( const Key & aKey ) const
198 {
199// check if key exists
200 auto tIterator = mMap.find( aKey );
201
202#if !defined( NDEBUG ) || defined( DEBUG )
203
204 BELFEM_ASSERT( tIterator != mMap.end(),
205 "Key %s not found in map.",
206 map::KeyToString( aKey ).c_str() );
207
208#else
209 BELFEM_ERROR( tIterator != mMap.end(),
210 "Key not found in map." );
211#endif
212
213 return tIterator->second;
214 }
215 };
216//------------------------------------------------------------------------------
217} /* namespace belfem */
218#endif //BELFEM_CL_ORDEREDMAP_HPP
#define BELFEM_ERROR(aCheck,...)
Definition assert.hpp:264
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Value & operator()(const Key &aKey)
find operator
Definition cl_OrderedMap.hpp:173
void clear()
clear map
Definition cl_OrderedMap.hpp:89
Value & operator[](const Key &aKey)
insert operator
Definition cl_OrderedMap.hpp:111
const Value & operator()(const Key &aKey) const
find operator ( const variant )
Definition cl_OrderedMap.hpp:197
OrderedMap(const OrderedMap< Key, Value > &aMap)=default
copy constructor
auto empty() const -> decltype(mMap.empty())
Definition cl_OrderedMap.hpp:145
auto find(const Key &tKey) const -> decltype(mMap.find(tKey))
Definition cl_OrderedMap.hpp:139
OrderedMap< Key, Value > & operator=(OrderedMap< Key, Value > &&other) noexcept=default
Move assignment operator constructor.
OrderedMap(OrderedMap< Key, Value > &&other) noexcept=default
move constructor
bool key_exists(const Key &aKey) const
Definition cl_OrderedMap.hpp:119
typename std::map< Key, Value >::const_iterator const_iterator
Definition cl_OrderedMap.hpp:41
auto end() const -> decltype(mMap.end())
Definition cl_OrderedMap.hpp:133
auto begin() const -> decltype(mMap.begin())
Definition cl_OrderedMap.hpp:127
void erase_key(const Key &aKey)
Definition cl_OrderedMap.hpp:153
auto map_data() -> decltype(mMap) &
Definition cl_OrderedMap.hpp:162
size_t size() const
returns the size of the map
Definition cl_OrderedMap.hpp:100
~OrderedMap()=default
default destructor
OrderedMap< Key, Value > & operator=(const OrderedMap< Key, Value > &other)=default
Copy assignment operator.
OrderedMap()=default
empty constructor
std::string KeyToString(const T &aKey)
Definition cl_Map.hpp:31
USER GUIDES:
Definition cl_Capacitor.cpp:16