22
22
23
23
namespace nop {
24
24
25
- // Generates a pair of template arguments (member pointer type and value) to be
26
- // passed to MemberPointer<MemberPointerType, MemberPointerValue, ...> from the
27
- // given type name and member name.
28
- #define _NOP_MEMBER_POINTER (type, member ) decltype(&type::member), &type::member
29
-
30
- // Generates a MemberPointer type definition, given a type name and a variable
31
- // number of member names. The first member name is handled here, while the
32
- // remaining member names are passed to _NOP_MEMBER_POINTER_NEXT for recursive
33
- // expansion.
34
- #define _NOP_MEMBER_POINTER_FIRST (type, ...) \
35
- ::nop::MemberPointer<_NOP_MEMBER_POINTER(type, _NOP_FIRST_ARG(__VA_ARGS__)) \
36
- _NOP_MEMBER_POINTER_NEXT ( \
37
- type, _NOP_REST_ARG(__VA_ARGS__))>
38
-
39
- // Recursively handles the remaining member names in the template argument list
40
- // for MemberPointer.
41
- #define _NOP_MEMBER_POINTER_NEXT (type, ...) \
42
- _NOP_IF_ELSE (_NOP_HAS_ARGS(__VA_ARGS__)) \
43
- (, _NOP_MEMBER_POINTER(type, _NOP_FIRST_ARG(__VA_ARGS__)) \
44
- _NOP_DEFER2 (__NOP_MEMBER_POINTER_NEXT)()( \
45
- type, _NOP_REST_ARG(__VA_ARGS__)))(/* done*/ )
46
-
47
- // Indirection to enable recursive macro expansion of _NOP_MEMBER_POINTER_NEXT.
48
- #define __NOP_MEMBER_POINTER_NEXT () _NOP_MEMBER_POINTER_NEXT
49
-
50
- // Defines a list of MemberPointer types given a type and list of member names.
51
- #define NOP_MEMBER_LIST (type, ...) \
52
- NOP_MAP_ARGS (_NOP_MEMBER_POINTER_FIRST, (type), __VA_ARGS__)
25
+ //
26
+ // User-defined structures are structs or classes that have been annotated so
27
+ // that the serialization engine understands how to read and write them.
53
28
54
29
// Defines the set of members belonging to a type that should be
55
- // serialized/deserialized. This macro should be called once within the
30
+ // serialized/deserialized. This macro must be inkoked once within the
56
31
// struct/class definition, preferrably in the private section for classes with
57
32
// private data.
58
- #define NOP_MEMBERS (type, ... /* members*/ ) \
33
+ #define NOP_STRUCTURE (type, ... /* members*/ ) \
59
34
template <typename , typename > \
60
35
friend struct ::nop::Encoding; \
61
36
template <typename , typename > \
@@ -67,7 +42,7 @@ namespace nop {
67
42
// Defines the set of members belonging to a type that should be
68
43
// serialized/deserialized without changing the type itself. This is useful for
69
44
// making external library types with public data serializable.
70
- #define NOP_STRUCTURE (type, ... /* members*/ ) \
45
+ #define NOP_EXTERNAL_STRUCTURE (type, ... /* members*/ ) \
71
46
template <typename > \
72
47
struct NOP__MEMBER_TRAITS ; \
73
48
template <> \
@@ -77,8 +52,8 @@ namespace nop {
77
52
NOP__MEMBER_TRAITS<type> __attribute__ ((used)) \
78
53
NOP__GetExternalMemberTraits(type*)
79
54
80
- // Similar to NOP_STRUCTURE but for template types.
81
- #define NOP_TEMPLATE (type, ... /* members*/ ) \
55
+ // Similar to NOP_EXTERNAL_STRUCTURE but for template types.
56
+ #define NOP_EXTERNAL_TEMPLATE (type, ... /* members*/ ) \
82
57
template <typename > \
83
58
struct NOP__MEMBER_TRAITS ; \
84
59
template <typename ... Ts> \
@@ -90,6 +65,39 @@ namespace nop {
90
65
NOP__MEMBER_TRAITS<type<Ts...>> __attribute__ ((used)) \
91
66
NOP__GetExternalMemberTraits(type<Ts...>*)
92
67
68
+ //
69
+ // Utility macros used by the macros above.
70
+ //
71
+
72
+ // Generates a pair of template arguments (member pointer type and value) to be
73
+ // passed to MemberPointer<MemberPointerType, MemberPointerValue, ...> from the
74
+ // given type name and member name.
75
+ #define _NOP_MEMBER_POINTER (type, member ) decltype(&type::member), &type::member
76
+
77
+ // Generates a MemberPointer type definition, given a type name and a variable
78
+ // number of member names. The first member name is handled here, while the
79
+ // remaining member names are passed to _NOP_MEMBER_POINTER_NEXT for recursive
80
+ // expansion.
81
+ #define _NOP_MEMBER_POINTER_FIRST (type, ...) \
82
+ ::nop::MemberPointer<_NOP_MEMBER_POINTER(type, _NOP_FIRST_ARG(__VA_ARGS__)) \
83
+ _NOP_MEMBER_POINTER_NEXT ( \
84
+ type, _NOP_REST_ARG(__VA_ARGS__))>
85
+
86
+ // Recursively handles the remaining member names in the template argument list
87
+ // for MemberPointer.
88
+ #define _NOP_MEMBER_POINTER_NEXT (type, ...) \
89
+ _NOP_IF_ELSE (_NOP_HAS_ARGS(__VA_ARGS__)) \
90
+ (, _NOP_MEMBER_POINTER(type, _NOP_FIRST_ARG(__VA_ARGS__)) \
91
+ _NOP_DEFER2 (__NOP_MEMBER_POINTER_NEXT)()( \
92
+ type, _NOP_REST_ARG(__VA_ARGS__)))(/* done*/ )
93
+
94
+ // Indirection to enable recursive macro expansion of _NOP_MEMBER_POINTER_NEXT.
95
+ #define __NOP_MEMBER_POINTER_NEXT () _NOP_MEMBER_POINTER_NEXT
96
+
97
+ // Defines a list of MemberPointer types given a type and list of member names.
98
+ #define NOP_MEMBER_LIST (type, ...) \
99
+ NOP_MAP_ARGS (_NOP_MEMBER_POINTER_FIRST, (type), __VA_ARGS__)
100
+
93
101
} // namespace nop
94
102
95
103
#endif // LIBNOP_INCLUDE_NOP_STRUCTURE_H_
0 commit comments