Chromium Code Reviews| Index: mojo/public/cpp/bindings/lib/bindings_internal.h |
| diff --git a/mojo/public/cpp/bindings/lib/bindings_internal.h b/mojo/public/cpp/bindings/lib/bindings_internal.h |
| index 4b847e71e3c8f7c98a70db1f2fe9f9b57332bf82..9306e7f0e77a2553a004b36313f92e300ed109ef 100644 |
| --- a/mojo/public/cpp/bindings/lib/bindings_internal.h |
| +++ b/mojo/public/cpp/bindings/lib/bindings_internal.h |
| @@ -5,10 +5,11 @@ |
| #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ |
| #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ |
| +#include "mojo/public/cpp/bindings/lib/template_util.h" |
| #include "mojo/public/cpp/system/core.h" |
| namespace mojo { |
| -template <typename S> class InterfaceHandle; |
| +class String; |
| namespace internal { |
| template <typename T> class Array_Data; |
| @@ -62,102 +63,38 @@ T FetchAndReset(T* ptr) { |
| return temp; |
| } |
| -template <typename T> |
| -class WrapperHelper { |
| - public: |
| - static const T Wrap(const typename T::Data* data) { |
| - return T(typename T::Wrap(), const_cast<typename T::Data*>(data)); |
| - } |
| - static typename T::Data* Unwrap(const T& object) { |
| - return const_cast<typename T::Data*>(object.data_); |
| - } |
| -}; |
| - |
| -template <typename Data> |
| -inline const typename Data::Wrapper Wrap(const Data* data) { |
| - return WrapperHelper<typename Data::Wrapper>::Wrap(data); |
| -} |
| - |
| -template <typename T> |
| -inline typename T::Data* Unwrap(const T& object) { |
| - return WrapperHelper<T>::Unwrap(object); |
| -} |
| - |
| -template <typename T> struct TypeTraits { |
| - static const bool kIsHandle = false; |
| - static const bool kIsObject = true; |
| -}; |
| -template <> struct TypeTraits<bool> { |
| - static const bool kIsHandle = false; |
| - static const bool kIsObject = false; |
| -}; |
| -template <> struct TypeTraits<char> { |
| - static const bool kIsHandle = false; |
| - static const bool kIsObject = false; |
| +template <typename T> struct IsHandle { |
| + static const bool value = false; |
| }; |
| -template <> struct TypeTraits<int8_t> { |
| - static const bool kIsHandle = false; |
| - static const bool kIsObject = false; |
| +template <> struct IsHandle<Handle> { |
| + static const bool value = true; |
| }; |
| -template <> struct TypeTraits<int16_t> { |
| - static const bool kIsHandle = false; |
| - static const bool kIsObject = false; |
| +template <> struct IsHandle<DataPipeConsumerHandle> { |
|
yzshen1
2014/05/27 22:16:59
It might make sense to define IsHandle<> with the
|
| + static const bool value = true; |
| }; |
| -template <> struct TypeTraits<int32_t> { |
| - static const bool kIsHandle = false; |
| - static const bool kIsObject = false; |
| +template <> struct IsHandle<DataPipeProducerHandle> { |
| + static const bool value = true; |
| }; |
| -template <> struct TypeTraits<int64_t> { |
| - static const bool kIsHandle = false; |
| - static const bool kIsObject = false; |
| +template <> struct IsHandle<MessagePipeHandle> { |
| + static const bool value = true; |
| }; |
| -template <> struct TypeTraits<uint8_t> { |
| - static const bool kIsHandle = false; |
| - static const bool kIsObject = false; |
| +template <> struct IsHandle<SharedBufferHandle> { |
| + static const bool value = true; |
| }; |
| -template <> struct TypeTraits<uint16_t> { |
| - static const bool kIsHandle = false; |
| - static const bool kIsObject = false; |
| -}; |
| -template <> struct TypeTraits<uint32_t> { |
| - static const bool kIsHandle = false; |
| - static const bool kIsObject = false; |
| -}; |
| -template <> struct TypeTraits<uint64_t> { |
| - static const bool kIsHandle = false; |
| - static const bool kIsObject = false; |
| -}; |
| -template <> struct TypeTraits<float> { |
| - static const bool kIsHandle = false; |
| - static const bool kIsObject = false; |
| -}; |
| -template <> struct TypeTraits<double> { |
| - static const bool kIsHandle = false; |
| - static const bool kIsObject = false; |
| -}; |
| -template <> struct TypeTraits<Handle> { |
| - static const bool kIsHandle = true; |
| - static const bool kIsObject = false; |
| -}; |
| -template <> struct TypeTraits<DataPipeConsumerHandle> { |
| - static const bool kIsHandle = true; |
| - static const bool kIsObject = false; |
| -}; |
| -template <> struct TypeTraits<DataPipeProducerHandle> { |
| - static const bool kIsHandle = true; |
| - static const bool kIsObject = false; |
| + |
| +template <typename T, bool kMoveOnly = IsMoveOnlyType<T>::value> |
| +struct WrapperTraits; |
| + |
| +template <typename T> struct WrapperTraits<T, false> { |
| + typedef T DataType; |
| }; |
| -template <> struct TypeTraits<MessagePipeHandle> { |
| - static const bool kIsHandle = true; |
| - static const bool kIsObject = false; |
| +template <typename H> struct WrapperTraits<ScopedHandleBase<H>, true> { |
| + typedef H DataType; |
| }; |
| -template <typename S> struct TypeTraits<InterfaceHandle<S> > { |
| - static const bool kIsHandle = true; |
| - static const bool kIsObject = false; |
| +template <typename S> struct WrapperTraits<S, true> { |
| + typedef typename S::Data_* DataType; |
| }; |
| -template <typename T> class ObjectTraits {}; |
| - |
| } // namespace internal |
| } // namespace mojo |