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

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

Issue 923033003: Implement unions as members of structs. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 a8f95b2300bdb8143a8adecbb89afa9345f75830..c8810a6469baad436515e8016adc0b978ea937a6 100644
--- a/mojo/public/cpp/bindings/lib/bindings_internal.h
+++ b/mojo/public/cpp/bindings/lib/bindings_internal.h
@@ -76,27 +76,76 @@ struct IsHandle {
enum { value = IsBaseOf<Handle, H>::value };
};
-template <typename T, bool move_only = IsMoveOnlyType<T>::value>
+template <typename T>
+struct IsUnionDataType {
+ template <typename U>
+ static YesType Test(const typename U::MojomUnionDataType*);
+
+ template <typename U>
+ static NoType Test(...);
+
+ static const bool value =
+ sizeof(Test<T>(0)) == sizeof(YesType) && !IsConst<T>::value;
+};
+
+template <typename T>
+struct IsWrappedUnionPtr {
+ static const bool value = false;
+};
+
+template <typename S>
+struct IsWrappedUnionPtr<StructPtr<S>> {
yzshen1 2015/02/25 21:07:00 I feel that you could use IsUnionDataType and Wrap
azani 2015/03/03 00:44:15 Done.
+ template <typename U>
+ static YesType Test(const typename U::Data_::MojomUnionDataType*);
+
+ template <typename U>
+ static NoType Test(...);
+
+ static const bool value = sizeof(Test<S>(0)) == sizeof(YesType);
+};
+
+template <typename S>
+struct IsWrappedUnionPtr<InlinedStructPtr<S>> {
yzshen1 2015/02/25 21:07:00 ditto.
azani 2015/03/03 00:44:15 Done.
+ template <typename U>
+ static YesType Test(const typename U::Data_::MojomUnionDataType*);
+
+ template <typename U>
+ static NoType Test(...);
+
+ static const bool value = sizeof(Test<S>(0)) == sizeof(YesType);
+};
+
+template <typename T,
+ bool move_only = IsMoveOnlyType<T>::value,
+ bool is_union_wrapper = IsWrappedUnionPtr<T>::value>
struct WrapperTraits;
template <typename T>
-struct WrapperTraits<T, false> {
+struct WrapperTraits<T, false, false> {
typedef T DataType;
};
template <typename H>
-struct WrapperTraits<ScopedHandleBase<H>, true> {
+struct WrapperTraits<ScopedHandleBase<H>, true, false> {
typedef H DataType;
};
template <typename S>
-struct WrapperTraits<StructPtr<S>, true> {
+struct WrapperTraits<StructPtr<S>, true, false> {
typedef typename S::Data_* DataType;
};
template <typename S>
-struct WrapperTraits<InlinedStructPtr<S>, true> {
+struct WrapperTraits<InlinedStructPtr<S>, true, false> {
typedef typename S::Data_* DataType;
};
template <typename S>
-struct WrapperTraits<S, true> {
+struct WrapperTraits<StructPtr<S>, true, true> {
+ typedef typename S::Data_ DataType;
yzshen1 2015/02/25 21:07:00 I looked at array_serialization, and didn't see wh
azani 2015/03/03 00:44:15 Done.
+};
+template <typename S>
+struct WrapperTraits<InlinedStructPtr<S>, true, true> {
+ typedef typename S::Data_ DataType;
+};
+template <typename S>
+struct WrapperTraits<S, true, false> {
typedef typename S::Data_* DataType;
};

Powered by Google App Engine
This is Rietveld 408576698