-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTracker.h
More file actions
59 lines (41 loc) · 1.04 KB
/
Copy pathTracker.h
File metadata and controls
59 lines (41 loc) · 1.04 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
/** $VER: Tracker.h (2026.07.13) P. Stuer - Tracks the registered instances. **/
#pragma once
#include <vector>
template <typename T>
class tracker_t
{
public:
tracker_t() : _Current() { }
tracker_t(const tracker_t &) = delete;
tracker_t & operator=(const tracker_t &) = delete;
tracker_t(tracker_t &&) = delete;
tracker_t & operator=(tracker_t &&) = delete;
virtual ~tracker_t() { };
void Add(T * item) noexcept
{
std::unique_lock Lock(_Mutex);
_Items.push_back(item);
SetCurrent(item);
}
void Remove(T * item) noexcept
{
std::unique_lock Lock(_Mutex);
auto Iter = std::find(_Items.begin(), _Items.end(), item);
if (Iter == _Items.end())
return;
_Items.erase(Iter);
SetCurrent(nullptr);
}
T * GetCurrent() const noexcept
{
return _Current;
}
void SetCurrent(T * item) noexcept
{
_Current = item;
}
private:
std::mutex _Mutex;
T * _Current;
std::vector<T *> _Items;
};