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_BINDINGS_LIB_BINDINGS_INTERNAL_H_
6 #define MOJO_PUBLIC_BINDINGS_LIB_BINDINGS_INTERNAL_H_
8 #include "mojo/public/cpp/system/core.h"
12 template <typename T> class Array_Data;
20 MOJO_COMPILE_ASSERT(sizeof(StructHeader) == 8, bad_sizeof_StructHeader);
24 uint32_t num_elements;
26 MOJO_COMPILE_ASSERT(sizeof(ArrayHeader) == 8, bad_sizeof_ArrayHeader);
33 MOJO_COMPILE_ASSERT(sizeof(StructPointer<char>) == 8, bad_sizeof_StructPointer);
40 MOJO_COMPILE_ASSERT(sizeof(ArrayPointer<char>) == 8, bad_sizeof_ArrayPointer);
44 Array_Data<char>* ptr;
46 MOJO_COMPILE_ASSERT(sizeof(StringPointer) == 8, bad_sizeof_StringPointer);
51 void ResetIfNonNull(T* ptr) {
57 T FetchAndReset(T* ptr) {
66 static const T Wrap(const typename T::Data* data) {
67 return T(typename T::Wrap(), const_cast<typename T::Data*>(data));
69 static typename T::Data* Unwrap(const T& object) {
70 return const_cast<typename T::Data*>(object.data_);
74 template <typename Data>
75 inline const typename Data::Wrapper Wrap(const Data* data) {
76 return WrapperHelper<typename Data::Wrapper>::Wrap(data);
80 inline typename T::Data* Unwrap(const T& object) {
81 return WrapperHelper<T>::Unwrap(object);
84 template <typename T> struct TypeTraits {
85 static const bool kIsObject = true;
87 template <> struct TypeTraits<bool> {
88 static const bool kIsObject = false;
90 template <> struct TypeTraits<char> {
91 static const bool kIsObject = false;
93 template <> struct TypeTraits<int8_t> {
94 static const bool kIsObject = false;
96 template <> struct TypeTraits<int16_t> {
97 static const bool kIsObject = false;
99 template <> struct TypeTraits<int32_t> {
100 static const bool kIsObject = false;
102 template <> struct TypeTraits<int64_t> {
103 static const bool kIsObject = false;
105 template <> struct TypeTraits<uint8_t> {
106 static const bool kIsObject = false;
108 template <> struct TypeTraits<uint16_t> {
109 static const bool kIsObject = false;
111 template <> struct TypeTraits<uint32_t> {
112 static const bool kIsObject = false;
114 template <> struct TypeTraits<uint64_t> {
115 static const bool kIsObject = false;
117 template <> struct TypeTraits<float> {
118 static const bool kIsObject = false;
120 template <> struct TypeTraits<double> {
121 static const bool kIsObject = false;
123 template <> struct TypeTraits<Handle> {
124 static const bool kIsObject = false;
126 template <> struct TypeTraits<DataPipeConsumerHandle> {
127 static const bool kIsObject = false;
129 template <> struct TypeTraits<DataPipeProducerHandle> {
130 static const bool kIsObject = false;
132 template <> struct TypeTraits<MessagePipeHandle> {
133 static const bool kIsObject = false;
136 template <typename T> class ObjectTraits {};
138 } // namespace internal
141 #endif // MOJO_PUBLIC_BINDINGS_LIB_BINDINGS_INTERNAL_H_