-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager.h
More file actions
58 lines (48 loc) · 1.63 KB
/
Copy pathmanager.h
File metadata and controls
58 lines (48 loc) · 1.63 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
/*
* ************************************************************************
* Copyright (c) 2025, Dhanush H V. All rights reserved.
* Licensed under the MIT License. See the LICENSE file for more details
* *************************************************************************
*/
#ifndef MANAGER_H
#define MANAGER_H
#include <unordered_set>
template <typename T>
class BUF_MANAGER {
protected:
// All instance buffers would be registered here
// for the same runtime
static std::string TAG;
static inline std::unordered_set<T*> BUFFERS;
public:
BUF_MANAGER() {
// Initialize the buffer for current runtime
TAG = "[BUF_MANAGER]";
BUFFERS = std::unordered_set<T*>();
}
~BUF_MANAGER() {
// Clear all the buffers before runtime exit
// to avoid memory overflow
BUFFERS.clear();
}
// Register a new buffer for the current runtime
static bool register_buf(T* buffer) {
// Register the new buffer to manager
BUFFERS.insert(buffer);
return BUFFERS.contains(buffer);
}
// Unregister an existing registered buffer
static bool unregister_buf(T* buffer) {
BUFFERS.erase(buffer); // remove an existing buffers from the register
return !BUFFERS.contains(buffer); // check if the register was removed successfully
}
// Get all the existing buffers in the register
static std::unordered_set<T*> get_buffs() {
return BUFFERS;
}
// Get the total number of registered buffers in the register
static int buf_size() {
return BUFFERS.size();
}
};
#endif //MANAGER_H