• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef Arguments_h
27 #define Arguments_h
28 
29 #include "ArgumentDecoder.h"
30 #include "ArgumentEncoder.h"
31 #include <wtf/TypeTraits.h>
32 
33 namespace CoreIPC {
34 
35 struct Arguments0 {
36     typedef Arguments0 ValueType;
37 
encodeArguments038     void encode(ArgumentEncoder*) const
39     {
40     }
41 
decodeArguments042     static bool decode(ArgumentDecoder*, Arguments0&)
43     {
44         return true;
45     }
46 };
47 
In()48 inline Arguments0 In()
49 {
50     return Arguments0();
51 }
52 
Out()53 inline Arguments0 Out()
54 {
55     return Arguments0();
56 }
57 
58 template<typename T1> struct Arguments1 {
59     typedef Arguments1<typename WTF::RemoveConst<typename WTF::RemoveReference<T1>::Type>::Type> ValueType;
60 
Arguments1Arguments161     Arguments1()
62     {
63     }
64 
Arguments1Arguments165     Arguments1(T1 t1)
66         : argument1(t1)
67     {
68     }
69 
encodeArguments170     void encode(ArgumentEncoder* encoder) const
71     {
72         encoder->encode(argument1);
73     }
74 
decodeArguments175     static bool decode(ArgumentDecoder* decoder, Arguments1& result)
76     {
77         return decoder->decode(result.argument1);
78     }
79 
80     T1 argument1;
81 };
82 
In(const T1 & t1)83 template<typename T1> Arguments1<const T1&> In(const T1& t1)
84 {
85     return Arguments1<const T1&>(t1);
86 }
87 
Out(T1 & t1)88 template<typename T1> Arguments1<T1&> Out(T1& t1)
89 {
90     return Arguments1<T1&>(t1);
91 }
92 
93 template<typename T1, typename T2> struct Arguments2 : Arguments1<T1> {
94     typedef Arguments2<typename WTF::RemoveConst<typename WTF::RemoveReference<T1>::Type>::Type,
95                        typename WTF::RemoveConst<typename WTF::RemoveReference<T2>::Type>::Type> ValueType;
96 
Arguments2Arguments297     Arguments2()
98     {
99     }
100 
Arguments2Arguments2101     Arguments2(T1 t1, T2 t2)
102         : Arguments1<T1>(t1)
103         , argument2(t2)
104     {
105     }
106 
encodeArguments2107     void encode(ArgumentEncoder* encoder) const
108     {
109         Arguments1<T1>::encode(encoder);
110         encoder->encode(argument2);
111     }
112 
decodeArguments2113     static bool decode(ArgumentDecoder* decoder, Arguments2& result)
114     {
115         if (!Arguments1<T1>::decode(decoder, result))
116             return false;
117 
118         return decoder->decode(result.argument2);
119     }
120 
121     T2 argument2;
122 };
123 
In(const T1 & t1,const T2 & t2)124 template<typename T1, typename T2> Arguments2<const T1&, const T2&> In(const T1& t1, const T2& t2)
125 {
126     return Arguments2<const T1&, const T2&>(t1, t2);
127 }
128 
Out(T1 & t1,T2 & t2)129 template<typename T1, typename T2> Arguments2<T1&, T2&> Out(T1& t1, T2& t2)
130 {
131     return Arguments2<T1&, T2&>(t1, t2);
132 }
133 
134 template<typename T1, typename T2, typename T3> struct Arguments3 : Arguments2<T1, T2> {
135     typedef Arguments3<typename WTF::RemoveConst<typename WTF::RemoveReference<T1>::Type>::Type,
136                        typename WTF::RemoveConst<typename WTF::RemoveReference<T2>::Type>::Type,
137                        typename WTF::RemoveConst<typename WTF::RemoveReference<T3>::Type>::Type> ValueType;
138 
Arguments3Arguments3139     Arguments3()
140     {
141     }
142 
Arguments3Arguments3143     Arguments3(T1 t1, T2 t2, T3 t3)
144         : Arguments2<T1, T2>(t1, t2)
145         , argument3(t3)
146     {
147     }
148 
encodeArguments3149     void encode(ArgumentEncoder* encoder) const
150     {
151         Arguments2<T1, T2>::encode(encoder);
152         encoder->encode(argument3);
153     }
154 
decodeArguments3155     static bool decode(ArgumentDecoder* decoder, Arguments3& result)
156     {
157         if (!Arguments2<T1, T2>::decode(decoder, result))
158             return false;
159 
160         return decoder->decode(result.argument3);
161     }
162 
163     T3 argument3;
164 };
165 
In(const T1 & t1,const T2 & t2,const T3 & t3)166 template<typename T1, typename T2, typename T3> Arguments3<const T1&, const T2&, const T3&> In(const T1& t1, const T2& t2, const T3 &t3)
167 {
168     return Arguments3<const T1&, const T2&, const T3&>(t1, t2, t3);
169 }
170 
Out(T1 & t1,T2 & t2,T3 & t3)171 template<typename T1, typename T2, typename T3> Arguments3<T1&, T2&, T3&> Out(T1& t1, T2& t2, T3& t3)
172 {
173     return Arguments3<T1&, T2&, T3&>(t1, t2, t3);
174 }
175 
176 template<typename T1, typename T2, typename T3, typename T4> struct Arguments4 : Arguments3<T1, T2, T3> {
177     typedef Arguments4<typename WTF::RemoveConst<typename WTF::RemoveReference<T1>::Type>::Type,
178                        typename WTF::RemoveConst<typename WTF::RemoveReference<T2>::Type>::Type,
179                        typename WTF::RemoveConst<typename WTF::RemoveReference<T3>::Type>::Type,
180                        typename WTF::RemoveConst<typename WTF::RemoveReference<T4>::Type>::Type> ValueType;
181 
Arguments4Arguments4182     Arguments4()
183     {
184     }
185 
Arguments4Arguments4186     Arguments4(T1 t1, T2 t2, T3 t3, T4 t4)
187         : Arguments3<T1, T2, T3>(t1, t2, t3)
188         , argument4(t4)
189     {
190     }
191 
encodeArguments4192     void encode(ArgumentEncoder* encoder) const
193     {
194         Arguments3<T1, T2, T3>::encode(encoder);
195         encoder->encode(argument4);
196     }
197 
decodeArguments4198     static bool decode(ArgumentDecoder* decoder, Arguments4& result)
199     {
200         if (!Arguments3<T1, T2, T3>::decode(decoder, result))
201             return false;
202 
203         return decoder->decode(result.argument4);
204     }
205 
206     T4 argument4;
207 };
208 
In(const T1 & t1,const T2 & t2,const T3 & t3,const T4 & t4)209 template<typename T1, typename T2, typename T3, typename T4> Arguments4<const T1&, const T2&, const T3&, const T4&> In(const T1& t1, const T2& t2, const T3 &t3, const T4& t4)
210 {
211     return Arguments4<const T1&, const T2&, const T3&, const T4&>(t1, t2, t3, t4);
212 }
213 
Out(T1 & t1,T2 & t2,T3 & t3,T4 & t4)214 template<typename T1, typename T2, typename T3, typename T4> Arguments4<T1&, T2&, T3&, T4&> Out(T1& t1, T2& t2, T3& t3, T4& t4)
215 {
216     return Arguments4<T1&, T2&, T3&, T4&>(t1, t2, t3, t4);
217 }
218 
219 template<typename T1, typename T2, typename T3, typename T4, typename T5> struct Arguments5 : Arguments4<T1, T2, T3, T4> {
220     typedef Arguments5<typename WTF::RemoveConst<typename WTF::RemoveReference<T1>::Type>::Type,
221                        typename WTF::RemoveConst<typename WTF::RemoveReference<T2>::Type>::Type,
222                        typename WTF::RemoveConst<typename WTF::RemoveReference<T3>::Type>::Type,
223                        typename WTF::RemoveConst<typename WTF::RemoveReference<T4>::Type>::Type,
224                        typename WTF::RemoveConst<typename WTF::RemoveReference<T5>::Type>::Type> ValueType;
225 
Arguments5Arguments5226     Arguments5()
227     {
228     }
229 
Arguments5Arguments5230     Arguments5(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
231         : Arguments4<T1, T2, T3, T4>(t1, t2, t3, t4)
232         , argument5(t5)
233     {
234     }
235 
encodeArguments5236     void encode(ArgumentEncoder* encoder) const
237     {
238         Arguments4<T1, T2, T3, T4>::encode(encoder);
239         encoder->encode(argument5);
240     }
241 
decodeArguments5242     static bool decode(ArgumentDecoder* decoder, Arguments5& result)
243     {
244         if (!Arguments4<T1, T2, T3, T4>::decode(decoder, result))
245             return false;
246 
247         return decoder->decode(result.argument5);
248     }
249 
250     T5 argument5;
251 };
252 
In(const T1 & t1,const T2 & t2,const T3 & t3,const T4 & t4,const T5 & t5)253 template<typename T1, typename T2, typename T3, typename T4, typename T5> Arguments5<const T1&, const T2&, const T3&, const T4&, const T5&> In(const T1& t1, const T2& t2, const T3 &t3, const T4& t4, const T5& t5)
254 {
255     return Arguments5<const T1&, const T2&, const T3&, const T4&, const T5&>(t1, t2, t3, t4, t5);
256 }
257 
Out(T1 & t1,T2 & t2,T3 & t3,T4 & t4,T5 & t5)258 template<typename T1, typename T2, typename T3, typename T4, typename T5> Arguments5<T1&, T2&, T3&, T4&, T5&> Out(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5)
259 {
260     return Arguments5<T1&, T2&, T3&, T4&, T5&>(t1, t2, t3, t4, t5);
261 }
262 
263 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> struct Arguments6 : Arguments5<T1, T2, T3, T4, T5> {
264     typedef Arguments6<typename WTF::RemoveConst<typename WTF::RemoveReference<T1>::Type>::Type,
265                        typename WTF::RemoveConst<typename WTF::RemoveReference<T2>::Type>::Type,
266                        typename WTF::RemoveConst<typename WTF::RemoveReference<T3>::Type>::Type,
267                        typename WTF::RemoveConst<typename WTF::RemoveReference<T4>::Type>::Type,
268                        typename WTF::RemoveConst<typename WTF::RemoveReference<T5>::Type>::Type,
269                        typename WTF::RemoveConst<typename WTF::RemoveReference<T6>::Type>::Type> ValueType;
270 
Arguments6Arguments6271     Arguments6()
272     {
273     }
274 
Arguments6Arguments6275     Arguments6(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
276         : Arguments5<T1, T2, T3, T4, T5>(t1, t2, t3, t4, t5)
277         , argument6(t6)
278     {
279     }
280 
encodeArguments6281     void encode(ArgumentEncoder* encoder) const
282     {
283         Arguments5<T1, T2, T3, T4, T5>::encode(encoder);
284         encoder->encode(argument6);
285     }
286 
decodeArguments6287     static bool decode(ArgumentDecoder* decoder, Arguments6& result)
288     {
289         if (!Arguments5<T1, T2, T3, T4, T5>::decode(decoder, result))
290             return false;
291 
292         return decoder->decode(result.argument6);
293     }
294 
295     T6 argument6;
296 };
297 
In(const T1 & t1,const T2 & t2,const T3 & t3,const T4 & t4,const T5 & t5,const T6 & t6)298 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> Arguments6<const T1&, const T2&, const T3&, const T4&, const T5&, const T6&> In(const T1& t1, const T2& t2, const T3 &t3, const T4& t4, const T5& t5, const T6& t6)
299 {
300     return Arguments6<const T1&, const T2&, const T3&, const T4&, const T5&, const T6&>(t1, t2, t3, t4, t5, t6);
301 }
302 
Out(T1 & t1,T2 & t2,T3 & t3,T4 & t4,T5 & t5,T6 & t6)303 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> Arguments6<T1&, T2&, T3&, T4&, T5&, T6&> Out(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6)
304 {
305     return Arguments6<T1&, T2&, T3&, T4&, T5&, T6&>(t1, t2, t3, t4, t5, t6);
306 }
307 
308 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> struct Arguments7 : Arguments6<T1, T2, T3, T4, T5, T6> {
309     typedef Arguments7<typename WTF::RemoveConst<typename WTF::RemoveReference<T1>::Type>::Type,
310                        typename WTF::RemoveConst<typename WTF::RemoveReference<T2>::Type>::Type,
311                        typename WTF::RemoveConst<typename WTF::RemoveReference<T3>::Type>::Type,
312                        typename WTF::RemoveConst<typename WTF::RemoveReference<T4>::Type>::Type,
313                        typename WTF::RemoveConst<typename WTF::RemoveReference<T5>::Type>::Type,
314                        typename WTF::RemoveConst<typename WTF::RemoveReference<T6>::Type>::Type,
315                        typename WTF::RemoveConst<typename WTF::RemoveReference<T7>::Type>::Type> ValueType;
316 
Arguments7Arguments7317     Arguments7()
318     {
319     }
320 
Arguments7Arguments7321     Arguments7(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
322         : Arguments6<T1, T2, T3, T4, T5, T6>(t1, t2, t3, t4, t5, t6)
323         , argument7(t7)
324     {
325     }
326 
encodeArguments7327     void encode(ArgumentEncoder* encoder) const
328     {
329         Arguments6<T1, T2, T3, T4, T5, T6>::encode(encoder);
330         encoder->encode(argument7);
331     }
332 
decodeArguments7333     static bool decode(ArgumentDecoder* decoder, Arguments7& result)
334     {
335         if (!Arguments6<T1, T2, T3, T4, T5, T6>::decode(decoder, result))
336             return false;
337 
338         return decoder->decode(result.argument7);
339     }
340 
341     T7 argument7;
342 };
343 
In(const T1 & t1,const T2 & t2,const T3 & t3,const T4 & t4,const T5 & t5,const T6 & t6,const T7 & t7)344 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> Arguments7<const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&> In(const T1& t1, const T2& t2, const T3 &t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7)
345 {
346     return Arguments7<const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&>(t1, t2, t3, t4, t5, t6, t7);
347 }
348 
Out(T1 & t1,T2 & t2,T3 & t3,T4 & t4,T5 & t5,T6 & t6,T7 & t7)349 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> Arguments7<T1&, T2&, T3&, T4&, T5&, T6&, T7&> Out(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7)
350 {
351     return Arguments7<T1&, T2&, T3&, T4&, T5&, T6&, T7&>(t1, t2, t3, t4, t5, t6, t7);
352 }
353 
354 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> struct Arguments8 : Arguments7<T1, T2, T3, T4, T5, T6, T7> {
355     typedef Arguments8<typename WTF::RemoveConst<typename WTF::RemoveReference<T1>::Type>::Type,
356     typename WTF::RemoveConst<typename WTF::RemoveReference<T2>::Type>::Type,
357     typename WTF::RemoveConst<typename WTF::RemoveReference<T3>::Type>::Type,
358     typename WTF::RemoveConst<typename WTF::RemoveReference<T4>::Type>::Type,
359     typename WTF::RemoveConst<typename WTF::RemoveReference<T5>::Type>::Type,
360     typename WTF::RemoveConst<typename WTF::RemoveReference<T6>::Type>::Type,
361     typename WTF::RemoveConst<typename WTF::RemoveReference<T7>::Type>::Type,
362     typename WTF::RemoveConst<typename WTF::RemoveReference<T8>::Type>::Type> ValueType;
363 
Arguments8Arguments8364     Arguments8() { }
365 
Arguments8Arguments8366     Arguments8(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
367         : Arguments7<T1, T2, T3, T4, T5, T6, T7>(t1, t2, t3, t4, t5, t6, t7)
368         , argument8(t8)
369     {
370     }
371 
encodeArguments8372     void encode(ArgumentEncoder* encoder) const
373     {
374         Arguments7<T1, T2, T3, T4, T5, T6, T7>::encode(encoder);
375         encoder->encode(argument8);
376     }
377 
decodeArguments8378     static bool decode(ArgumentDecoder* decoder, Arguments8& result)
379     {
380         if (!Arguments7<T1, T2, T3, T4, T5, T6, T7>::decode(decoder, result))
381             return false;
382 
383         return decoder->decode(result.argument8);
384     }
385 
386     T8 argument8;
387 };
388 
In(const T1 & t1,const T2 & t2,const T3 & t3,const T4 & t4,const T5 & t5,const T6 & t6,const T7 & t7,const T8 & t8)389 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> Arguments8<const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&, const T8&> In(const T1& t1, const T2& t2, const T3 &t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8)
390 {
391     return Arguments8<const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&, const T8&>(t1, t2, t3, t4, t5, t6, t7, t8);
392 }
393 
Out(T1 & t1,T2 & t2,T3 & t3,T4 & t4,T5 & t5,T6 & t6,T7 & t7,T8 & t8)394 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> Arguments8<T1&, T2&, T3&, T4&, T5&, T6&, T7&, T8&> Out(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8)
395 {
396     return Arguments8<T1&, T2&, T3&, T4&, T5&, T6&, T7&, T8&>(t1, t2, t3, t4, t5, t6, t7, t8);
397 }
398 
399 } // namespace CoreIPC
400 
401 #endif // Arguments_h
402