-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathplooc_class_strict.h
472 lines (400 loc) · 27.1 KB
/
plooc_class_strict.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
/*****************************************************************************
* Copyright(C)2009-2019 by GorgonMeducer<[email protected]> *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
****************************************************************************/
//#ifndef __PLOOC_CLASS_STRICT_H__ /* deliberately comment this out! */
//#define __PLOOC_CLASS_STRICT_H__ /* deliberately comment this out! */
/******************************************************************************
* HOW TO USE *
******************************************************************************/
//!Add following content to your module header file, e.g. xxxxxx.h
//#include "plooc_class.h"
/*============================ INCLUDES ======================================*/
//#include <stdint.h>
/*! \NOTE the uint_fast8_t used in this header file is defined in stdint.h
if you don't have stdint.h supported in your toolchain, you should
define uint_fast8_t all by yourself with following rule:
a. if the target processor is 8 bits, define it as uint8_t
b. if the target processor is 16 bits, define it as uint16_t
c. if the target processor is 32 bits, define it as uint32_t
d. if the target processor is 64 bits, define it as either uint32_t or
uint64_t
*/
#ifdef __cplusplus
extern "C" {
#endif
/*============================ MACROS ========================================*/
#undef dcl_class
#undef declare_class
#undef def_class
#undef define_class
#undef __def_class2
#undef __def_class3
#undef __def_class4
#undef __def_class5
#undef __def_class6
#undef __def_class7
#undef __def_class8
#undef __def_class
#undef end_def_class
#undef end_define_class
#undef __end_def_class
#undef extern_class
#undef __extern_class
#undef end_extern_class
#undef __end_extern_class
/*============================ MACROFIED FUNCTIONS ===========================*/
#if defined(__PLOOC_CLASS_IMPLEMENT__) || defined(__PLOOC_CLASS_IMPLEMENT)
# define __def_class2(__name, _1) \
typedef struct __name __name; \
typedef struct __##__name __##__name; \
struct __##__name { \
__PLOOC_CONNECT2(__PLOOC_PRI_,_1) \
}; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
};
# define __def_class3(__name, _1, _2) \
typedef struct __name __name; \
typedef struct __##__name __##__name; \
struct __##__name { \
__PLOOC_CONNECT2(__PLOOC_PRI_,_1) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_2) \
}; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
};
# define __def_class4(__name, _1, _2, _3) \
typedef struct __name __name; \
typedef struct __##__name __##__name; \
struct __##__name { \
__PLOOC_CONNECT2(__PLOOC_PRI_,_1) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_2) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_3) \
}; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
};
# define __def_class5(__name, _1, _2, _3, _4) \
typedef struct __name __name; \
typedef struct __##__name __##__name; \
struct __##__name { \
__PLOOC_CONNECT2(__PLOOC_PRI_,_1) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_2) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_3) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_4) \
}; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
};
# define __def_class6(__name, _1, _2, _3, _4, _5) \
typedef struct __name __name; \
typedef struct __##__name __##__name; \
struct __##__name { \
__PLOOC_CONNECT2(__PLOOC_PRI_,_1) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_2) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_3) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_4) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_5) \
}; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
};
# define __def_class7(__name, _1, _2, _3, _4, _5, _6) \
typedef struct __name __name; \
typedef struct __##__name __##__name; \
struct __##__name { \
__PLOOC_CONNECT2(__PLOOC_PRI_,_1) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_2) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_3) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_4) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_5) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_6) \
}; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_6) \
};
# define __def_class8(__name, _1, _2, _3, _4, _5, _6, _7) \
typedef struct __name __name; \
typedef struct __##__name __##__name; \
struct __##__name { \
__PLOOC_CONNECT2(__PLOOC_PRI_,_1) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_2) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_3) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_4) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_5) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_6) \
__PLOOC_CONNECT2(__PLOOC_PRI_,_7) \
}; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_6) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_7) \
};
# define __end_def_class(...)
# define __extern_class(...)
# define __end_extern_class(...)
# undef __class
# define __class(__name) __##__name
# undef class
# define class(__name) __class(__name)
# undef __with_class
# define __with_class(__type, __src, ...) \
{ \
class(__type)*_ =(class(__type) *)(__src); \
PLOOC_UNUSED_PARAM(_); \
__VA_ARGS__; \
} \
for (class(__type)*_ =(class(__type) *)(__src);NULL != _; _ = NULL)
# undef with_class
# define with_class(__type, __src, ...) \
__with_class(__type, __src, __VA_ARGS__)
# undef __class_internal
# define __class_internal(__src, __des, __type, ...) \
class(__type) *(__des) = (class(__type) *)(__src); \
PLOOC_UNUSED_PARAM(__des); \
__with_class(__type, (__src), __VA_ARGS__)
# undef class_internal
# define class_internal(__src, __des, __type,...) \
__class_internal(__src, __des, __type, __VA_ARGS__)
#elif defined(__PLOOC_CLASS_INHERIT__) || defined(__PLOOC_CLASS_INHERIT)
# define __def_class2(__name, _1) \
typedef struct __name __name; \
struct __protected_##__name { \
__PLOOC_CONNECT2(__PLOOC_PRO_,_1) \
}; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
};
# define __def_class3(__name, _1, _2) \
typedef struct __name __name; \
struct __protected_##__name { \
__PLOOC_CONNECT2(__PLOOC_PRO_,_1) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_2) \
}; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
};
# define __def_class4(__name, _1, _2, _3) \
typedef struct __name __name; \
struct __protected_##__name { \
__PLOOC_CONNECT2(__PLOOC_PRO_,_1) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_2) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_3) \
}; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
};
# define __def_class5(__name, _1, _2, _3, _4) \
typedef struct __name __name; \
struct __protected_##__name { \
__PLOOC_CONNECT2(__PLOOC_PRO_,_1) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_2) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_3) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_4) \
}; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
};
# define __def_class6(__name, _1, _2, _3, _4, _5) \
typedef struct __name __name; \
struct __protected_##__name { \
__PLOOC_CONNECT2(__PLOOC_PRO_,_1) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_2) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_3) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_4) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_5) \
}; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
};
# define __def_class7(__name, _1, _2, _3, _4, _5, _6) \
typedef struct __name __name; \
struct __protected_##__name { \
__PLOOC_CONNECT2(__PLOOC_PRO_,_1) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_2) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_3) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_4) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_5) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_6) \
}; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_6) \
};
# define __def_class8(__name, _1, _2, _3, _4, _5, _6, _7) \
typedef struct __name __name; \
struct __protected_##__name { \
__PLOOC_CONNECT2(__PLOOC_PRO_,_1) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_2) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_3) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_4) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_5) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_6) \
__PLOOC_CONNECT2(__PLOOC_PRO_,_7) \
}; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_6) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_7) \
};
# define __end_def_class(...)
# define __extern_class(...)
# define __end_extern_class(...)
# undef __class_protected
# define __class_protected(__name) struct __protected_##__name
# undef class_protected
# define class_protected(__name) __class_protected(__name)
# undef __with_protected
# define __with_protected(__type, __src, ...) \
{ \
class_protected(__type)*_ =(class_protected(__type) *)(__src); \
PLOOC_UNUSED_PARAM(_); \
__VA_ARGS__; \
} \
for ( class_protected(__type)*_ =(class_protected(__type) *)(__src); \
NULL != _; \
_ = NULL)
# undef with_protected
# define with_protected(__type, __src, ...) \
__with_protected(__type, __src, __VA_ARGS__)
# undef __protected_internal
# define __protected_internal(__src, __des, __type, ...) \
class_protected(__type) *(__des)=(class_protected(__type) *)(__src);\
PLOOC_UNUSED_PARAM(__des); \
__with_protected(__type, __src, __VA_ARGS__)
# undef protected_internal
# define protected_internal(__src, __des, __type, ...) \
__protected_internal(__src, __des, __type, __VA_ARGS__)
#else /* __PLOOC_CLASS_EXTERN */
# define __def_class2(__name, _1) \
typedef struct __name __name; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
};
# define __def_class3(__name, _1, _2) \
typedef struct __name __name; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
};
# define __def_class4(__name, _1, _2, _3) \
typedef struct __name __name; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
};
# define __def_class5(__name, _1, _2, _3, _4) \
typedef struct __name __name; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
};
# define __def_class6(__name, _1, _2, _3, _4, _5) \
typedef struct __name __name; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
};
# define __def_class7(__name, _1, _2, _3, _4, _5, _6) \
typedef struct __name __name; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_6) \
};
# define __def_class8(__name, _1, _2, _3, _4, _5, _6, _7) \
typedef struct __name __name; \
struct __name { \
__PLOOC_CONNECT2(__PLOOC_EXT_,_1) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_2) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_3) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_4) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_5) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_6) \
__PLOOC_CONNECT2(__PLOOC_EXT_,_7) \
};
# define __end_def_class(...)
#define __extern_class(...) __PLOOC_EVAL(__def_class, __VA_ARGS__) \
(__VA_ARGS__)
#define __end_extern_class(...)
#endif
#define def_class(...) __PLOOC_EVAL(__def_class, __VA_ARGS__) \
(__VA_ARGS__)
#define define_class(...) def_class(__VA_ARGS__)
#define end_def_class(...) __end_def_class(__VA_ARGS__)
#define end_define_class(...) end_def_class(__VA_ARGS__)
#define declare_class(__name) typedef struct __name __name;
#define dcl_class(__name) declare_class(__name)
#define extern_class(...) __extern_class(__VA_ARGS__)
#define end_extern_class(...) __end_extern_class(__VA_ARGS__)
#undef __PLOOC_CLASS_IMPLEMENT__
#undef __PLOOC_CLASS_INHERIT__
#undef __PLOOC_CLASS_IMPLEMENT
#undef __PLOOC_CLASS_INHERIT
/*============================ TYPES =========================================*/
/*============================ GLOBAL VARIABLES ==============================*/
/*============================ LOCAL VARIABLES ===============================*/
/*============================ PROTOTYPES ====================================*/
//#endif /* deliberately comment this out! */
#ifdef __cplusplus
}
#endif