COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
include
comms
details
bits_access.h
1
//
2
// Copyright 2016 - 2024 (C). Alex Robenko. All rights reserved.
3
//
4
// This Source Code Form is subject to the terms of the Mozilla Public
5
// License, v. 2.0. If a copy of the MPL was not distributed with this
6
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8
9
#pragma once
10
11
#include <tuple>
12
#include <type_traits>
13
14
#include "macro_common.h"
15
#include "gen_enum.h"
16
#include "base_detection.h"
17
18
#ifdef COMMS_MUST_DEFINE_BASE
19
#define COMMS_AS_BITMASK_FUNC Base& asBitmask()
20
#define COMMS_AS_BITMASK_CONST_FUNC const Base& asBitmask() const
21
#else
// #ifdef COMMS_MUST_DEFINE_BASE
22
#define COMMS_AS_BITMASK_FUNC FUNC_AUTO_REF_RETURN(asBitmask, decltype(comms::field::toFieldBase(*this)))
23
#define COMMS_AS_BITMASK_CONST_FUNC FUNC_AUTO_REF_RETURN_CONST(asBitmask, decltype(comms::field::toFieldBase(*this)))
24
#endif
// #ifdef COMMS_MUST_DEFINE_BASE
25
26
#define COMMS_BIT_ACC_FUNC(f_, n_) \
27
bool COMMS_CONCATENATE(getBitValue_, n_)() const {\
28
return f_.getBitValue(COMMS_CONCATENATE(BitIdx_, n_)); \
29
} \
30
void COMMS_CONCATENATE(setBitValue_, n_)(bool val) {\
31
f_.setBitValue(COMMS_CONCATENATE(BitIdx_, n_), val); \
32
}
33
34
#define COMMS_BIT_ACC_FUNC_1(f_, n_) COMMS_BIT_ACC_FUNC(f_, n_)
35
#define COMMS_BIT_ACC_FUNC_2(f_, n_, ...) \
36
COMMS_BIT_ACC_FUNC(f_, n_) \
37
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_1(f_, __VA_ARGS__))
38
#define COMMS_BIT_ACC_FUNC_3(f_, n_, ...) \
39
COMMS_BIT_ACC_FUNC(f_, n_) \
40
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_2(f_, __VA_ARGS__))
41
#define COMMS_BIT_ACC_FUNC_4(f_, n_, ...) \
42
COMMS_BIT_ACC_FUNC(f_, n_) \
43
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_3(f_, __VA_ARGS__))
44
#define COMMS_BIT_ACC_FUNC_5(f_, n_, ...) \
45
COMMS_BIT_ACC_FUNC(f_, n_) \
46
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_4(f_, __VA_ARGS__))
47
#define COMMS_BIT_ACC_FUNC_6(f_, n_, ...) \
48
COMMS_BIT_ACC_FUNC(f_, n_) \
49
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_5(f_, __VA_ARGS__))
50
#define COMMS_BIT_ACC_FUNC_7(f_, n_, ...) \
51
COMMS_BIT_ACC_FUNC(f_, n_) \
52
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_6(f_, __VA_ARGS__))
53
#define COMMS_BIT_ACC_FUNC_8(f_, n_, ...) \
54
COMMS_BIT_ACC_FUNC(f_, n_) \
55
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_7(f_, __VA_ARGS__))
56
#define COMMS_BIT_ACC_FUNC_9(f_, n_, ...) \
57
COMMS_BIT_ACC_FUNC(f_, n_) \
58
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_8(f_, __VA_ARGS__))
59
#define COMMS_BIT_ACC_FUNC_10(f_, n_, ...) \
60
COMMS_BIT_ACC_FUNC(f_, n_) \
61
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_9(f_, __VA_ARGS__))
62
#define COMMS_BIT_ACC_FUNC_11(f_, n_, ...) \
63
COMMS_BIT_ACC_FUNC(f_, n_) \
64
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_10(f_, __VA_ARGS__))
65
#define COMMS_BIT_ACC_FUNC_12(f_, n_, ...) \
66
COMMS_BIT_ACC_FUNC(f_, n_) \
67
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_11(f_, __VA_ARGS__))
68
#define COMMS_BIT_ACC_FUNC_13(f_, n_, ...) \
69
COMMS_BIT_ACC_FUNC(f_, n_) \
70
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_12(f_, __VA_ARGS__))
71
#define COMMS_BIT_ACC_FUNC_14(f_, n_, ...) \
72
COMMS_BIT_ACC_FUNC(f_, n_) \
73
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_13(f_, __VA_ARGS__))
74
#define COMMS_BIT_ACC_FUNC_15(f_, n_, ...) \
75
COMMS_BIT_ACC_FUNC(f_, n_) \
76
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_14(f_, __VA_ARGS__))
77
#define COMMS_BIT_ACC_FUNC_16(f_, n_, ...) \
78
COMMS_BIT_ACC_FUNC(f_, n_) \
79
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_15(f_, __VA_ARGS__))
80
#define COMMS_BIT_ACC_FUNC_17(f_, n_, ...) \
81
COMMS_BIT_ACC_FUNC(f_, n_) \
82
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_16(f_, __VA_ARGS__))
83
#define COMMS_BIT_ACC_FUNC_18(f_, n_, ...) \
84
COMMS_BIT_ACC_FUNC(f_, n_) \
85
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_17(f_, __VA_ARGS__))
86
#define COMMS_BIT_ACC_FUNC_19(f_, n_, ...) \
87
COMMS_BIT_ACC_FUNC(f_, n_) \
88
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_18(f_, __VA_ARGS__))
89
#define COMMS_BIT_ACC_FUNC_20(f_, n_, ...) \
90
COMMS_BIT_ACC_FUNC(f_, n_) \
91
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_19(f_, __VA_ARGS__))
92
#define COMMS_BIT_ACC_FUNC_21(f_, n_, ...) \
93
COMMS_BIT_ACC_FUNC(f_, n_) \
94
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_20(f_, __VA_ARGS__))
95
#define COMMS_BIT_ACC_FUNC_22(f_, n_, ...) \
96
COMMS_BIT_ACC_FUNC(f_, n_) \
97
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_21(f_, __VA_ARGS__))
98
#define COMMS_BIT_ACC_FUNC_23(f_, n_, ...) \
99
COMMS_BIT_ACC_FUNC(f_, n_) \
100
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_22(f_, __VA_ARGS__))
101
#define COMMS_BIT_ACC_FUNC_24(f_, n_, ...) \
102
COMMS_BIT_ACC_FUNC(f_, n_) \
103
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_23(f_, __VA_ARGS__))
104
#define COMMS_BIT_ACC_FUNC_25(f_, n_, ...) \
105
COMMS_BIT_ACC_FUNC(f_, n_) \
106
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_24(f_, __VA_ARGS__))
107
#define COMMS_BIT_ACC_FUNC_26(f_, n_, ...) \
108
COMMS_BIT_ACC_FUNC(f_, n_) \
109
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_25(f_, __VA_ARGS__))
110
#define COMMS_BIT_ACC_FUNC_27(f_, n_, ...) \
111
COMMS_BIT_ACC_FUNC(f_, n_) \
112
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_26(f_, __VA_ARGS__))
113
#define COMMS_BIT_ACC_FUNC_28(f_, n_, ...) \
114
COMMS_BIT_ACC_FUNC(f_, n_) \
115
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_27(f_, __VA_ARGS__))
116
#define COMMS_BIT_ACC_FUNC_29(f_, n_, ...) \
117
COMMS_BIT_ACC_FUNC(f_, n_) \
118
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_28(f_, __VA_ARGS__))
119
#define COMMS_BIT_ACC_FUNC_30(f_, n_, ...) \
120
COMMS_BIT_ACC_FUNC(f_, n_) \
121
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_29(f_, __VA_ARGS__))
122
#define COMMS_BIT_ACC_FUNC_31(f_, n_, ...) \
123
COMMS_BIT_ACC_FUNC(f_, n_) \
124
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_30(f_, __VA_ARGS__))
125
#define COMMS_BIT_ACC_FUNC_32(f_, n_, ...) \
126
COMMS_BIT_ACC_FUNC(f_, n_) \
127
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_31(f_, __VA_ARGS__))
128
#define COMMS_BIT_ACC_FUNC_33(f_, n_, ...) \
129
COMMS_BIT_ACC_FUNC(f_, n_) \
130
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_32(f_, __VA_ARGS__))
131
#define COMMS_BIT_ACC_FUNC_34(f_, n_, ...) \
132
COMMS_BIT_ACC_FUNC(f_, n_) \
133
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_33(f_, __VA_ARGS__))
134
#define COMMS_BIT_ACC_FUNC_35(f_, n_, ...) \
135
COMMS_BIT_ACC_FUNC(f_, n_) \
136
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_34(f_, __VA_ARGS__))
137
#define COMMS_BIT_ACC_FUNC_36(f_, n_, ...) \
138
COMMS_BIT_ACC_FUNC(f_, n_) \
139
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_35(f_, __VA_ARGS__))
140
#define COMMS_BIT_ACC_FUNC_37(f_, n_, ...) \
141
COMMS_BIT_ACC_FUNC(f_, n_) \
142
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_36(f_, __VA_ARGS__))
143
#define COMMS_BIT_ACC_FUNC_38(f_, n_, ...) \
144
COMMS_BIT_ACC_FUNC(f_, n_) \
145
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_37(f_, __VA_ARGS__))
146
#define COMMS_BIT_ACC_FUNC_39(f_, n_, ...) \
147
COMMS_BIT_ACC_FUNC(f_, n_) \
148
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_38(f_, __VA_ARGS__))
149
#define COMMS_BIT_ACC_FUNC_40(f_, n_, ...) \
150
COMMS_BIT_ACC_FUNC(f_, n_) \
151
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_39(f_, __VA_ARGS__))
152
#define COMMS_BIT_ACC_FUNC_41(f_, n_, ...) \
153
COMMS_BIT_ACC_FUNC(f_, n_) \
154
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_40(f_, __VA_ARGS__))
155
#define COMMS_BIT_ACC_FUNC_42(f_, n_, ...) \
156
COMMS_BIT_ACC_FUNC(f_, n_) \
157
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_41(f_, __VA_ARGS__))
158
#define COMMS_BIT_ACC_FUNC_43(f_, n_, ...) \
159
COMMS_BIT_ACC_FUNC(f_, n_) \
160
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_42(f_, __VA_ARGS__))
161
#define COMMS_BIT_ACC_FUNC_44(f_, n_, ...) \
162
COMMS_BIT_ACC_FUNC(f_, n_) \
163
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_43(f_, __VA_ARGS__))
164
#define COMMS_BIT_ACC_FUNC_45(f_, n_, ...) \
165
COMMS_BIT_ACC_FUNC(f_, n_) \
166
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_44(f_, __VA_ARGS__))
167
#define COMMS_BIT_ACC_FUNC_46(f_, n_, ...) \
168
COMMS_BIT_ACC_FUNC(f_, n_) \
169
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_45(f_, __VA_ARGS__))
170
#define COMMS_BIT_ACC_FUNC_47(f_, n_, ...) \
171
COMMS_BIT_ACC_FUNC(f_, n_) \
172
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_46(f_, __VA_ARGS__))
173
#define COMMS_BIT_ACC_FUNC_48(f_, n_, ...) \
174
COMMS_BIT_ACC_FUNC(f_, n_) \
175
COMMS_EXPAND(COMMS_BIT_ACC_FUNC_47(f_, __VA_ARGS__))
176
177
#define COMMS_CHOOSE_BIT_ACC_FUNC_(N, f_, ...) COMMS_EXPAND(COMMS_BIT_ACC_FUNC_ ## N(f_, __VA_ARGS__))
178
#define COMMS_CHOOSE_BIT_ACC_FUNC(N, f_, ...) COMMS_EXPAND(COMMS_CHOOSE_BIT_ACC_FUNC_(N, f_, __VA_ARGS__))
179
#define COMMS_DO_BIT_ACC_FUNC(f_, ...) \
180
COMMS_EXPAND(COMMS_CHOOSE_BIT_ACC_FUNC(COMMS_NUM_ARGS(__VA_ARGS__), f_, __VA_ARGS__))
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
Generated by
1.9.8