-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathreset.h
35 lines (28 loc) · 789 Bytes
/
reset.h
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
#ifndef __RESET_H
#define __RESET_H
#include <vector>
#include <iostream>
#include <set>
namespace chdl {
void reset(); // Completely reset CHDL state
struct reset_func_base {
virtual ~reset_func_base();
virtual void operator()() = 0;
static std::vector<reset_func_base*> *rfuns();
};
template<typename T> struct reset_func : public reset_func_base {
reset_func(const T &f): f(f) { rfuns()->push_back(this); }
virtual void operator()() { f(); }
const T &f;
};
// Mixin: delete your object on reset;
struct delete_on_reset {
delete_on_reset();
virtual ~delete_on_reset();
static std::set<delete_on_reset*> dors;
};
}
#define CHDL_REGISTER_RESET(x) namespace { \
static reset_func<decltype(x)> __chdl_reset__ ## x (x); \
}
#endif