// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef MOJO_PUBLIC_BINDINGS_LIB_BINDINGS_INTERNAL_H_ #define MOJO_PUBLIC_BINDINGS_LIB_BINDINGS_INTERNAL_H_ #include "mojo/public/system/core_cpp.h" namespace mojo { template class TypeConverter {}; namespace internal { template class Array_Data; #pragma pack(push, 1) struct StructHeader { uint32_t num_bytes; uint32_t num_fields; }; MOJO_COMPILE_ASSERT(sizeof(StructHeader) == 8, bad_sizeof_StructHeader); struct ArrayHeader { uint32_t num_bytes; uint32_t num_elements; }; MOJO_COMPILE_ASSERT(sizeof(ArrayHeader) == 8, bad_sizeof_ArrayHeader); template union StructPointer { uint64_t offset; T* ptr; }; MOJO_COMPILE_ASSERT(sizeof(StructPointer) == 8, bad_sizeof_StructPointer); template union ArrayPointer { uint64_t offset; Array_Data* ptr; }; MOJO_COMPILE_ASSERT(sizeof(ArrayPointer) == 8, bad_sizeof_ArrayPointer); union StringPointer { uint64_t offset; Array_Data* ptr; }; MOJO_COMPILE_ASSERT(sizeof(StringPointer) == 8, bad_sizeof_StringPointer); #pragma pack(pop) template void ResetIfNonNull(T* ptr) { if (ptr) *ptr = T(); } template T FetchAndReset(T* ptr) { T temp = *ptr; *ptr = T(); return temp; } template class WrapperHelper { public: static const T Wrap(const typename T::Data* data) { return T(typename T::Wrap(), const_cast(data)); } static typename T::Data* Unwrap(const T& object) { return const_cast(object.data_); } }; template inline const typename Data::Wrapper Wrap(const Data* data) { return WrapperHelper::Wrap(data); } template inline typename T::Data* Unwrap(const T& object) { return WrapperHelper::Unwrap(object); } template struct TypeTraits { static const bool kIsObject = true; }; template <> struct TypeTraits { static const bool kIsObject = false; }; template <> struct TypeTraits { static const bool kIsObject = false; }; template <> struct TypeTraits { static const bool kIsObject = false; }; template <> struct TypeTraits { static const bool kIsObject = false; }; template <> struct TypeTraits { static const bool kIsObject = false; }; template <> struct TypeTraits { static const bool kIsObject = false; }; template <> struct TypeTraits { static const bool kIsObject = false; }; template <> struct TypeTraits { static const bool kIsObject = false; }; template <> struct TypeTraits { static const bool kIsObject = false; }; template <> struct TypeTraits { static const bool kIsObject = false; }; template <> struct TypeTraits { static const bool kIsObject = false; }; template <> struct TypeTraits { static const bool kIsObject = false; }; template <> struct TypeTraits { static const bool kIsObject = false; }; template <> struct TypeTraits { static const bool kIsObject = false; }; template class ObjectTraits {}; } // namespace internal } // namespace mojo #endif // MOJO_PUBLIC_BINDINGS_LIB_BINDINGS_INTERNAL_H_