-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommon.h
More file actions
59 lines (42 loc) · 1.45 KB
/
Common.h
File metadata and controls
59 lines (42 loc) · 1.45 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
#pragma once
// --------------------------------------------------
// all project common types/macros/functions
// --------------------------------------------------
#include <stdint.h>
#include <assert.h>
#include <vector>
// typedefs
using uint = unsigned int;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;
using uchar = unsigned char;
using ID = u32;
using Byte = u8;
using Bytes = std::vector<Byte>;
using Indices = std::vector<uint>;
// macros
#define for_size(var, container) for (u32 var = 0; var < std::size(container); ++var)
#define no_copy_and_assign(obj) \
obj(obj const& other) = delete; \
void operator=(obj const& other) = delete;
#define no_move_and_assign(obj) \
obj(obj && other) = delete; \
void operator=(obj && other) = delete;
#define not_in_use(param) (param)
// black magic macros for unique names
// src = https://stackoverflow.com/questions/2419650/c-c-macro-template-blackmagic-to-generate-unique-name
#define CONCATENATE_DETAIL(x, y) x##y
#define CONCATENATE(x, y) CONCATENATE_DETAIL(x, y)
#define make_unique_name(x) CONCATENATE(x, __COUNTER__)
/// TODO move into own header if needed elsewhere
template <class Action>
struct Deferred_Action {
Deferred_Action(Action&& a) : action(a) {}
~Deferred_Action() { action(); }
Action action;
};
#define on_exit(action) Deferred_Action make_unique_name(deferred_action_)([&](){action;})