Tool Libs
UMIT-TIROL Institute of Automation and Control Engineering library collection
 
Loading...
Searching...
No Matches
registry.h
Go to the documentation of this file.
1
5#pragma once
6
7
12template<typename T, typename H, unsigned int sz>
13class Registry {
14 T *t[sz];
15 H *h[sz];
16 unsigned int len = 0;
17public:
19 void reg(T *inst, H *handle) {
20 for (unsigned int i = 0; i < len; ++i) {
21 assert(t[i] != inst); // class instance already registered!
22 }
23 t[len] = inst;
24 h[len] = handle;
25 ++len;
26 }
28 T* from(H *handle) {
29 for (unsigned int i = 0; i < len; ++i) {
30 if (h[i] == handle) return t[i];
31 }
32 assert(false); // make sure to register the (instance,handle) pair first
33 return nullptr;
34 }
35};
registry that maps classes to HAL handles
Definition registry.h:13
void reg(T *inst, H *handle)
register given class instance to handle
Definition registry.h:19
T * from(H *handle)
get registered class instance from handle
Definition registry.h:28