blob: 93f7bc4d2b8ac8db48a45274073c109a94d1b614 [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)
50#define DEF_ARGS_VER0_S_string(V) DEF_ARGS_VER0_S_STR(V)
51
52#define DEF_ARGS_VER0_S(T, V) DEF_ARGS_VER0_S_##T(V)
53#define DEF_ARGS_VER0_V(T, V) _##V = std::vector<T>(p->V()->begin(), p->V()->end());
54
55#define DEF_ARGS_VER1_S(T, V) const T& V
56#define DEF_ARGS_VER1_V(T, V) const std::vector<T>& V
57#define DEF_ARGS_VER2_S(T, V) _##V = V;
58#define DEF_ARGS_VER2_V(T, V) _##V = V;
59#define DEF_ARGS_VER3_S(T, V) \
60 T V() const \
61 { \
62 return _##V; \
63 }
64#define DEF_ARGS_VER3_V(T, V) \
65 std::vector<T> V() const \
66 { \
67 return _##V; \
68 }
69#define DEF_ARGS_VER4_S(T, V) T _##V;
70#define DEF_ARGS_VER4_V(T, V) std::vector<T> _##V;
71
72// another level of preprocessor indirection to handle ", " as function's input argument
73#define DEF_ARGS_VER1_TRUE(T, F, V) DEF_ARGS_VER1_##F(T, V)
74#define DEF_ARGS_VER1_FALSE(T, F, V) , DEF_ARGS_VER1_##F(T, V)
75
76#define DEF_ARGS_VER0(FIRST, T, F, V) DEF_ARGS_VER0_##F(T, V)
77#define DEF_ARGS_VER1(FIRST, T, F, V) DEF_ARGS_VER1_##FIRST(T, F, V)
78#define DEF_ARGS_VER2(FIRST, T, F, V) DEF_ARGS_VER2_##F(T, V)
79#define DEF_ARGS_VER3(FIRST, T, F, V) DEF_ARGS_VER3_##F(T, V)
80#define DEF_ARGS_VER4(FIRST, T, F, V) DEF_ARGS_VER4_##F(T, V)
81
82#define DEF_ARGS_0(VER, ...)
83#define DEF_ARGS_1(VER, T0, F0, V0) DEF_ARGS_##VER(TRUE, T0, F0, V0)
84#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)
85#define DEF_ARGS_3(VER, T0, F0, V0, T1, F1, V1, T2, F2, V2) \
86 DEF_ARGS_##VER(TRUE, T0, F0, V0) DEF_ARGS_##VER(FALSE, T1, F1, V1) DEF_ARGS_##VER(FALSE, T2, F2, V2)
87#define DEF_ARGS_4(VER, T0, F0, V0, T1, F1, V1, T2, F2, V2, T3, F3, V3) \
88 DEF_ARGS_##VER(TRUE, T0, F0, V0) DEF_ARGS_##VER(FALSE, T1, F1, V1) DEF_ARGS_##VER(FALSE, T2, F2, V2) \
89 DEF_ARGS_##VER(FALSE, T3, F3, V3)
90#define DEF_ARGS_5(VER, T0, F0, V0, T1, F1, V1, T2, F2, V2, T3, F3, V3, T4, F4, V4) \
91 DEF_ARGS_##VER(TRUE, T0, F0, V0) DEF_ARGS_##VER(FALSE, T1, F1, V1) DEF_ARGS_##VER(FALSE, T2, F2, V2) \
92 DEF_ARGS_##VER(FALSE, T3, F3, V3) DEF_ARGS_##VER(FALSE, T4, F4, V4)
93
94#define DEF_ARGS_6(VER, T0, F0, V0, T1, F1, V1, T2, F2, V2, T3, F3, V3, T4, F4, V4, T5, F5, V5) \
95 DEF_ARGS_##VER(TRUE, T0, F0, V0) DEF_ARGS_##VER(FALSE, T1, F1, V1) DEF_ARGS_##VER(FALSE, T2, F2, V2) \
96 DEF_ARGS_##VER(FALSE, T3, F3, V3) DEF_ARGS_##VER(FALSE, T4, F4, V4) DEF_ARGS_##VER(FALSE, T5, F5, V5)
97
98#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) \
99 DEF_ARGS_##VER(TRUE, T0, F0, V0) DEF_ARGS_##VER(FALSE, T1, F1, V1) DEF_ARGS_##VER(FALSE, T2, F2, V2) \
100 DEF_ARGS_##VER(FALSE, T3, F3, V3) DEF_ARGS_##VER(FALSE, T4, F4, V4) DEF_ARGS_##VER(FALSE, T5, F5, V5) \
101 DEF_ARGS_##VER(FALSE, T6, F6, V6)
102
103#define DEF_VER0_VAR_DECL_PTR(NAME) const NAME* p = static_cast<const NAME*>(options);
104#define DEF_VER0_VAR_0(NAME)
105#define DEF_VER0_VAR_1(NAME) DEF_VER0_VAR_DECL_PTR(NAME)
106#define DEF_VER0_VAR_2(NAME) DEF_VER0_VAR_DECL_PTR(NAME)
107#define DEF_VER0_VAR_3(NAME) DEF_VER0_VAR_DECL_PTR(NAME)
108#define DEF_VER0_VAR_4(NAME) DEF_VER0_VAR_DECL_PTR(NAME)
109#define DEF_VER0_VAR_5(NAME) DEF_VER0_VAR_DECL_PTR(NAME)
110#define DEF_VER0_VAR_6(NAME) DEF_VER0_VAR_DECL_PTR(NAME)
111#define DEF_VER0_VAR_7(NAME) DEF_VER0_VAR_DECL_PTR(NAME)
112
113#define DEF_ATTRIBUTE(NAME, NUM_ARGS, ...) \
114 class Tosa##NAME##Attribute : public TosaAttributeBase \
115 { \
116 public: \
117 Tosa##NAME##Attribute(const TosaAttributeBase* options) \
118 { \
Kevin Cheng55b363b2021-11-06 01:24:24 +0000119 const Tosa##NAME##Attribute* p = static_cast<const Tosa##NAME##Attribute*>(options); \
Eric Kunze2364dcd2021-04-26 11:06:57 -0700120 *this = *p; \
121 } \
122 Tosa##NAME##Attribute(const Tosa##NAME##Attribute* p) \
123 { \
124 *this = *p; \
125 } \
126 Tosa##NAME##Attribute(const void* options){ DEF_VER0_VAR_##NUM_ARGS(NAME##Attribute) \
127 DEF_ARGS_##NUM_ARGS(VER0, __VA_ARGS__) } Tosa##NAME \
128 ##Attribute(DEF_ARGS_##NUM_ARGS(VER1, __VA_ARGS__)) \
129 { \
130 DEF_ARGS_##NUM_ARGS(VER2, __VA_ARGS__) \
131 } \
132 virtual ~Tosa##NAME##Attribute() \
133 {} \
134 DEF_ARGS_##NUM_ARGS(VER3, __VA_ARGS__) private : DEF_ARGS_##NUM_ARGS(VER4, __VA_ARGS__) \
135 };
136
137#include "attribute.def"
138#undef DEF_ATTRIBUTE
139#undef DEF_ARGS_0
140#undef DEF_ARGS_1
141#undef DEF_ARGS_2
142#undef DEF_ARGS_3
143#undef DEF_ARGS_4
144#undef DEF_ARGS_5
145#undef DEF_ARGS_6
146#undef DEF_ARGS_7
147#undef DEF_ARGS_VER0
148#undef DEF_ARGS_VER1
149#undef DEF_ARGS_VER2
150#undef DEF_ARGS_VER3
151#undef DEF_ARGS_VER4
152#undef DEF_ARGS_VER0_S_int32_t
153#undef DEF_ARGS_VER0_S_float
154#undef DEF_ARGS_VER0_S_bool
155#undef DEF_ARGS_VER0_S_ResizeMode
156#undef DEF_ARGS_VER0_S_string
157#undef DEF_ARGS_VER0_S_STR
158#undef DEF_ARGS_VER0_S_DEFAULT
159#undef DEF_ARGS_VER1_TRUE
160#undef DEF_ARGS_VER1_FALSE
161#undef DEF_ARGS_VER0_S
162#undef DEF_ARGS_VER0_V
163#undef DEF_ARGS_VER1_S
164#undef DEF_ARGS_VER1_V
165#undef DEF_ARGS_VER2_S
166#undef DEF_ARGS_VER2_V
167#undef DEF_ARGS_VER3_S
168#undef DEF_ARGS_VER3_V
169#undef DEF_ARGS_VER4_S
170#undef DEF_ARGS_VER4_V
171#undef DEF_VER0_VAR_0
172#undef DEF_VER0_VAR_1
173#undef DEF_VER0_VAR_2
174#undef DEF_VER0_VAR_3
175#undef DEF_VER0_VAR_4
176#undef DEF_VER0_VAR_5
177#undef DEF_VER0_VAR_DECL_PTR
178
179} // namespace tosa
180
181#endif // _TOSA_SERIALIZATION_ATTRIBUTE_H