Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: mojo/public/cpp/bindings/lib/template_util.h

Issue 2136733002: Mojo C++ bindings: add a new mode to generator to use native STL/WTF types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@67_new
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_
7 7
8 #include <type_traits> 8 #include <type_traits>
9 9
10 namespace mojo { 10 namespace mojo {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 template <bool B, typename T, typename F> 107 template <bool B, typename T, typename F>
108 struct Conditional { 108 struct Conditional {
109 typedef T type; 109 typedef T type;
110 }; 110 };
111 111
112 template <typename T, typename F> 112 template <typename T, typename F>
113 struct Conditional<false, T, F> { 113 struct Conditional<false, T, F> {
114 typedef F type; 114 typedef F type;
115 }; 115 };
116 116
117 template <typename T>
118 struct HasCloneMethod {
119 template <typename U>
120 static char Test(decltype(&U::Clone));
121 template <typename U>
122 static int Test(...);
123 static const bool value = sizeof(Test<T>(0)) == sizeof(char);
124
125 private:
126 EnsureTypeIsComplete<T> check_t_;
127 };
128
129 template <typename T,
130 typename std::enable_if<HasCloneMethod<T>::value>::type* = nullptr>
131 T Clone(const T& input) {
132 return input.Clone();
133 };
134
135 template <typename T,
136 typename std::enable_if<!HasCloneMethod<T>::value>::type* = nullptr>
137 T Clone(const T& input) {
138 return input;
139 }
140
141 template <typename T>
142 struct HasEqualsMethod {
143 template <typename U>
144 static char Test(decltype(&U::Equals));
145 template <typename U>
146 static int Test(...);
147 static const bool value = sizeof(Test<T>(0)) == sizeof(char);
148
149 private:
150 EnsureTypeIsComplete<T> check_t_;
151 };
152
153 template <typename T,
154 typename std::enable_if<HasEqualsMethod<T>::value>::type* = nullptr>
155 bool Equals(const T& a, const T& b) {
156 return a.Equals(b);
157 };
158
159 template <typename T,
160 typename std::enable_if<!HasEqualsMethod<T>::value>::type* = nullptr>
161 bool Equals(const T& a, const T& b) {
162 return a == b;
163 }
164
165 } // namespace internal 117 } // namespace internal
166 } // namespace mojo 118 } // namespace mojo
167 119
168 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_ 120 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/serialization_forward.h ('k') | mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698