Unravel Engine C++ Reference
Loading...
Searching...
No Matches
bimap.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4
5namespace input
6{
7template<typename K, typename V>
8class bimap
9{
10 std::map<V, K> key_by_value_;
11 std::map<K, V> values_by_key_;
12
13public:
14 void clear()
15 {
16 key_by_value_.clear();
17 values_by_key_.clear();
18 }
19
20 auto get_key(const V value) const -> K
21 {
22 return key_by_value_.at(value);
23 }
24
25 auto get_key(const V value, const K defaultKey) const -> K
26 {
27 const auto& find = key_by_value_.find(value);
28 if(find == key_by_value_.end())
29 {
30 return defaultKey;
31 }
32
33 return find->second;
34 }
35
36 auto get_value(const K key) const -> V
37 {
38 return values_by_key_.at(key);
39 }
40
41 auto get_value(const K key, const V defaultValue) const -> V
42 {
43 const auto& find = values_by_key_.find(key);
44 if(find == values_by_key_.end())
45 {
46 return defaultValue;
47 }
48
49 return find->second;
50 }
51
52 void map(const K key, const V value)
53 {
54 key_by_value_.emplace(value, key);
55 values_by_key_.emplace(key, value);
56 }
57};
58} // namespace InputLib
auto get_value(const K key) const -> V
Definition bimap.hpp:36
auto get_key(const V value) const -> K
Definition bimap.hpp:20
auto get_key(const V value, const K defaultKey) const -> K
Definition bimap.hpp:25
void map(const K key, const V value)
Definition bimap.hpp:52
void clear()
Definition bimap.hpp:14
auto get_value(const K key, const V defaultValue) const -> V
Definition bimap.hpp:41