Faro Engine 0.0.0.b519570 (main)
Loading...
Searching...
No Matches
Map.hpp
Go to the documentation of this file.
1#pragma once
2#include <map>
3#include "Array.hpp"
4
5namespace Faro
6{
7 template<class KeyType, class ValueType>
8 class Map
9 {
10 public:
11 void Add(KeyType k, ValueType v)
12 {
13 data.insert(std::pair<KeyType, ValueType>(k, v));
14 }
15
16 void Remove(KeyType k)
17 {
18 auto it = data.find(k);
19 if (it != data.end()) data.erase(k);
20 }
21
22 bool Contains(KeyType k) const
23 {
24 return data.find(k) != data.end();
25 }
26
27 void Clear()
28 {
29 data.clear();
30 }
31
33 {
34 Array<KeyType> keys;
35
36 for (auto it = data.begin(); it != data.end(); ++it)
37 {
38 keys.Add(it->first);
39 }
40
41 return keys;
42 }
43
45 {
46 Array<ValueType> values;
47
48 for (auto it = data.begin(); it != data.end(); ++it)
49 {
50 values.Add(it->second);
51 }
52
53 return values;
54 }
55
56 uint32 Size() const
57 {
58 return data.size();
59 }
60
61 ValueType& operator [](KeyType k)
62 {
63 return data[k];
64 }
65
66 typedef typename std::map<KeyType, ValueType>::iterator Iterator;
67 typedef typename std::map<KeyType, ValueType>::const_iterator CIterator;
68
69 Iterator begin() { return data.begin(); }
70 CIterator cbegin() const { return data.cbegin(); }
71 Iterator end() noexcept { return data.end(); }
72 CIterator cend() const { return data.cend(); }
73
74 private:
75 std::map<KeyType, ValueType> data;
76 };
77}
Definition Array.hpp:11
void Add(const T &object)
Definition Array.hpp:26
Definition Map.hpp:9
void Add(KeyType k, ValueType v)
Definition Map.hpp:11
void Clear()
Definition Map.hpp:27
CIterator cend() const
Definition Map.hpp:72
std::map< KeyType, ValueType >::const_iterator CIterator
Definition Map.hpp:67
ValueType & operator[](KeyType k)
Definition Map.hpp:61
Array< ValueType > GetValues() const
Definition Map.hpp:44
Iterator end() noexcept
Definition Map.hpp:71
Iterator begin()
Definition Map.hpp:69
void Remove(KeyType k)
Definition Map.hpp:16
uint32 Size() const
Definition Map.hpp:56
std::map< KeyType, ValueType >::iterator Iterator
Definition Map.hpp:66
Array< KeyType > GetKeys() const
Definition Map.hpp:32
bool Contains(KeyType k) const
Definition Map.hpp:22
CIterator cbegin() const
Definition Map.hpp:70
Definition Array.hpp:8
uint32_t uint32
Definition Primitives.hpp:12