1#pragma once
2
3/*
4 * Built-in interface ids
5 */
6#define PwInterfaceId_Basic 0
7#define PwInterfaceId_RandomAccess 1
8#define PwInterfaceId_Reader 2
9#define PwInterfaceId_Writer 3
10#define PwInterfaceId_LineReader 4
11#define PwInterfaceId_Append 5
12#define PwInterfaceId_Fd 6
13
14#define PW_NUM_BUILTIN_INTERFACES 7
15
16/*
17 * Method declaration macros
18 */
19
20#define PW_METHOD_BEGIN(interface_name, method_name) \
21 struct _PwInterface_##interface_name; \
22 struct _PwMethod_##interface_name##_##method_name; \
23 typedef struct _PwMethod_##interface_name##_##method_name PwMethod_##interface_name##_##method_name; \
24 typedef
25
26#define PW_METHOD_END(interface_name, method_name) \
27 ; \
28 struct _PwMethod_##interface_name##_##method_name { \
29 [[ gnu::warn_unused_result ]] PwFunc_##interface_name##_##method_name func; \
30 struct _PwMethod_##interface_name##_##method_name* super; \
31 struct _PwInterface_##interface_name* self; \
32 unsigned struct_offset; \
33 uint16_t type_id; \
34 };
35/* Note:
36 * struct_offset is a shorthand copy of self->type->struct_offsets[0]
37 */
38
39/*
40 * Interface declaration macros
41 */
42#define PW_INTERFACE_BEGIN(interface_name) \
43 struct _PwInterface_##interface_name { \
44 uint16_t id; \
45 uint16_t num_methods; \
46 char* name; \
47 char** method_names; \
48 struct _PwType* type;
49
50#define PW_INTERFACE_END(interface_name) \
51 }; \
52 typedef struct _PwInterface_##interface_name PwInterface_##interface_name;
53
54
55/*
56 * Generic interface.
57 *
58 * This structure is used in PwType and by basic interface-agnostic functions.
59 */
60
61struct _PwType; // forward declaration
62
63PW_METHOD_BEGIN(Generic, Generic)
64 bool (*PwFunc_Generic_Generic)(PwMethod_Generic_Generic* mthis, ...)
65PW_METHOD_END(Generic, Generic)
66
67PW_INTERFACE_BEGIN(Generic)
68 PwMethod_Generic_Generic methods[]; // for real interfaces this is multiple fields, not an array
69PW_INTERFACE_END(Generic)
70
71// shortcuts
72typedef PwMethod_Generic_Generic PwMethod_Generic;
73typedef PwFunc_Generic_Generic PwFunc_Generic;
74
75
76#ifdef __cplusplus
77}
78#endif