-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefine_structure.h
55 lines (47 loc) · 2.6 KB
/
define_structure.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef SRC_RENDERER_VULKAN_API_STRUCTURES_DEFINE_STRUCTURE_H_
#define SRC_RENDERER_VULKAN_API_STRUCTURES_DEFINE_STRUCTURE_H_
#define __STRUCTURE_BUILDER(name, structure, initializer) \
class name { \
private: \
structure value_; \
\
public: \
constexpr name() : value_(initializer) {} \
constexpr name(structure value) : value_(value) {} \
\
constexpr operator structure() const { \
return value_; \
} \
\
constexpr structure BuildObject() const { \
return value_; \
} \
\
constexpr const structure* Build() const { \
return &value_; \
}
#define STRUCTURE_BUILDER(name, structure, structureType) \
__STRUCTURE_BUILDER(name, structure, {.sType = structureType})
#define STRUCTURE_BUILDER_NO_STYPE(name, structure) \
__STRUCTURE_BUILDER(name, structure, )
#define STRUCTURE_SETTER(methodName, argumentType, argumentName) \
constexpr auto& Set##methodName(argumentType argumentName) { \
value_.argumentName = argumentName; \
return *this; \
}
#define STRUCTURE_SETTER_POINTER_FROM_BUILDER(methodName, builderType, \
argumentName) \
constexpr auto& Set##methodName(const builderType& argumentNameBuilder) { \
value_.argumentName = argumentNameBuilder.Build(); \
return *this; \
}
#define STRUCTURE_SETTER_CUSTOM_ASSIGNMENT(methodName, argumentType, \
argumentName, assignment) \
constexpr auto& Set##methodName(argumentType argumentName) { \
value_.assignment = argumentName; \
return *this; \
}
#define END_STRUCTURE_BUILDER \
} \
;
#endif // SRC_RENDERER_VULKAN_API_STRUCTURES_DEFINE_STRUCTURE_H_