• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef TRAITS_UTIL_H
17 #define TRAITS_UTIL_H
18 
19 #include <string>
20 #include <vector>
21 
22 namespace Updater {
23 namespace Detail {
24 template<typename T>
25 inline constexpr bool G_IS_NUM = std::is_integral_v<T> && !std::is_same_v<T, bool>;
26 
27 template<typename T>
28 inline constexpr bool G_IS_BOOL = std::is_same_v<bool, T>;
29 
30 template<typename T>
31 inline constexpr bool G_IS_STR = (std::is_same_v<char *, T> || std::is_same_v<const char *, T> ||
32                         std::is_same_v<std::string, T>);
33 
34 template<typename T>
35 inline constexpr bool G_IS_PRINTABLE = (G_IS_NUM<T> || G_IS_BOOL<T> || G_IS_STR<T>);
36 
37 template<typename T>
38 inline constexpr bool G_IS_BASE_TYPE = (G_IS_NUM<T> || G_IS_BOOL<T> || G_IS_STR<T>);
39 
40 template<typename T>
41 struct IsVector : std::false_type {};
42 
43 template<typename T>
44 struct IsVector<std::vector<T>> : std::true_type {};
45 
46 template<typename T>
47 constexpr bool G_IS_VECTOR = IsVector<T>::value;
48 
49 template<bool b, typename T>
50 using isMatch = typename std::enable_if_t<b, T>;
51 
52 template<typename T>
53 struct StandardTypeHelper {
54     static_assert(G_IS_BASE_TYPE<T>);
55     using type = std::conditional_t<G_IS_NUM<T>, int, std::conditional_t<G_IS_STR<T>, std::string, bool>>;
56 };
57 
58 template<typename T>
59 using StandardType = typename StandardTypeHelper<T>::type;
60 
61 template<std::size_t idx, typename...T>
62 inline auto &Get(T &&...t)
63 {
64     return std::get<idx>(std::forward_as_tuple(t...));
65 }
66 }
67 }
68 #endif
69