Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / mojo / public / cpp / bindings / lib / bindings_internal.h
blobf12be10ab62a16923d0d0d216c84deb08d1edbe2
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/bindings/lib/template_util.h"
9 #include "mojo/public/cpp/system/core.h"
11 namespace mojo {
12 class String;
14 namespace internal {
15 template <typename T> class Array_Data;
17 #pragma pack(push, 1)
19 struct StructHeader {
20 uint32_t num_bytes;
21 uint32_t num_fields;
23 MOJO_COMPILE_ASSERT(sizeof(StructHeader) == 8, bad_sizeof_StructHeader);
25 struct ArrayHeader {
26 uint32_t num_bytes;
27 uint32_t num_elements;
29 MOJO_COMPILE_ASSERT(sizeof(ArrayHeader) == 8, bad_sizeof_ArrayHeader);
31 template <typename T>
32 union StructPointer {
33 uint64_t offset;
34 T* ptr;
36 MOJO_COMPILE_ASSERT(sizeof(StructPointer<char>) == 8, bad_sizeof_StructPointer);
38 template <typename T>
39 union ArrayPointer {
40 uint64_t offset;
41 Array_Data<T>* ptr;
43 MOJO_COMPILE_ASSERT(sizeof(ArrayPointer<char>) == 8, bad_sizeof_ArrayPointer);
45 union StringPointer {
46 uint64_t offset;
47 Array_Data<char>* ptr;
49 MOJO_COMPILE_ASSERT(sizeof(StringPointer) == 8, bad_sizeof_StringPointer);
51 #pragma pack(pop)
53 template <typename T>
54 void ResetIfNonNull(T* ptr) {
55 if (ptr)
56 *ptr = T();
59 template <typename T>
60 T FetchAndReset(T* ptr) {
61 T temp = *ptr;
62 *ptr = T();
63 return temp;
66 template <typename H> struct IsHandle {
67 enum { value = IsBaseOf<Handle, H>::value };
70 template <typename T, bool move_only = IsMoveOnlyType<T>::value>
71 struct WrapperTraits;
73 template <typename T> struct WrapperTraits<T, false> {
74 typedef T DataType;
76 template <typename H> struct WrapperTraits<ScopedHandleBase<H>, true> {
77 typedef H DataType;
79 template <typename S> struct WrapperTraits<S, true> {
80 typedef typename S::Data_* DataType;
83 } // namespace internal
84 } // namespace mojo
86 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_