Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: mojo/public/cpp/bindings/lib/bindings_internal.h

Issue 814543006: Move //mojo/{public, edk} underneath //third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_
7
8 #include "mojo/public/cpp/bindings/lib/template_util.h"
9 #include "mojo/public/cpp/bindings/struct_ptr.h"
10 #include "mojo/public/cpp/system/core.h"
11
12 namespace mojo {
13 class String;
14
15 template <typename T>
16 class Array;
17
18 template <typename K, typename V>
19 class Map;
20
21 namespace internal {
22 template <typename T>
23 class Array_Data;
24
25 #pragma pack(push, 1)
26
27 struct StructHeader {
28 uint32_t num_bytes;
29 uint32_t num_fields;
30 };
31 static_assert(sizeof(StructHeader) == 8, "Bad sizeof(StructHeader)");
32
33 struct ArrayHeader {
34 uint32_t num_bytes;
35 uint32_t num_elements;
36 };
37 static_assert(sizeof(ArrayHeader) == 8, "Bad_sizeof(ArrayHeader)");
38
39 template <typename T>
40 union StructPointer {
41 uint64_t offset;
42 T* ptr;
43 };
44 static_assert(sizeof(StructPointer<char>) == 8, "Bad_sizeof(StructPointer)");
45
46 template <typename T>
47 union ArrayPointer {
48 uint64_t offset;
49 Array_Data<T>* ptr;
50 };
51 static_assert(sizeof(ArrayPointer<char>) == 8, "Bad_sizeof(ArrayPointer)");
52
53 union StringPointer {
54 uint64_t offset;
55 Array_Data<char>* ptr;
56 };
57 static_assert(sizeof(StringPointer) == 8, "Bad_sizeof(StringPointer)");
58
59 #pragma pack(pop)
60
61 template <typename T>
62 void ResetIfNonNull(T* ptr) {
63 if (ptr)
64 *ptr = T();
65 }
66
67 template <typename T>
68 T FetchAndReset(T* ptr) {
69 T temp = *ptr;
70 *ptr = T();
71 return temp;
72 }
73
74 template <typename H>
75 struct IsHandle {
76 enum { value = IsBaseOf<Handle, H>::value };
77 };
78
79 template <typename T, bool move_only = IsMoveOnlyType<T>::value>
80 struct WrapperTraits;
81
82 template <typename T>
83 struct WrapperTraits<T, false> {
84 typedef T DataType;
85 };
86 template <typename H>
87 struct WrapperTraits<ScopedHandleBase<H>, true> {
88 typedef H DataType;
89 };
90 template <typename S>
91 struct WrapperTraits<StructPtr<S>, true> {
92 typedef typename S::Data_* DataType;
93 };
94 template <typename S>
95 struct WrapperTraits<InlinedStructPtr<S>, true> {
96 typedef typename S::Data_* DataType;
97 };
98 template <typename S>
99 struct WrapperTraits<S, true> {
100 typedef typename S::Data_* DataType;
101 };
102
103 template <typename T, typename Enable = void>
104 struct ValueTraits {
105 static bool Equals(const T& a, const T& b) { return a == b; }
106 };
107
108 template <typename T>
109 struct ValueTraits<
110 T,
111 typename EnableIf<IsSpecializationOf<Array, T>::value ||
112 IsSpecializationOf<Map, T>::value ||
113 IsSpecializationOf<StructPtr, T>::value ||
114 IsSpecializationOf<InlinedStructPtr, T>::value>::type> {
115 static bool Equals(const T& a, const T& b) { return a.Equals(b); }
116 };
117
118 template <typename T>
119 struct ValueTraits<ScopedHandleBase<T>> {
120 static bool Equals(const ScopedHandleBase<T>& a,
121 const ScopedHandleBase<T>& b) {
122 return a.get().value() == b.get().value();
123 }
124 };
125
126 } // namespace internal
127 } // namespace mojo
128
129 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/array_serialization.h ('k') | mojo/public/cpp/bindings/lib/bindings_serialization.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698