OLD | NEW |
---|---|
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_CALLBACK_INTERNAL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_CALLBACK_INTERNAL_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_CALLBACK_INTERNAL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_CALLBACK_INTERNAL_H_ |
7 | 7 |
8 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" | 8 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
9 #include "mojo/public/cpp/bindings/lib/template_util.h" | |
9 | 10 |
10 namespace mojo { | 11 namespace mojo { |
12 class String; | |
13 | |
11 namespace internal { | 14 namespace internal { |
12 | 15 |
13 template <typename T, bool is_object_type = TypeTraits<T>::kIsObject> | 16 template <typename T, bool is_move_only = IsMoveOnlyType<T>::value> |
yzshen1
2014/05/27 22:16:59
It seems we don't need the second template paramet
| |
14 struct Callback_ParamTraits {}; | 17 struct Callback_ParamTraits {}; |
15 | 18 |
16 template <typename T> | 19 template <typename T> |
17 struct Callback_ParamTraits<T, true> { | 20 struct Callback_ParamTraits<T, true> { |
18 typedef const T& ForwardType; | 21 typedef T ForwardType; |
19 static const bool kIsScopedHandle = false; | |
20 }; | 22 }; |
21 | 23 |
22 template <typename T> | 24 template <typename T> |
23 struct Callback_ParamTraits<T, false> { | 25 struct Callback_ParamTraits<T, false> { |
24 typedef T ForwardType; | 26 typedef T ForwardType; |
25 static const bool kIsScopedHandle = false; | |
26 }; | 27 }; |
27 | 28 |
28 template <typename H> | 29 template <> |
29 struct Callback_ParamTraits<ScopedHandleBase<H>, true> { | 30 struct Callback_ParamTraits<String, false> { |
30 typedef ScopedHandleBase<H> ForwardType; | 31 typedef const String& ForwardType; |
31 static const bool kIsScopedHandle = true; | |
32 }; | 32 }; |
33 | 33 |
34 template<bool B, typename T = void> | |
35 struct EnableIf {}; | |
36 | |
37 template<typename T> | |
38 struct EnableIf<true, T> { typedef T type; }; | |
39 | |
40 template <typename T> | |
41 typename EnableIf<!Callback_ParamTraits<T>::kIsScopedHandle, T>::type& | |
42 Callback_Forward(T& t) { | |
43 return t; | |
44 } | |
45 | |
46 template <typename T> | |
47 typename EnableIf<Callback_ParamTraits<T>::kIsScopedHandle, T>::type | |
48 Callback_Forward(T& t) { | |
49 return t.Pass(); | |
50 } | |
51 | |
52 } // namespace internal | 34 } // namespace internal |
53 } // namespace mojo | 35 } // namespace mojo |
54 | 36 |
55 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CALLBACK_INTERNAL_H_ | 37 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CALLBACK_INTERNAL_H_ |
OLD | NEW |