blob: 1178ee466f74391d0ab823359d4b1fb08c540ff1 [file] [log] [blame]
Eric Kunze2364dcd2021-04-26 11:06:57 -07001
2// Copyright (c) 2020-2021, ARM Limited.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#ifndef _TOSA_SERIALIZATION_ATTRIBUTE_H
17#define _TOSA_SERIALIZATION_ATTRIBUTE_H
18#include "flatbuffers/idl.h"
19#include "flatbuffers/util.h"
20#include "tosa_generated.h"
21
22using std::string;
23
24namespace tosa
25{
26
27class TosaAttributeBase
28{
29public:
30 virtual ~TosaAttributeBase()
31 {}
32};
33
34class TosaNoneAttribute : public TosaAttributeBase
35{
36public:
37 TosaNoneAttribute()
38 {}
39 TosaNoneAttribute(TosaNoneAttribute* p)
40 {}
41};
42
43#define DEF_ARGS_VER0_S_STR(V) _##V = p->V()->str();
44#define DEF_ARGS_VER0_S_DEFAULT(V) _##V = p->V();
45
46#define DEF_ARGS_VER0_S_int32_t(V) DEF_ARGS_VER0_S_DEFAULT(V)
47#define DEF_ARGS_VER0_S_float(V) DEF_ARGS_VER0_S_DEFAULT(V)
48#define DEF_ARGS_VER0_S_bool(V) DEF_ARGS_VER0_S_DEFAULT(V)
49#define DEF_ARGS_VER0_S_ResizeMode(V) DEF_ARGS_VER0_S_DEFAULT(V)
James Ward485a11d2022-08-05 13:48:37 +010050#define DEF_ARGS_VER0_S_DType(V) DEF_ARGS_VER0_S_DEFAULT(V)
Eric Kunze2364dcd2021-04-26 11:06:57 -070051#define DEF_ARGS_VER0_S_string(V) DEF_ARGS_VER0_S_STR(V)
52
53#define DEF_ARGS_VER0_S(T, V) DEF_ARGS_VER0_S_##T(V)
54#define DEF_ARGS_VER0_V(T, V) _##V = std::vector<T>(p->V()->begin(), p->V()->end());
55
56#define DEF_ARGS_VER1_S(T, V) const T& V
57#define DEF_ARGS_VER1_V(T, V) const std::vector<T>& V
58#define DEF_ARGS_VER2_S(T, V) _##V = V;
59#define DEF_ARGS_VER2_V(T, V) _##V = V;
60#define DEF_ARGS_VER3_S(T, V) \
61 T V() const \
62 { \
63 return _##V; \
64 }
65#define DEF_ARGS_VER3_V(T, V) \
66 std::vector<T> V() const \
67 { \
68 return _##V; \
69 }
70#define DEF_ARGS_VER4_S(T, V) T _##V;
71#define DEF_ARGS_VER4_V(T, V) std::vector<T> _##V;
72
73// another level of preprocessor indirection to handle ", " as function's input argument
74#define DEF_ARGS_VER1_TRUE(T, F, V) DEF_ARGS_VER1_##F(T, V)
75#define DEF_ARGS_VER1_FALSE(T, F, V) , DEF_ARGS_VER1_##F(T, V)
76
77#define DEF_ARGS_VER0(FIRST, T, F, V) DEF_ARGS_VER0_##F(T, V)
78#define DEF_ARGS_VER1(FIRST, T, F, V) DEF_ARGS_VER1_##FIRST(T, F, V)
79#define DEF_ARGS_VER2(FIRST, T, F, V) DEF_ARGS_VER2_##F(T, V)
80#define DEF_ARGS_VER3(FIRST, T, F, V) DEF_ARGS_VER3_##F(T, V)
81#define DEF_ARGS_VER4(FIRST, T, F, V) DEF_ARGS_VER4_##F(T, V)
82
83#define DEF_ARGS_0(VER, ...)
84#define DEF_ARGS_1(VER, T0, F0, V0) DEF_ARGS_##VER(TRUE, T0, F0, V0)
85#define DEF_ARGS_2(VER, T0, F0, V0, T1, F1, V1) DEF_ARGS_##VER(TRUE, T0, F0, V0) DEF_ARGS_##VER(FALSE, T1, F1, V1)
86#define DEF_ARGS_3(VER, T0, F0, V0, T1, F1, V1, T2, F2, V2) \
87 DEF_ARGS_##VER(TRUE, T0, F0, V0) DEF_ARGS_##VER(FALSE, T1, F1, V1) DEF_ARGS_##VER(FALSE, T2, F2, V2)
88#define DEF_ARGS_4(VER, T0, F0, V0, T1, F1, V1, T2, F2, V2, T3, F3, V3) \
89 DEF_ARGS_##VER(TRUE, T0, F0, V0) DEF_ARGS_##VER(FALSE, T1, F1, V1) DEF_ARGS_##VER(FALSE, T2, F2, V2) \
90 DEF_ARGS_##VER(FALSE, T3, F3, V3)
91#define DEF_ARGS_5(VER, T0, F0, V0, T1, F1, V1, T2, F2, V2, T3, F3, V3, T4, F4, V4) \
92 DEF_ARGS_##VER(TRUE, T0, F0, V0) DEF_ARGS_##VER(FALSE, T1, F1, V1) DEF_ARGS_##VER(FALSE, T2, F2, V2) \
93 DEF_ARGS_##VER(FALSE, T3, F3, V3) DEF_ARGS_##VER(FALSE, T4, F4, V4)
94
95#define DEF_ARGS_6(VER, T0, F0, V0, T1, F1, V1, T2, F2, V2, T3, F3, V3, T4, F4, V4, T5, F5, V5) \
96 DEF_ARGS_##VER(TRUE, T0, F0, V0) DEF_ARGS_##VER(FALSE, T1, F1, V1) DEF_ARGS_##VER(FALSE, T2, F2, V2) \
97 DEF_ARGS_##VER(FALSE, T3, F3, V3) DEF_ARGS_##VER(FALSE, T4, F4, V4) DEF_ARGS_##VER(FALSE, T5, F5, V5)
98
99#define DEF_ARGS_7(VER, T0, F0, V0, T1, F1, V1, T2, F2, V2, T3, F3, V3, T4, F4, V4, T5, F5, V5, T6, F6, V6) \
100 DEF_ARGS_##VER(TRUE, T0, F0, V0) DEF_ARGS_##VER(FALSE, T1, F1, V1) DEF_ARGS_##VER(FALSE, T2, F2, V2) \
101 DEF_ARGS_##VER(FALSE, T3, F3, V3) DEF_ARGS_##VER(FALSE, T4, F4, V4) DEF_ARGS_##VER(FALSE, T5, F5, V5) \
102 DEF_ARGS_##VER(FALSE, T6, F6, V6)
103
104#define DEF_VER0_VAR_DECL_PTR(NAME) const NAME* p = static_cast<const NAME*>(options);
105#define DEF_VER0_VAR_0(NAME)
106#define DEF_VER0_VAR_1(NAME) DEF_VER0_VAR_DECL_PTR(NAME)
107#define DEF_VER0_VAR_2(NAME) DEF_VER0_VAR_DECL_PTR(NAME)
108#define DEF_VER0_VAR_3(NAME) DEF_VER0_VAR_DECL_PTR(NAME)
109#define DEF_VER0_VAR_4(NAME) DEF_VER0_VAR_DECL_PTR(NAME)
110#define DEF_VER0_VAR_5(NAME) DEF_VER0_VAR_DECL_PTR(NAME)
111#define DEF_VER0_VAR_6(NAME) DEF_VER0_VAR_DECL_PTR(NAME)
112#define DEF_VER0_VAR_7(NAME) DEF_VER0_VAR_DECL_PTR(NAME)
113
114#define DEF_ATTRIBUTE(NAME, NUM_ARGS, ...) \
115 class Tosa##NAME##Attribute : public TosaAttributeBase \
116 { \
117 public: \
118 Tosa##NAME##Attribute(const TosaAttributeBase* options) \
119 { \
Kevin Cheng55b363b2021-11-06 01:24:24 +0000120 const Tosa##NAME##Attribute* p = static_cast<const Tosa##NAME##Attribute*>(options); \
Eric Kunze2364dcd2021-04-26 11:06:57 -0700121 *this = *p; \
122 } \
123 Tosa##NAME##Attribute(const Tosa##NAME##Attribute* p) \
124 { \
125 *this = *p; \
126 } \
127 Tosa##NAME##Attribute(const void* options){ DEF_VER0_VAR_##NUM_ARGS(NAME##Attribute) \
128 DEF_ARGS_##NUM_ARGS(VER0, __VA_ARGS__) } Tosa##NAME \
129 ##Attribute(DEF_ARGS_##NUM_ARGS(VER1, __VA_ARGS__)) \
130 { \
131 DEF_ARGS_##NUM_ARGS(VER2, __VA_ARGS__) \
132 } \
133 virtual ~Tosa##NAME##Attribute() \
134 {} \
135 DEF_ARGS_##NUM_ARGS(VER3, __VA_ARGS__) private : DEF_ARGS_##NUM_ARGS(VER4, __VA_ARGS__) \
136 };
137
138#include "attribute.def"
139#undef DEF_ATTRIBUTE
140#undef DEF_ARGS_0
141#undef DEF_ARGS_1
142#undef DEF_ARGS_2
143#undef DEF_ARGS_3
144#undef DEF_ARGS_4
145#undef DEF_ARGS_5
146#undef DEF_ARGS_6
147#undef DEF_ARGS_7
148#undef DEF_ARGS_VER0
149#undef DEF_ARGS_VER1
150#undef DEF_ARGS_VER2
151#undef DEF_ARGS_VER3
152#undef DEF_ARGS_VER4
153#undef DEF_ARGS_VER0_S_int32_t
154#undef DEF_ARGS_VER0_S_float
155#undef DEF_ARGS_VER0_S_bool
156#undef DEF_ARGS_VER0_S_ResizeMode
James Ward485a11d2022-08-05 13:48:37 +0100157#undef DEF_ARGS_VER0_S_DType
Eric Kunze2364dcd2021-04-26 11:06:57 -0700158#undef DEF_ARGS_VER0_S_string
159#undef DEF_ARGS_VER0_S_STR
160#undef DEF_ARGS_VER0_S_DEFAULT
161#undef DEF_ARGS_VER1_TRUE
162#undef DEF_ARGS_VER1_FALSE
163#undef DEF_ARGS_VER0_S
164#undef DEF_ARGS_VER0_V
165#undef DEF_ARGS_VER1_S
166#undef DEF_ARGS_VER1_V
167#undef DEF_ARGS_VER2_S
168#undef DEF_ARGS_VER2_V
169#undef DEF_ARGS_VER3_S
170#undef DEF_ARGS_VER3_V
171#undef DEF_ARGS_VER4_S
172#undef DEF_ARGS_VER4_V
173#undef DEF_VER0_VAR_0
174#undef DEF_VER0_VAR_1
175#undef DEF_VER0_VAR_2
176#undef DEF_VER0_VAR_3
177#undef DEF_VER0_VAR_4
178#undef DEF_VER0_VAR_5
179#undef DEF_VER0_VAR_DECL_PTR
180
181} // namespace tosa
182
183#endif // _TOSA_SERIALIZATION_ATTRIBUTE_H