forked from kovacsv/VisualScriptEngineWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNE_SlotList.hpp
More file actions
120 lines (97 loc) · 2.84 KB
/
NE_SlotList.hpp
File metadata and controls
120 lines (97 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef NE_SLOTLIST_HPP
#define NE_SLOTLIST_HPP
#include "NE_Debug.hpp"
#include "NE_OrderedMap.hpp"
#include "NE_SlotId.hpp"
#include <vector>
#include <unordered_map>
#include <memory>
#include <functional>
#include <algorithm>
namespace NE
{
template <class SlotType>
class SlotList
{
public:
SlotList ();
bool Insert (const std::shared_ptr<SlotType>& slot);
bool InsertBefore (const std::shared_ptr<SlotType>& slot, const SlotId& nextSlotId);
bool InsertAfter (const std::shared_ptr<SlotType>& slot, const SlotId& prevSlotId);
std::shared_ptr<SlotType> Get (const SlotId& slotId);
std::shared_ptr<const SlotType> Get (const SlotId& slotId) const;
bool Contains (const SlotId& slotId) const;
size_t Count () const;
bool IsEmpty () const;
void Enumerate (const std::function<bool (std::shared_ptr<SlotType>&)>& processor);
void Enumerate (const std::function<bool (const std::shared_ptr<const SlotType>&)>& processor) const;
private:
OrderedMap<SlotId, std::shared_ptr<SlotType>> slots;
};
template <class SlotType>
SlotList<SlotType>::SlotList () :
slots ()
{
}
template <class SlotType>
bool SlotList<SlotType>::Insert (const std::shared_ptr<SlotType>& slot)
{
return slots.Insert (slot->GetId (), slot);
}
template <class SlotType>
bool SlotList<SlotType>::InsertBefore (const std::shared_ptr<SlotType>& slot, const SlotId& nextSlotId)
{
return slots.InsertBefore (slot->GetId (), slot, nextSlotId);
}
template <class SlotType>
bool SlotList<SlotType>::InsertAfter (const std::shared_ptr<SlotType>& slot, const SlotId& prevSlotId)
{
return slots.InsertAfter (slot->GetId (), slot, prevSlotId);
}
template <class SlotType>
std::shared_ptr<SlotType> SlotList<SlotType>::Get (const SlotId& slotId)
{
if (DBGERROR (!slots.Contains (slotId))) {
return nullptr;
}
return slots.GetValue (slotId);
}
template <class SlotType>
std::shared_ptr<const SlotType> SlotList<SlotType>::Get (const SlotId& slotId) const
{
if (DBGERROR (!slots.Contains (slotId))) {
return nullptr;
}
return slots.GetValue (slotId);
}
template <class SlotType>
bool SlotList<SlotType>::Contains (const SlotId& slotId) const
{
return slots.Contains (slotId);
}
template <class SlotType>
size_t SlotList<SlotType>::Count () const
{
return slots.Count ();
}
template <class SlotType>
bool SlotList<SlotType>::IsEmpty () const
{
return slots.IsEmpty ();
}
template <class SlotType>
void SlotList<SlotType>::Enumerate (const std::function<bool (std::shared_ptr<SlotType>&)>& processor)
{
slots.Enumerate ([&] (std::shared_ptr<SlotType>& slot) {
return processor (slot);
});
}
template <class SlotType>
void SlotList<SlotType>::Enumerate (const std::function<bool (const std::shared_ptr<const SlotType>&)>& processor) const
{
slots.Enumerate ([&] (const std::shared_ptr<SlotType>& slot) {
return processor (slot);
});
}
}
#endif