// 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_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ #include "mojo/public/cpp/bindings/lib/template_util.h" #include "mojo/public/cpp/bindings/struct_ptr.h" #include "mojo/public/cpp/system/core.h" namespace mojo { class String; template class Array; template class Map; namespace internal { template class Array_Data; #pragma pack(push, 1) struct StructHeader { uint32_t num_bytes; uint32_t num_fields; }; static_assert(sizeof(StructHeader) == 8, "Bad sizeof(StructHeader)"); struct ArrayHeader { uint32_t num_bytes; uint32_t num_elements; }; static_assert(sizeof(ArrayHeader) == 8, "Bad_sizeof(ArrayHeader)"); template union StructPointer { uint64_t offset; T* ptr; }; static_assert(sizeof(StructPointer) == 8, "Bad_sizeof(StructPointer)"); template union ArrayPointer { uint64_t offset; Array_Data* ptr; }; static_assert(sizeof(ArrayPointer) == 8, "Bad_sizeof(ArrayPointer)"); union StringPointer { uint64_t offset; Array_Data* ptr; }; static_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 struct IsHandle { enum { value = IsBaseOf::value }; }; template ::value> struct WrapperTraits; template struct WrapperTraits { typedef T DataType; }; template struct WrapperTraits, true> { typedef H DataType; }; template struct WrapperTraits, true> { typedef typename S::Data_* DataType; }; template struct WrapperTraits, true> { typedef typename S::Data_* DataType; }; template struct WrapperTraits { typedef typename S::Data_* DataType; }; template struct ValueTraits { static bool Equals(const T& a, const T& b) { return a == b; } }; template struct ValueTraits< T, typename EnableIf::value || IsSpecializationOf::value || IsSpecializationOf::value || IsSpecializationOf::value>::type> { static bool Equals(const T& a, const T& b) { return a.Equals(b); } }; template struct ValueTraits> { static bool Equals(const ScopedHandleBase& a, const ScopedHandleBase& b) { return a.get().value() == b.get().value(); } }; } // namespace internal } // namespace mojo #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_