-
Notifications
You must be signed in to change notification settings - Fork 0
/
postinit.hh
35 lines (32 loc) · 1.24 KB
/
postinit.hh
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 POSTINITHH
#define POSTINITHH
#ifndef TEG_NO_POSTINIT
#include "teg.hh"
#include <functional>
namespace TEG {
/* Usage: (in global scope ONLY)
static TEG::PostInitHandler whatever(priority, []() {
// code goes here
});
where priority determines the order of execution. (If not specified, the
priority is 0.)
Handlers are executed after all C++ static initialization is completed,
and after TEG has done all TEG-specific initialization (e.g. command line
handling), but before teg_main is called.
Execution order: 0, 1, ..., max(priority), min(priority), ..., -2, -1
Don't provide absurdly large or small priorities; they're handled with
arrays! Only use non-zero priorities to ensure that your InitHandler runs
before/after a specific other InitHandler (or InitHandlers) that it
depends on (or is depended on by) */
struct PostInitHandler {
PostInitHandler(int priority, std::function<void()> handler);
PostInitHandler(std::function<void()> handler)
: PostInitHandler(0, handler) {}
/* We do not provide a destructor. We assume we will be used correctly. */
};
#if WE_ARE_IN_CHARGE_OF_POSTINIT_HANDLING || WE_ARE_POSTINIT_CC
void DoPostInit();
#endif
}
#endif
#endif