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
3 // found in the LICENSE file.
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_
8 #include "mojo/public/cpp/system/core.h"
11 template <typename S> class InterfaceHandle;
14 template <typename T> class Array_Data;
22 MOJO_COMPILE_ASSERT(sizeof(StructHeader) == 8, bad_sizeof_StructHeader);
26 uint32_t num_elements;
28 MOJO_COMPILE_ASSERT(sizeof(ArrayHeader) == 8, bad_sizeof_ArrayHeader);
35 MOJO_COMPILE_ASSERT(sizeof(StructPointer<char>) == 8, bad_sizeof_StructPointer);
42 MOJO_COMPILE_ASSERT(sizeof(ArrayPointer<char>) == 8, bad_sizeof_ArrayPointer);
46 Array_Data<char>* ptr;
48 MOJO_COMPILE_ASSERT(sizeof(StringPointer) == 8, bad_sizeof_StringPointer);
53 void ResetIfNonNull(T* ptr) {
59 T FetchAndReset(T* ptr) {
68 static const T Wrap(const typename T::Data* data) {
69 return T(typename T::Wrap(), const_cast<typename T::Data*>(data));
71 static typename T::Data* Unwrap(const T& object) {
72 return const_cast<typename T::Data*>(object.data_);
76 template <typename Data>
77 inline const typename Data::Wrapper Wrap(const Data* data) {
78 return WrapperHelper<typename Data::Wrapper>::Wrap(data);
82 inline typename T::Data* Unwrap(const T& object) {
83 return WrapperHelper<T>::Unwrap(object);
86 template <typename T> struct TypeTraits {
87 static const bool kIsHandle = false;
88 static const bool kIsObject = true;
90 template <> struct TypeTraits<bool> {
91 static const bool kIsHandle = false;
92 static const bool kIsObject = false;
94 template <> struct TypeTraits<char> {
95 static const bool kIsHandle = false;
96 static const bool kIsObject = false;
98 template <> struct TypeTraits<int8_t> {
99 static const bool kIsHandle = false;
100 static const bool kIsObject = false;
102 template <> struct TypeTraits<int16_t> {
103 static const bool kIsHandle = false;
104 static const bool kIsObject = false;
106 template <> struct TypeTraits<int32_t> {
107 static const bool kIsHandle = false;
108 static const bool kIsObject = false;
110 template <> struct TypeTraits<int64_t> {
111 static const bool kIsHandle = false;
112 static const bool kIsObject = false;
114 template <> struct TypeTraits<uint8_t> {
115 static const bool kIsHandle = false;
116 static const bool kIsObject = false;
118 template <> struct TypeTraits<uint16_t> {
119 static const bool kIsHandle = false;
120 static const bool kIsObject = false;
122 template <> struct TypeTraits<uint32_t> {
123 static const bool kIsHandle = false;
124 static const bool kIsObject = false;
126 template <> struct TypeTraits<uint64_t> {
127 static const bool kIsHandle = false;
128 static const bool kIsObject = false;
130 template <> struct TypeTraits<float> {
131 static const bool kIsHandle = false;
132 static const bool kIsObject = false;
134 template <> struct TypeTraits<double> {
135 static const bool kIsHandle = false;
136 static const bool kIsObject = false;
138 template <> struct TypeTraits<Handle> {
139 static const bool kIsHandle = true;
140 static const bool kIsObject = false;
142 template <> struct TypeTraits<DataPipeConsumerHandle> {
143 static const bool kIsHandle = true;
144 static const bool kIsObject = false;
146 template <> struct TypeTraits<DataPipeProducerHandle> {
147 static const bool kIsHandle = true;
148 static const bool kIsObject = false;
150 template <> struct TypeTraits<MessagePipeHandle> {
151 static const bool kIsHandle = true;
152 static const bool kIsObject = false;
154 template <typename S> struct TypeTraits<InterfaceHandle<S> > {
155 static const bool kIsHandle = true;
156 static const bool kIsObject = false;
159 template <typename T> class ObjectTraits {};
161 } // namespace internal
164 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_