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

Unified Diff: mojo/public/cpp/bindings/lib/bindings_internal.h

Issue 294833002: Mojo: more idiomatic C++ bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix windows bustage Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698