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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_BINDINGS_INTERNAL_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_
7 7
8 #include "mojo/public/cpp/bindings/lib/template_util.h" 8 #include "mojo/public/cpp/bindings/lib/template_util.h"
9 #include "mojo/public/cpp/bindings/struct_ptr.h" 9 #include "mojo/public/cpp/bindings/struct_ptr.h"
10 #include "mojo/public/cpp/system/core.h" 10 #include "mojo/public/cpp/system/core.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 T temp = *ptr; 69 T temp = *ptr;
70 *ptr = T(); 70 *ptr = T();
71 return temp; 71 return temp;
72 } 72 }
73 73
74 template <typename H> 74 template <typename H>
75 struct IsHandle { 75 struct IsHandle {
76 enum { value = IsBaseOf<Handle, H>::value }; 76 enum { value = IsBaseOf<Handle, H>::value };
77 }; 77 };
78 78
79 template <typename T, bool move_only = IsMoveOnlyType<T>::value> 79 template <typename T>
80 struct IsUnionDataType {
81 template <typename U>
82 static YesType Test(const typename U::MojomUnionDataType*);
83
84 template <typename U>
85 static NoType Test(...);
86
87 static const bool value =
88 sizeof(Test<T>(0)) == sizeof(YesType) && !IsConst<T>::value;
89 };
90
91 template <typename T>
92 struct IsWrappedUnionPtr {
93 static const bool value = false;
94 };
95
96 template <typename S>
97 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.
98 template <typename U>
99 static YesType Test(const typename U::Data_::MojomUnionDataType*);
100
101 template <typename U>
102 static NoType Test(...);
103
104 static const bool value = sizeof(Test<S>(0)) == sizeof(YesType);
105 };
106
107 template <typename S>
108 struct IsWrappedUnionPtr<InlinedStructPtr<S>> {
yzshen1 2015/02/25 21:07:00 ditto.
azani 2015/03/03 00:44:15 Done.
109 template <typename U>
110 static YesType Test(const typename U::Data_::MojomUnionDataType*);
111
112 template <typename U>
113 static NoType Test(...);
114
115 static const bool value = sizeof(Test<S>(0)) == sizeof(YesType);
116 };
117
118 template <typename T,
119 bool move_only = IsMoveOnlyType<T>::value,
120 bool is_union_wrapper = IsWrappedUnionPtr<T>::value>
80 struct WrapperTraits; 121 struct WrapperTraits;
81 122
82 template <typename T> 123 template <typename T>
83 struct WrapperTraits<T, false> { 124 struct WrapperTraits<T, false, false> {
84 typedef T DataType; 125 typedef T DataType;
85 }; 126 };
86 template <typename H> 127 template <typename H>
87 struct WrapperTraits<ScopedHandleBase<H>, true> { 128 struct WrapperTraits<ScopedHandleBase<H>, true, false> {
88 typedef H DataType; 129 typedef H DataType;
89 }; 130 };
90 template <typename S> 131 template <typename S>
91 struct WrapperTraits<StructPtr<S>, true> { 132 struct WrapperTraits<StructPtr<S>, true, false> {
92 typedef typename S::Data_* DataType; 133 typedef typename S::Data_* DataType;
93 }; 134 };
94 template <typename S> 135 template <typename S>
95 struct WrapperTraits<InlinedStructPtr<S>, true> { 136 struct WrapperTraits<InlinedStructPtr<S>, true, false> {
96 typedef typename S::Data_* DataType; 137 typedef typename S::Data_* DataType;
97 }; 138 };
98 template <typename S> 139 template <typename S>
99 struct WrapperTraits<S, true> { 140 struct WrapperTraits<StructPtr<S>, true, true> {
141 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.
142 };
143 template <typename S>
144 struct WrapperTraits<InlinedStructPtr<S>, true, true> {
145 typedef typename S::Data_ DataType;
146 };
147 template <typename S>
148 struct WrapperTraits<S, true, false> {
100 typedef typename S::Data_* DataType; 149 typedef typename S::Data_* DataType;
101 }; 150 };
102 151
103 template <typename T, typename Enable = void> 152 template <typename T, typename Enable = void>
104 struct ValueTraits { 153 struct ValueTraits {
105 static bool Equals(const T& a, const T& b) { return a == b; } 154 static bool Equals(const T& a, const T& b) { return a == b; }
106 }; 155 };
107 156
108 template <typename T> 157 template <typename T>
109 struct ValueTraits< 158 struct ValueTraits<
(...skipping 10 matching lines...) Expand all
120 static bool Equals(const ScopedHandleBase<T>& a, 169 static bool Equals(const ScopedHandleBase<T>& a,
121 const ScopedHandleBase<T>& b) { 170 const ScopedHandleBase<T>& b) {
122 return a.get().value() == b.get().value(); 171 return a.get().value() == b.get().value();
123 } 172 }
124 }; 173 };
125 174
126 } // namespace internal 175 } // namespace internal
127 } // namespace mojo 176 } // namespace mojo
128 177
129 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ 178 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698