1 | // |
---|
2 | // You received this file as part of Finroc |
---|
3 | // A framework for intelligent robot control |
---|
4 | // |
---|
5 | // Copyright (C) Finroc GbR (finroc.org) |
---|
6 | // |
---|
7 | // This program is free software; you can redistribute it and/or modify |
---|
8 | // it under the terms of the GNU General Public License as published by |
---|
9 | // the Free Software Foundation; either version 2 of the License, or |
---|
10 | // (at your option) any later version. |
---|
11 | // |
---|
12 | // This program is distributed in the hope that it will be useful, |
---|
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | // GNU General Public License for more details. |
---|
16 | // |
---|
17 | // You should have received a copy of the GNU General Public License along |
---|
18 | // with this program; if not, write to the Free Software Foundation, Inc., |
---|
19 | // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
---|
20 | // |
---|
21 | //---------------------------------------------------------------------- |
---|
22 | /*!\file plugins/composite_ports/internal/type_traits.h |
---|
23 | * |
---|
24 | * \author Max Reichardt |
---|
25 | * |
---|
26 | * \date 2020-02-11 |
---|
27 | * |
---|
28 | * Type traits with respect to port types in particular |
---|
29 | * |
---|
30 | */ |
---|
31 | //---------------------------------------------------------------------- |
---|
32 | #ifndef __plugins__structure__internal__type_traits_h__ |
---|
33 | #define __plugins__structure__internal__type_traits_h__ |
---|
34 | |
---|
35 | //---------------------------------------------------------------------- |
---|
36 | // External includes (system with <>, local with "") |
---|
37 | //---------------------------------------------------------------------- |
---|
38 | #include "plugins/data_ports/tGenericPort.h" |
---|
39 | #include "plugins/data_ports/tInputPort.h" |
---|
40 | #include "plugins/data_ports/tOutputPort.h" |
---|
41 | #include "plugins/data_ports/tProxyPort.h" |
---|
42 | #include "plugins/parameters/tParameter.h" |
---|
43 | |
---|
44 | #ifdef _LIB_FINROC_PLUGINS_RPC_PORTS_PRESENT_ |
---|
45 | #include "plugins/rpc_ports/tServerPort.h" |
---|
46 | #include "plugins/rpc_ports/tClientPort.h" |
---|
47 | #include "plugins/rpc_ports/tProxyPort.h" |
---|
48 | #endif |
---|
49 | |
---|
50 | //---------------------------------------------------------------------- |
---|
51 | // Internal includes with "" |
---|
52 | //---------------------------------------------------------------------- |
---|
53 | |
---|
54 | //---------------------------------------------------------------------- |
---|
55 | // Namespace declaration |
---|
56 | //---------------------------------------------------------------------- |
---|
57 | namespace finroc |
---|
58 | { |
---|
59 | |
---|
60 | //---------------------------------------------------------------------- |
---|
61 | // Forward declarations / typedefs / enums |
---|
62 | //---------------------------------------------------------------------- |
---|
63 | |
---|
64 | namespace rpc_ports |
---|
65 | { |
---|
66 | class tRPCInterface; |
---|
67 | template <typename T> |
---|
68 | class tServerPort; |
---|
69 | template <typename T> |
---|
70 | class tClientPort; |
---|
71 | template <typename T, bool SERVER_PORT> |
---|
72 | class tProxyPort; |
---|
73 | } |
---|
74 | |
---|
75 | namespace structure |
---|
76 | { |
---|
77 | class tConveniencePortBase; |
---|
78 | template <typename TPort> |
---|
79 | class tBasicConveniencePort; |
---|
80 | } |
---|
81 | |
---|
82 | namespace composite_ports |
---|
83 | { |
---|
84 | namespace internal |
---|
85 | { |
---|
86 | |
---|
87 | enum tPortTypeRelation |
---|
88 | { |
---|
89 | ePTR_INPUT, |
---|
90 | ePTR_OUTPUT, |
---|
91 | ePTR_PARAMETER, |
---|
92 | ePTR_COUNTER_PART, |
---|
93 | ePTR_COUNTER_PART_PARAMETER_IF_INPUT, |
---|
94 | ePTR_SERVER_IF_INPUT, |
---|
95 | ePTR_CLIENT_IF_INPUT, |
---|
96 | ePTR_DIMENSION |
---|
97 | }; |
---|
98 | |
---|
99 | template <int Tprimary_interface_relations, template <typename> class TPortType, typename T, bool Trpc, bool Tdirection_specified> |
---|
100 | class tGenericPortType; |
---|
101 | |
---|
102 | //---------------------------------------------------------------------- |
---|
103 | // Function declarations |
---|
104 | //---------------------------------------------------------------------- |
---|
105 | |
---|
106 | class tTestType : public rrlib::serialization::tMemoryBuffer |
---|
107 | #ifdef _LIB_FINROC_PLUGINS_RPC_PORTS_PRESENT_ |
---|
108 | , public rpc_ports::tRPCInterface |
---|
109 | #endif |
---|
110 | {}; |
---|
111 | |
---|
112 | template <template <typename> class TPortType> |
---|
113 | struct IsRPCPort |
---|
114 | { |
---|
115 | enum { value = (!std::is_base_of<data_ports::tPort<tTestType>, TPortType<tTestType>>::value) && (!std::is_base_of<parameters::tParameter<tTestType>, TPortType<tTestType>>::value) }; |
---|
116 | }; |
---|
117 | |
---|
118 | template <template <typename> class TPortType> |
---|
119 | struct IsConveniencePort |
---|
120 | { |
---|
121 | enum { value = std::is_base_of<structure::tConveniencePortBase, TPortType<tTestType>>::value }; |
---|
122 | }; |
---|
123 | |
---|
124 | template <template <typename> class TPortType, bool Trpc = IsRPCPort<TPortType>::value> |
---|
125 | struct IsOutputPort |
---|
126 | { |
---|
127 | enum { value = std::is_base_of<data_ports::tOutputPort<double>, TPortType<double>>::value || |
---|
128 | std::is_base_of<data_ports::tProxyPort<double, true>, TPortType<double>>::value |
---|
129 | }; |
---|
130 | }; |
---|
131 | template <template <typename> class TPortType> |
---|
132 | struct IsOutputPort<TPortType, true> |
---|
133 | { |
---|
134 | enum { value = std::is_base_of<rpc_ports::tClientPort<tTestType>, TPortType<tTestType>>::value || |
---|
135 | std::is_base_of<rpc_ports::tProxyPort<tTestType, false>, TPortType<tTestType>>::value |
---|
136 | }; |
---|
137 | }; |
---|
138 | |
---|
139 | template <template <typename> class TPortType, bool Trpc = IsRPCPort<TPortType>::value> |
---|
140 | struct IsInputPort |
---|
141 | { |
---|
142 | enum { value = std::is_base_of<data_ports::tInputPort<double>, TPortType<double>>::value || |
---|
143 | std::is_base_of<data_ports::tProxyPort<double, false>, TPortType<double>>::value || |
---|
144 | std::is_base_of<parameters::tParameter<double>, TPortType<double>>::value |
---|
145 | }; |
---|
146 | }; |
---|
147 | template <template <typename> class TPortType> |
---|
148 | struct IsInputPort<TPortType, true> |
---|
149 | { |
---|
150 | enum { value = std::is_base_of<rpc_ports::tServerPort<tTestType>, TPortType<tTestType>>::value || |
---|
151 | std::is_base_of<rpc_ports::tProxyPort<tTestType, true>, TPortType<tTestType>>::value |
---|
152 | }; |
---|
153 | }; |
---|
154 | |
---|
155 | |
---|
156 | template <template <typename> class TPort, bool Trpc = IsRPCPort<TPort>::value> |
---|
157 | struct MakeInputPortImplementation |
---|
158 | { |
---|
159 | template <typename T> |
---|
160 | using base_type = typename std::conditional < std::is_base_of<data_ports::tProxyPort<tTestType, false>, TPort<tTestType>>::value || std::is_base_of<data_ports::tProxyPort<tTestType, true>, TPort<tTestType>>::value, data_ports::tProxyPort<T, false>, data_ports::tInputPort<T >>::type; |
---|
161 | |
---|
162 | template <typename T> |
---|
163 | using type = typename std::conditional<IsConveniencePort<TPort>::value, structure::tBasicConveniencePort<base_type<T>>, base_type<T>>::type; |
---|
164 | }; |
---|
165 | template <template <typename> class TPort> |
---|
166 | struct MakeInputPortImplementation<TPort, true> |
---|
167 | { |
---|
168 | template <typename T> |
---|
169 | using base_type = typename std::conditional < std::is_base_of<rpc_ports::tServerPort<tTestType>, TPort<tTestType>>::value || std::is_base_of<rpc_ports::tClientPort<tTestType>, TPort<tTestType>>::value, rpc_ports::tServerPort<T>, rpc_ports::tProxyPort<T, true >>::type; |
---|
170 | |
---|
171 | template <typename T> |
---|
172 | using type = typename std::conditional<IsConveniencePort<TPort>::value, structure::tBasicConveniencePort<base_type<T>>, base_type<T>>::type; |
---|
173 | }; |
---|
174 | template <template <typename> class TPort> |
---|
175 | using MakeInputPort = MakeInputPortImplementation<TPort>; |
---|
176 | |
---|
177 | template <template <typename> class TPort, bool Trpc = IsRPCPort<TPort>::value> |
---|
178 | struct MakeOutputPortImplementation |
---|
179 | { |
---|
180 | template <typename T> |
---|
181 | using base_type = typename std::conditional < std::is_base_of<data_ports::tProxyPort<tTestType, false>, TPort<tTestType>>::value || std::is_base_of<data_ports::tProxyPort<tTestType, true>, TPort<tTestType>>::value, data_ports::tProxyPort<T, true>, data_ports::tOutputPort<T >>::type; |
---|
182 | |
---|
183 | template <typename T> |
---|
184 | using type = typename std::conditional<IsConveniencePort<TPort>::value, structure::tBasicConveniencePort<base_type<T>>, base_type<T>>::type; |
---|
185 | }; |
---|
186 | template <template <typename> class TPort> |
---|
187 | struct MakeOutputPortImplementation<TPort, true> |
---|
188 | { |
---|
189 | template <typename T> |
---|
190 | using base_type = typename std::conditional < std::is_base_of<rpc_ports::tClientPort<tTestType>, TPort<tTestType>>::value || std::is_base_of<rpc_ports::tClientPort<tTestType>, TPort<tTestType>>::value, rpc_ports::tClientPort<T>, rpc_ports::tProxyPort<T, false >>::type; |
---|
191 | |
---|
192 | template <typename T> |
---|
193 | using type = typename std::conditional<IsConveniencePort<TPort>::value, structure::tBasicConveniencePort<base_type<T>>, base_type<T>>::type; |
---|
194 | }; |
---|
195 | template <template <typename> class TPort> |
---|
196 | using MakeOutputPort = MakeOutputPortImplementation<TPort>; |
---|
197 | |
---|
198 | template <template <typename> class TPort> |
---|
199 | struct MakeParameter |
---|
200 | { |
---|
201 | template <typename T> |
---|
202 | using type = typename std::conditional<IsConveniencePort<TPort>::value, structure::tBasicConveniencePort<parameters::tParameter<T>>, parameters::tParameter<T>>::type; |
---|
203 | }; |
---|
204 | |
---|
205 | template <template <typename> class TPort, bool Tpossibly_parameter, bool Tinput = IsInputPort<TPort>::value, bool Toutput = IsOutputPort<TPort>::value> |
---|
206 | struct MakeCounterDirectionPort |
---|
207 | { |
---|
208 | template <typename T> |
---|
209 | using type = data_ports::tPort<T>; |
---|
210 | }; |
---|
211 | template <template <typename> class TPort, bool Tpossibly_parameter> |
---|
212 | struct MakeCounterDirectionPort<TPort, Tpossibly_parameter, true, false> |
---|
213 | { |
---|
214 | template <typename T> |
---|
215 | using type = typename MakeOutputPort<TPort>::template type<T>; |
---|
216 | }; |
---|
217 | template <template <typename> class TPort> |
---|
218 | struct MakeCounterDirectionPort<TPort, false, false, true> |
---|
219 | { |
---|
220 | template <typename T> |
---|
221 | using type = typename MakeInputPort<TPort>::template type<T>; |
---|
222 | }; |
---|
223 | template <template <typename> class TPort> |
---|
224 | struct MakeCounterDirectionPort<TPort, true, false, true> : MakeParameter<TPort> |
---|
225 | { |
---|
226 | }; |
---|
227 | template <template <typename> class TPort> |
---|
228 | using MakeCounterPart = MakeCounterDirectionPort<TPort, false>; |
---|
229 | template <template <typename> class TPort> |
---|
230 | using MakeCounterPartParameterIfInput = MakeCounterDirectionPort<TPort, true>; |
---|
231 | |
---|
232 | template <template <typename> class TPort, bool TServer, bool TClient> |
---|
233 | struct MakeRPCPort |
---|
234 | { |
---|
235 | template <typename T> |
---|
236 | using type = core::tPortWrapperBase; |
---|
237 | }; |
---|
238 | template <template <typename> class TPort> |
---|
239 | struct MakeRPCPort<TPort, false, true> |
---|
240 | { |
---|
241 | template <typename T> |
---|
242 | using base_type = typename std::conditional < std::is_base_of<data_ports::tProxyPort<tTestType, false>, TPort<tTestType>>::value || std::is_base_of<data_ports::tProxyPort<tTestType, true>, TPort<tTestType>>::value, rpc_ports::tProxyPort<T, false>, rpc_ports::tClientPort<T >>::type; |
---|
243 | |
---|
244 | template <typename T> |
---|
245 | using type = typename std::conditional<IsConveniencePort<TPort>::value, structure::tBasicConveniencePort<base_type<T>>, base_type<T>>::type; |
---|
246 | }; |
---|
247 | template <template <typename> class TPort> |
---|
248 | struct MakeRPCPort<TPort, true, false> |
---|
249 | { |
---|
250 | template <typename T> |
---|
251 | using base_type = typename std::conditional < std::is_base_of<data_ports::tProxyPort<tTestType, false>, TPort<tTestType>>::value || std::is_base_of<data_ports::tProxyPort<tTestType, true>, TPort<tTestType>>::value, rpc_ports::tProxyPort<T, true>, rpc_ports::tServerPort<T >>::type; |
---|
252 | |
---|
253 | template <typename T> |
---|
254 | using type = typename std::conditional<IsConveniencePort<TPort>::value, structure::tBasicConveniencePort<base_type<T>>, base_type<T>>::type; |
---|
255 | }; |
---|
256 | |
---|
257 | template <template <typename> class TPort> |
---|
258 | using MakeServerIfInput = MakeRPCPort<TPort, IsInputPort<TPort>::value, IsOutputPort<TPort>::value>; |
---|
259 | template <template <typename> class TPort> |
---|
260 | using MakeClientIfInput = MakeRPCPort<TPort, IsOutputPort<TPort>::value, IsInputPort<TPort>::value>; |
---|
261 | |
---|
262 | |
---|
263 | template <typename TPort> |
---|
264 | struct GetRelationId |
---|
265 | { |
---|
266 | enum { value = 0 }; |
---|
267 | }; |
---|
268 | template <int Tprimary_interface_relations, template <typename> class TPortType, typename T, bool Trpc, bool Tdirection_specified> |
---|
269 | struct GetRelationId<tGenericPortType<Tprimary_interface_relations, TPortType, T, Trpc, Tdirection_specified>> |
---|
270 | { |
---|
271 | enum { value = Tprimary_interface_relations }; |
---|
272 | }; |
---|
273 | |
---|
274 | template <int Trelation_id, template <typename> class TReferencePort, template <template <typename> class> class TBasePort> |
---|
275 | struct PrimaryPortRelation |
---|
276 | { |
---|
277 | template <typename T> |
---|
278 | using base_port = typename TBasePort<TReferencePort>::template type<T>; |
---|
279 | |
---|
280 | template <typename T> |
---|
281 | using type = tGenericPortType < GetRelationId<TReferencePort<double>>::value * 256 + Trelation_id, base_port, T, IsRPCPort<base_port>::value, IsInputPort<base_port>::value || IsOutputPort<base_port>::value >; |
---|
282 | }; |
---|
283 | |
---|
284 | |
---|
285 | //---------------------------------------------------------------------- |
---|
286 | // End of namespace declaration |
---|
287 | //---------------------------------------------------------------------- |
---|
288 | } |
---|
289 | } |
---|
290 | } |
---|
291 | |
---|
292 | |
---|
293 | #endif |
---|