My Project
Loading...
Searching...
No Matches
flags.h
Go to the documentation of this file.
1
4#ifndef __FLAGS
5#define __FLAGS
6
7#ifndef __cplusplus
8#define SET_FLAG(a, b) (a)->flag |= (ae_flag_##b)
9#else
10#define SET_FLAG(a, b) \
11 { \
12 const int f = a->flag | (ae_flag_##b); \
13 (a->flag) = (ae_flag)f; \
14 }
15#endif
16#define GET_FLAG(a, b) (((a)->flag & ae_flag_##b) == (ae_flag_##b))
17#define SAFE_FLAG(a, b) (a && ((a)->flag & (ae_flag_##b)) == (ae_flag_##b))
18#define UNSET_FLAG(a, b) ((a)->flag &= ~(ae_flag_##b))
19
20typedef enum {
21 ae_flag_none = 1 << 0,
25 ae_flag_const = 1 << 4,
26 ae_flag_late = 1 << 5,
28 ae_flag_final = 1 << 7,
30} __attribute__((packed)) ae_flag;
31
32// function factory for other flag
33#define _FLAG_FUNC(A, a) \
34 ANN static inline int a##flag(const A a, const enum a##flag flag) { \
35 return (a->a##flag & flag) == flag; \
36 } \
37 static inline int safe_##a##flag(const A a, const enum a##flag flag) { \
38 return a ? ((a->a##flag & flag) == flag) : 0; \
39 }
40#ifndef __cplusplus
41#define FLAG_FUNC(A, a) \
42 ANN static inline void set_##a##flag(A a, const enum a##flag flag) { \
43 a->a##flag |= flag; \
44 } \
45 static inline void unset_##a##flag(A a, const enum a##flag flag) { \
46 a->a##flag &= ~flag; \
47 } \
48 _FLAG_FUNC(A, a)
49#else
50#define FLAG_FUNC(A, a) \
51 ANN static inline void set_##a##flag(A a, const enum a##flag flag) { \
52 auto ff = a->a##flag | flag; \
53 a->a##flag = static_cast<enum a##flag>(ff); \
54 } \
55 static inline void unset_##a##flag(A a, const enum a##flag flag) { \
56 const auto ff = a->a##flag & ~flag; \
57 a->a##flag = static_cast<enum a##flag>(ff); \
58 } \
59 _FLAG_FUNC(A, a)
60#endif
61
62#endif
__attribute__
Definition flags.h:20
@ ae_flag_protect
Definition flags.h:29
@ ae_flag_static
Definition flags.h:22
@ ae_flag_global
Definition flags.h:24
@ ae_flag_private
Definition flags.h:23
@ ae_flag_late
Definition flags.h:26
@ ae_flag_none
Definition flags.h:21
@ ae_flag_const
Definition flags.h:25
@ ae_flag_abstract
Definition flags.h:27
@ ae_flag_final
Definition flags.h:28