Shaka Player Embedded
names.h
Go to the documentation of this file.
1 // Copyright 2016 Google LLC
2 //
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 // https://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 #ifndef SHAKA_EMBEDDED_MAPPING_NAMES_H_
16 #define SHAKA_EMBEDDED_MAPPING_NAMES_H_
17 
18 #include <string>
19 #include <type_traits>
20 #include <vector>
21 
22 #include "shaka/optional.h"
23 #include "src/util/templates.h"
24 
25 namespace shaka {
26 
27 class BackingObject;
28 
46 template <typename T, typename = void>
47 struct TypeName {
48  static std::string name() {
49  return T::name();
50  }
51 };
52 
53 template <typename T>
54 struct TypeName<shaka::optional<T>> {
55  static std::string name() {
56  return "optional " + TypeName<T>::name();
57  }
58 };
59 
60 template <typename... Types>
61 struct TypeName<shaka::variant<Types...>> {
62  private:
63  template <size_t I, typename = void>
64  struct Helper {
65  using T = variant_alternative_t<I, shaka::variant<Types...>>;
66  static std::string name() {
67  return TypeName<T>::name() + " or " + Helper<I + 1>::name();
68  }
69  };
70  template <typename Dummy>
71  struct Helper<sizeof...(Types) - 1, Dummy> {
72  using T =
73  variant_alternative_t<sizeof...(Types) - 1, shaka::variant<Types...>>;
74  static std::string name() {
75  return TypeName<T>::name();
76  }
77  };
78 
79  public:
80  static std::string name() {
81  return Helper<0>::name();
82  }
83 };
84 
85 template <typename T>
86 struct TypeName<std::vector<T>, void> {
87  static std::string name() {
88  return "array of " + TypeName<T>::name();
89  }
90 };
91 
92 template <typename T>
93 struct TypeName<T*, void> : TypeName<T> {};
94 
95 template <typename T>
96 struct TypeName<T, util::enable_if_t<util::is_number<T>::value>> {
97  static std::string name() {
98  return "number";
99  }
100 };
101 
102 template <>
103 struct TypeName<BackingObject, void> {
104  static std::string name() {
105  return "BackingObject";
106  }
107 };
108 template <>
109 struct TypeName<bool, void> {
110  static std::string name() {
111  return "boolean";
112  }
113 };
114 template <>
115 struct TypeName<std::string, void> {
116  static std::string name() {
117  return "string";
118  }
119 };
120 
121 } // namespace shaka
122 
123 #endif // SHAKA_EMBEDDED_MAPPING_NAMES_H_
static std::string name()
Definition: names.h:116
const char * name
typename std::enable_if< B, T >::type enable_if_t
Definition: templates.h:56
static std::string name()
Definition: names.h:55
static std::string name()
Definition: names.h:110
static std::string name()
Definition: names.h:104
static std::string name()
Definition: names.h:48
typename variant_alternative< I, Variant >::type variant_alternative_t
Definition: variant.h:288