AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Utils.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
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  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef ACSDKMANUFACTORY_INTERNAL_UTILS_H_
17 #define ACSDKMANUFACTORY_INTERNAL_UTILS_H_
18 
19 #include <tuple>
20 #include <type_traits>
21 
26 
27 namespace alexaClientSDK {
28 namespace acsdkManufactory {
29 namespace internal {
30 
48 struct Fold {
49  template <typename...>
50  struct Apply;
51 
52  template <typename Operation, typename Result0>
54  using type = Result0;
55  };
56 
57  template <typename Operation, typename Result0, typename A1>
59  using type = typename Operation::template Apply<Result0, A1>::type;
60  };
61 
62  template <typename Operation, typename Result0, typename A1, typename A2>
64  using Result1 = typename Operation::template Apply<Result0, A1>::type;
65  using type = typename Operation::template Apply<Result1, A2>::type;
66  };
67 
68  template <typename Operation, typename Result0, typename A1, typename A2, typename A3>
70  using Result1 = typename Operation::template Apply<Result0, A1>::type;
71  using Result2 = typename Operation::template Apply<Result1, A2>::type;
72  using type = typename Operation::template Apply<Result2, A3>::type;
73  };
74 
75  template <typename Operation, typename Result0, typename A1, typename A2, typename A3, typename A4, typename... An>
76  struct Apply<Operation, Result0, A1, A2, A3, A4, An...> {
77  using Result1 = typename Operation::template Apply<Result0, A1>::type;
78  using Result2 = typename Operation::template Apply<Result1, A2>::type;
79  using Result3 = typename Operation::template Apply<Result2, A3>::type;
80  using Result4 = typename Operation::template Apply<Result3, A4>::type;
81  using type = typename Apply<Operation, Result4, An...>::type;
82  };
83 
84  template <
85  typename Operation,
86  typename Result0,
87  typename A1,
88  typename A2,
89  typename A3,
90  typename A4,
91  typename A5,
92  typename A6,
93  typename A7,
94  typename... An>
95  struct Apply<Operation, Result0, A1, A2, A3, A4, A5, A6, A7, An...> {
96  using Result1 = typename Operation::template Apply<Result0, A1>::type;
97  using Result2 = typename Operation::template Apply<Result1, A2>::type;
98  using Result3 = typename Operation::template Apply<Result2, A3>::type;
99  using Result4 = typename Operation::template Apply<Result3, A4>::type;
100  using Result5 = typename Operation::template Apply<Result4, A5>::type;
101  using Result6 = typename Operation::template Apply<Result5, A6>::type;
102  using Result7 = typename Operation::template Apply<Result6, A7>::type;
103  using type = typename Apply<Operation, Result7, An...>::type;
104  };
105 
106  template <
107  typename Operation,
108  typename Result0,
109  typename A1,
110  typename A2,
111  typename A3,
112  typename A4,
113  typename A5,
114  typename A6,
115  typename A7,
116  typename A8,
117  typename A9,
118  typename A10,
119  typename A11,
120  typename A12,
121  typename... An>
122  struct Apply<Operation, Result0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, An...> {
123  using Result1 = typename Operation::template Apply<Result0, A1>::type;
124  using Result2 = typename Operation::template Apply<Result1, A2>::type;
125  using Result3 = typename Operation::template Apply<Result2, A3>::type;
126  using Result4 = typename Operation::template Apply<Result3, A4>::type;
127  using Result5 = typename Operation::template Apply<Result4, A5>::type;
128  using Result6 = typename Operation::template Apply<Result5, A6>::type;
129  using Result7 = typename Operation::template Apply<Result6, A7>::type;
130  using Result8 = typename Operation::template Apply<Result7, A8>::type;
131  using Result9 = typename Operation::template Apply<Result8, A9>::type;
132  using Result10 = typename Operation::template Apply<Result9, A10>::type;
133  using Result11 = typename Operation::template Apply<Result10, A11>::type;
134  using Result12 = typename Operation::template Apply<Result11, A12>::type;
135  using type = typename Apply<Operation, Result12, An...>::type;
136  };
137 };
138 
154  template <typename...>
155  struct Apply;
156 
157  template <typename Operation, typename Result0, typename... Types>
158  struct Apply<Operation, Result0, std::tuple<Types...>> {
159  using type = typename Fold::Apply<Operation, Result0, Types...>::type;
160  };
161 };
162 
171 template <typename...>
173 
174 template <typename Type, typename... ContainedTypes>
175 struct ContainsType<std::tuple<ContainedTypes...>, Type> {
176  template <typename InType>
177  struct IsFalse {
178  constexpr static const bool value = false;
179  };
180 
181  template <bool... InTypes>
182  struct BoolValues;
183 
184  using FalseValues = BoolValues<IsFalse<ContainedTypes>::value...>;
185  using SameValues = BoolValues<std::is_same<Type, ContainedTypes>::value...>;
186  constexpr static const bool value = !std::is_same<FalseValues, SameValues>::value;
187 };
188 
198 template <typename...>
200 
201 template <typename Container, typename... Types>
202 struct ContainsTypes<Container, Types...> {
203  template <typename InType>
204  struct IsTrue {
205  constexpr static const bool value = true;
206  };
207 
208  template <bool... InTypes>
209  struct BoolValues;
210 
211  using TrueValues = BoolValues<IsTrue<Types>::value...>;
212  using ContainedValues = BoolValues<ContainsType<Container, Types>::value...>;
213  constexpr static const bool value = std::is_same<TrueValues, ContainedValues>::value;
214 };
215 
225 template <typename...>
227 
228 template <typename... ContainerTypes, typename... TupleTypes>
229 struct ContainsTupleTypes<std::tuple<ContainerTypes...>, std::tuple<TupleTypes...>>
230  : ContainsTypes<std::tuple<ContainerTypes...>, TupleTypes...> {};
231 
239 template <typename...>
240 struct IsImport;
241 
242 template <typename Type>
244 
245 template <typename Type>
247 
248 template <typename Type>
249 struct IsImport<Type> : std::false_type {};
250 
258 template <typename...>
260 
261 template <typename Type>
263 
264 template <typename Type>
266 
274 template <typename... Types>
276  template <typename InType>
277  struct IsFalse {
278  constexpr static const bool value = false;
279  };
280 
281  template <bool... InTypes>
282  struct BoolValues;
283 
286  constexpr static const bool value = !std::is_same<FalseValues, IsImportValues>::value;
287 };
288 
298 template <typename... Types>
299 struct DedupTypes {
300  struct DedupOperation {
301  template <typename...>
302  struct Apply;
303 
304  template <typename... ResultTypes, typename Type>
305  struct Apply<std::tuple<ResultTypes...>, Type> {
306  using type = typename std::conditional<
307  ContainsType<std::tuple<ResultTypes...>, Type>::value,
308  std::tuple<ResultTypes...>,
309  std::tuple<ResultTypes..., Type>>::type;
310  };
311  };
312 
314 };
315 
326 template <typename...>
327 struct RemoveTypes;
328 
329 template <typename... Types, typename... Unwanted>
330 struct RemoveTypes<std::tuple<Types...>, std::tuple<Unwanted...>> {
331  struct RemoveTypesOperation {
332  template <typename...>
333  struct Apply;
334 
335  template <typename... ResultTypes, typename Type>
336  struct Apply<std::tuple<ResultTypes...>, Type> {
337  using type = typename std::conditional<
338  ContainsType<std::tuple<Unwanted...>, Type>::value,
339  std::tuple<ResultTypes...>,
340  std::tuple<ResultTypes..., Type>>::type;
341  };
342  };
343 
345 };
346 
357 template <typename... Types>
359  using UniqueParameters = typename DedupTypes<Types...>::type;
360 
362  template <typename...>
363  struct Apply;
364 
365  template <typename... ResultTypes, typename Type>
366  struct Apply<std::tuple<ResultTypes...>, Type> {
367  using type = typename std::
368  conditional<IsImport<Type>::value, std::tuple<ResultTypes...>, std::tuple<ResultTypes..., Type>>::type;
369  };
370  };
371 
373 
375  template <typename...>
376  struct Apply;
377 
378  template <typename... ResultTypes, typename Type>
379  struct Apply<std::tuple<ResultTypes...>, MakeOptional<Type>> {
380  using type = std::tuple<ResultTypes..., Type>;
381  };
382 
383  template <typename... ResultTypes, typename Type>
384  struct Apply<std::tuple<ResultTypes...>, Type> {
385  using type = std::tuple<ResultTypes...>;
386  };
387  };
388 
389  using MakeOptionalImports =
391 
393  template <typename...>
394  struct Apply;
395 
396  template <typename... ResultTypes, typename Type>
397  struct Apply<std::tuple<ResultTypes...>, OptionalImport<Type>> {
398  using type = std::tuple<ResultTypes..., Type>;
399  };
400 
401  template <typename... ResultTypes, typename Type>
402  struct Apply<std::tuple<ResultTypes...>, MakeOptional<Type>> {
403  using type = std::tuple<ResultTypes..., Type>;
404  };
405 
406  template <typename... ResultTypes, typename Type>
407  struct Apply<std::tuple<ResultTypes...>, Type> {
408  using type = std::tuple<ResultTypes...>;
409  };
410  };
411 
415  using OptionalImports =
417 
419  template <typename...>
420  struct Apply;
421 
422  template <typename... ResultTypes, typename Type>
423  struct Apply<std::tuple<ResultTypes...>, Import<Type>> {
424  using type = std::tuple<ResultTypes..., Type>;
425  };
426 
427  template <typename... ResultTypes, typename Type>
428  struct Apply<std::tuple<ResultTypes...>, Type> {
429  using type = std::tuple<ResultTypes...>;
430  };
431  };
432 
438 
440 
445 
452 
453  struct type {
454  using exports = Exports;
457  };
458 };
459 
467 template <typename... Types>
469 
470 template <typename Type, typename... Types>
471 struct DefaultValues<OptionalImport<Type>, Types...> {
477  static inline void apply(internal::CookBook& cookBook) {
478  cookBook.addInstance(Type());
480  }
481 };
482 
483 template <typename Type, typename... Types>
484 struct DefaultValues<Type, Types...> {
490  static inline void apply(internal::CookBook& cookBook) {
492  }
493 };
494 
495 template <>
496 struct DefaultValues<> {
502  static inline void apply(internal::CookBook& cookBook) {
503  }
504 };
505 
518 template <typename... Types>
520 
521 template <>
523  void operator()() {
524  }
525 };
526 
527 template <>
528 struct PrintMissingExport<std::tuple<>> : PrintMissingExport<> {};
529 
542 template <typename... Types>
544 
545 template <>
547  void operator()() {
548  }
549 };
550 
551 template <>
552 struct PrintMissingImport<std::tuple<>> : PrintMissingImport<> {};
553 
554 } // namespace internal
555 } // namespace acsdkManufactory
556 } // namespace alexaClientSDK
557 
558 #endif // ACSDKMANUFACTORY_INTERNAL_UTILS_H_
typename Operation::template Apply< Result5, A6 >::type Result6
Definition: Utils.h:101
typename Operation::template Apply< Result2, A3 >::type Result3
Definition: Utils.h:79
BoolValues< std::is_same< Type, ContainedTypes >::value... > SameValues
Definition: Utils.h:185
GTEST_API_ bool IsTrue(bool condition)
typename DedupTypes< Types... >::type UniqueParameters
Definition: Utils.h:359
typename std::conditional< ContainsType< std::tuple< Unwanted... >, Type >::value, std::tuple< ResultTypes... >, std::tuple< ResultTypes..., Type > >::type type
Definition: Utils.h:340
typename Operation::template Apply< Result3, A4 >::type Result4
Definition: Utils.h:80
typename Operation::template Apply< Result2, A3 >::type type
Definition: Utils.h:72
Definition: CapabilityConfiguration.h:190
typename RemoveTypes< typename RemoveTypes< OptionalImports, Exports >::type, UnsatisfiedRequiredImports >::type UnsatisfiedOptionalImports
Definition: Utils.h:451
typename RemoveTypes< DeclaredRequiredImports, MakeOptionalImports >::type RequiredImports
Definition: Utils.h:439
BoolValues< IsTrue< Types >::value... > TrueValues
Definition: Utils.h:211
typename Fold::Apply< DedupOperation, std::tuple<>, Types... >::type type
Definition: Utils.h:313
Matcher< T > An()
Definition: gmock-matchers.h:3736
static void apply(internal::CookBook &cookBook)
Definition: Utils.h:490
bool_constant< true > true_type
Definition: gtest-port.h:2210
typename Operation::template Apply< Result0, A1 >::type Result1
Definition: Utils.h:77
BoolValues< IsFalse< ContainedTypes >::value... > FalseValues
Definition: Utils.h:184
typename std::conditional< IsImport< Type >::value, std::tuple< ResultTypes... >, std::tuple< ResultTypes..., Type > >::type type
Definition: Utils.h:368
bool_constant< false > false_type
Definition: gtest-port.h:2209
typename FoldTupleTypes::Apply< GetExportsOperation, std::tuple<>, UniqueParameters >::type Exports
Definition: Utils.h:372
UnsatisfiedRequiredImports required
Definition: Utils.h:455
typename FoldTupleTypes::Apply< GetRequiredImportsOperation, std::tuple<>, UniqueParameters >::type DeclaredRequiredImports
Definition: Utils.h:437
typename RemoveTypes< RequiredImports, Exports >::type UnsatisfiedRequiredImports
Definition: Utils.h:444
typename FoldTupleTypes::Apply< GetOptionalImportsOperation, std::tuple<>, UniqueParameters >::type OptionalImports
Definition: Utils.h:416
typename std::conditional< ContainsType< std::tuple< ResultTypes... >, Type >::value, std::tuple< ResultTypes... >, std::tuple< ResultTypes..., Type > >::type type
Definition: Utils.h:309
typename Operation::template Apply< Result0, A1 >::type Result1
Definition: Utils.h:96
typename Operation::template Apply< Result0, A1 >::type Result1
Definition: Utils.h:64
static void apply(internal::CookBook &cookBook)
Definition: Utils.h:502
typename Operation::template Apply< Result1, A2 >::type Result2
Definition: Utils.h:97
typename Operation::template Apply< Result6, A7 >::type Result7
Definition: Utils.h:102
typename Operation::template Apply< Result4, A5 >::type Result5
Definition: Utils.h:100
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
typename Operation::template Apply< Result2, A3 >::type Result3
Definition: Utils.h:98
typename Operation::template Apply< Result0, A1 >::type type
Definition: Utils.h:59
BoolValues< ContainsType< Container, Types >::value... > ContainedValues
Definition: Utils.h:212
typename Operation::template Apply< Result1, A2 >::type type
Definition: Utils.h:65
typename Operation::template Apply< Result1, A2 >::type Result2
Definition: Utils.h:78
typename Fold::Apply< RemoveTypesOperation, std::tuple<>, Types... >::type type
Definition: Utils.h:344
type
Definition: upload.py:443
static void apply(internal::CookBook &cookBook)
Definition: Utils.h:477
typename Operation::template Apply< Result1, A2 >::type Result2
Definition: Utils.h:71
typename Fold::Apply< Operation, Result0, Types... >::type type
Definition: Utils.h:159
typename Apply< Operation, Result4, An... >::type type
Definition: Utils.h:81
typename Operation::template Apply< Result3, A4 >::type Result4
Definition: Utils.h:99
typename Operation::template Apply< Result0, A1 >::type Result1
Definition: Utils.h:70
typename FoldTupleTypes::Apply< GetMakeOptionalImportsOperation, std::tuple<>, UniqueParameters >::type MakeOptionalImports
Definition: Utils.h:390
CookBook & addInstance(const Type &instance)
Definition: CookBook_imp.h:533
UnsatisfiedOptionalImports optional
Definition: Utils.h:456

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0