COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
field_alias.h
1//
2// Copyright 2019 - 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
12#include "comms/details/macro_common.h"
13
14#define COMMS_ALIAS_MEM_ACC(prefix_, m_) COMMS_CONCATENATE(prefix_, m_)()
15
16#define COMMS_ALIAS_MEM_ACC_1(prefix_, m_) COMMS_EXPAND(COMMS_ALIAS_MEM_ACC(prefix_, m_))
17#define COMMS_ALIAS_MEM_ACC_2(prefix_, m_, ...) \
18 COMMS_ALIAS_MEM_ACC(prefix_, m_) . COMMS_EXPAND(COMMS_ALIAS_MEM_ACC_1(field_, __VA_ARGS__)) // using field_ as next prefix on purpose
19#define COMMS_ALIAS_MEM_ACC_3(prefix_, m_, ...) \
20 COMMS_ALIAS_MEM_ACC(prefix_, m_) . COMMS_EXPAND(COMMS_ALIAS_MEM_ACC_2(field_, __VA_ARGS__)) // using field_ as next prefix on purpose
21#define COMMS_ALIAS_MEM_ACC_4(prefix_, m_, ...) \
22 COMMS_ALIAS_MEM_ACC(prefix_, m_) . COMMS_EXPAND(COMMS_ALIAS_MEM_ACC_3(field_, __VA_ARGS__)) // using field_ as next prefix on purpose
23#define COMMS_ALIAS_MEM_ACC_5(prefix_, m_, ...) \
24 COMMS_ALIAS_MEM_ACC(prefix_, m_) . COMMS_EXPAND(COMMS_ALIAS_MEM_ACC_4(field_, __VA_ARGS__)) // using field_ as next prefix on purpose
25#define COMMS_ALIAS_MEM_ACC_6(prefix_, m_, ...) \
26 COMMS_ALIAS_MEM_ACC(prefix_, m_) . COMMS_EXPAND(COMMS_ALIAS_MEM_ACC_5(field_, __VA_ARGS__)) // using field_ as next prefix on purpose
27#define COMMS_ALIAS_MEM_ACC_7(prefix_, m_, ...) \
28 COMMS_ALIAS_MEM_ACC(prefix_, m_) . COMMS_EXPAND(COMMS_ALIAS_MEM_ACC_6(field_, __VA_ARGS__)) // using field_ as next prefix on purpose
29#define COMMS_ALIAS_MEM_ACC_8(prefix_, m_, ...) \
30 COMMS_ALIAS_MEM_ACC(prefix_, m_) . COMMS_EXPAND(COMMS_ALIAS_MEM_ACC_7(field_, __VA_ARGS__)) // using field_ as next prefix on purpose
31
32#define COMMS_ALIAS_ALL_MEM_ACC_(N, prefix_, ...) COMMS_EXPAND(COMMS_ALIAS_MEM_ACC_ ## N(prefix_, __VA_ARGS__))
33#define COMMS_ALIAS_ALL_MEM_ACC(N, prefix_, ...) COMMS_EXPAND(COMMS_ALIAS_ALL_MEM_ACC_(N, prefix_, __VA_ARGS__))
34#define COMMS_DO_ALIAS_ALL_MEM_ACC(prefix_, ...) \
35 COMMS_EXPAND(COMMS_ALIAS_ALL_MEM_ACC(COMMS_NUM_ARGS(__VA_ARGS__), prefix_, __VA_ARGS__))
36
37
38#if COMMS_IS_CPP14
39
40#define COMMS_DO_ALIAS(prefix_, f1_, ...) \
41 decltype(auto) COMMS_CONCATENATE(prefix_, f1_) () \
42 { \
43 return COMMS_DO_ALIAS_ALL_MEM_ACC(prefix_, __VA_ARGS__); \
44 }\
45 decltype(auto) COMMS_CONCATENATE(prefix_, f1_) () const \
46 { \
47 return COMMS_DO_ALIAS_ALL_MEM_ACC(prefix_, __VA_ARGS__); \
48 }
49
50#define COMMS_DO_ALIAS_NOTEMPLATE(prefix_, f1_, ...) COMMS_EXPAND(COMMS_DO_ALIAS(prefix_, f1_, __VA_ARGS__))
51
52#else // #if COMMS_IS_CPP14
53
54#ifndef COMMS_DO_ALIAS_RET_TYPE_PREFIX
55#define COMMS_DO_ALIAS_RET_TYPE_PREFIX
56#endif // #ifndef COMMS_DO_ALIAS_RET_TYPE_PREFIX
57
58#if defined(__GNUC__) && !defined(__clang__)
59#if __GNUC__ < 5
60#undef COMMS_DO_ALIAS_RET_TYPE_PREFIX
61#define COMMS_DO_ALIAS_RET_TYPE_PREFIX this->
62#endif // #if __GNUC__ < 5
63#endif // #if defined(__GNUC__) && !defined(__clang__)
64
65#define COMMS_DO_ALIAS(prefix_, f1_, ...) \
66 auto COMMS_CONCATENATE(prefix_, f1_) () -> decltype(COMMS_DO_ALIAS_RET_TYPE_PREFIX COMMS_DO_ALIAS_ALL_MEM_ACC(prefix_, __VA_ARGS__)) \
67 { \
68 return COMMS_DO_ALIAS_ALL_MEM_ACC(prefix_, __VA_ARGS__); \
69 }\
70 auto COMMS_CONCATENATE(prefix_, f1_) () const -> decltype(COMMS_DO_ALIAS_RET_TYPE_PREFIX COMMS_DO_ALIAS_ALL_MEM_ACC(prefix_, __VA_ARGS__)) \
71 { \
72 return COMMS_DO_ALIAS_ALL_MEM_ACC(prefix_, __VA_ARGS__); \
73 }
74
75#define COMMS_DO_ALIAS_NOTEMPLATE(prefix_, f1_, ...) \
76 auto COMMS_CONCATENATE(prefix_, f1_) () -> decltype(COMMS_DO_ALIAS_ALL_MEM_ACC(prefix_, __VA_ARGS__)) \
77 { \
78 return COMMS_DO_ALIAS_ALL_MEM_ACC(prefix_, __VA_ARGS__); \
79 }\
80 auto COMMS_CONCATENATE(prefix_, f1_) () const -> decltype(COMMS_DO_ALIAS_ALL_MEM_ACC(prefix_, __VA_ARGS__)) \
81 { \
82 return COMMS_DO_ALIAS_ALL_MEM_ACC(prefix_, __VA_ARGS__); \
83 }
84
85#endif // #if COMMS_IS_CPP14
86
87// ----------------------------------------------
88
89#define COMMS_FIELD_ALIAS_TYPE(P_, m_) COMMS_CONCATENATE(P_, m_)
90
91#define COMMS_FIELD_ALIAS_TYPE_1(P_, m_) COMMS_EXPAND(COMMS_FIELD_ALIAS_TYPE(P_, m_))
92#define COMMS_FIELD_ALIAS_TYPE_2(P_, m_, ...) \
93 COMMS_FIELD_ALIAS_TYPE(P_, m_) :: COMMS_EXPAND(COMMS_FIELD_ALIAS_TYPE_1(Field_, __VA_ARGS__)) // using Field_ as next prefix on purpose
94#define COMMS_FIELD_ALIAS_TYPE_3(P_, m_, ...) \
95 COMMS_FIELD_ALIAS_TYPE(P_, m_) :: COMMS_EXPAND(COMMS_FIELD_ALIAS_TYPE_2(Field_, __VA_ARGS__)) // using Field_ as next prefix on purpose
96#define COMMS_FIELD_ALIAS_TYPE_4(P_, m_, ...) \
97 COMMS_FIELD_ALIAS_TYPE(P_, m_) :: COMMS_EXPAND(COMMS_FIELD_ALIAS_TYPE_3(Field_, __VA_ARGS__)) // using Field_ as next prefix on purpose
98#define COMMS_FIELD_ALIAS_TYPE_5(P_, m_, ...) \
99 COMMS_FIELD_ALIAS_TYPE(P_, m_) :: COMMS_EXPAND(COMMS_FIELD_ALIAS_TYPE_4(Field_, __VA_ARGS__)) // using Field_ as next prefix on purpose
100#define COMMS_FIELD_ALIAS_TYPE_6(P_, m_, ...) \
101 COMMS_FIELD_ALIAS_TYPE(P_, m_) :: COMMS_EXPAND(COMMS_FIELD_ALIAS_TYPE_5(Field_, __VA_ARGS__)) // using Field_ as next prefix on purpose
102#define COMMS_FIELD_ALIAS_TYPE_7(P_, m_, ...) \
103 COMMS_FIELD_ALIAS_TYPE(P_, m_) :: COMMS_EXPAND(COMMS_FIELD_ALIAS_TYPE_6(Field_, __VA_ARGS__)) // using Field_ as next prefix on purpose
104#define COMMS_FIELD_ALIAS_TYPE_8(P_, m_, ...) \
105 COMMS_FIELD_ALIAS_TYPE(P_, m_) :: COMMS_EXPAND(COMMS_FIELD_ALIAS_TYPE_7(Field_, __VA_ARGS__)) // using Field_ as next prefix on purpose
106
107#define COMMS_ALIAS_ALL_TYPES_(N, P_, ...) COMMS_EXPAND(COMMS_FIELD_ALIAS_TYPE_ ## N(P_, __VA_ARGS__))
108#define COMMS_ALIAS_ALL_TYPES(N, P_, ...) COMMS_EXPAND(COMMS_ALIAS_ALL_TYPES_(N, P_, __VA_ARGS__))
109#define COMMS_DO_ALIAS_ALL_TYPES(P_, ...) \
110 COMMS_EXPAND(COMMS_ALIAS_ALL_TYPES(COMMS_NUM_ARGS(__VA_ARGS__), P_, __VA_ARGS__))
111
112#define COMMS_FIELD_ALIAS_TYPE_PREFIX_1
113#define COMMS_FIELD_ALIAS_TYPE_PREFIX_2 typename
114#define COMMS_FIELD_ALIAS_TYPE_PREFIX_3 typename
115#define COMMS_FIELD_ALIAS_TYPE_PREFIX_4 typename
116#define COMMS_FIELD_ALIAS_TYPE_PREFIX_5 typename
117#define COMMS_FIELD_ALIAS_TYPE_PREFIX_6 typename
118#define COMMS_FIELD_ALIAS_TYPE_PREFIX_7 typename
119#define COMMS_FIELD_ALIAS_TYPE_PREFIX_8 typename
120
121#define COMMS_FIELD_ALIAS_TYPE_PREFIX_(N) COMMS_FIELD_ALIAS_TYPE_PREFIX_ ## N
122#define COMMS_FIELD_ALIAS_TYPE_PREFIX(N) COMMS_EXPAND(COMMS_FIELD_ALIAS_TYPE_PREFIX_(N))
123
124#define COMMS_DO_ALIAS_TYPEDEF(P_, n_, ...) \
125 using COMMS_CONCATENATE(P_, n_) = \
126 COMMS_EXPAND(COMMS_FIELD_ALIAS_TYPE_PREFIX(COMMS_NUM_ARGS(__VA_ARGS__))) COMMS_EXPAND(COMMS_DO_ALIAS_ALL_TYPES(P_, __VA_ARGS__));
Contains various compiler related definitions.