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

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

Issue 2165233003: Mojo C++ bindings: provide data view for all object types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <functional> 10 #include <functional>
11 11
12 #include "base/template_util.h" 12 #include "base/template_util.h"
13 #include "mojo/public/cpp/bindings/interface_id.h" 13 #include "mojo/public/cpp/bindings/interface_id.h"
14 #include "mojo/public/cpp/bindings/lib/template_util.h" 14 #include "mojo/public/cpp/bindings/lib/template_util.h"
15 #include "mojo/public/cpp/system/core.h" 15 #include "mojo/public/cpp/system/core.h"
16 16
17 namespace mojo { 17 namespace mojo {
18 18
19 template <typename T> 19 template <typename T>
20 class Array; 20 class Array;
21 21
22 template <typename T> 22 template <typename T>
23 class ArrayDataView;
24
25 template <typename T>
23 class AssociatedInterfacePtrInfo; 26 class AssociatedInterfacePtrInfo;
24 27
25 template <typename T> 28 template <typename T>
26 class AssociatedInterfaceRequest; 29 class AssociatedInterfaceRequest;
27 30
28 template <typename T> 31 template <typename T>
29 class InterfacePtr; 32 class InterfacePtr;
30 33
31 template <typename T> 34 template <typename T>
32 class InterfaceRequest; 35 class InterfaceRequest;
33 36
34 template <typename K, typename V> 37 template <typename K, typename V>
35 class Map; 38 class Map;
36 39
40 template <typename K, typename V>
41 class MapDataView;
42
43 class NativeStruct;
44
45 class NativeStructDataView;
46
37 class String; 47 class String;
38 48
49 class StringDataView;
50
39 template <typename T> 51 template <typename T>
40 class StructPtr; 52 class StructPtr;
41 53
42 template <typename T> 54 template <typename T>
43 class InlinedStructPtr; 55 class InlinedStructPtr;
44 56
57 using NativeStructPtr = StructPtr<NativeStruct>;
58
45 namespace internal { 59 namespace internal {
46 60
47 // Please note that this is a different value than |mojo::kInvalidHandleValue|, 61 // Please note that this is a different value than |mojo::kInvalidHandleValue|,
48 // which is the "decoded" invalid handle. 62 // which is the "decoded" invalid handle.
49 const uint32_t kEncodedInvalidHandleValue = static_cast<uint32_t>(-1); 63 const uint32_t kEncodedInvalidHandleValue = static_cast<uint32_t>(-1);
50 64
51 // A serialized union always takes 16 bytes: 65 // A serialized union always takes 16 bytes:
52 // 4-byte size + 4-byte tag + 8-byte payload. 66 // 4-byte size + 4-byte tag + 8-byte payload.
53 const uint32_t kUnionDataSize = 16; 67 const uint32_t kUnionDataSize = 16;
54 68
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 template <typename T> 335 template <typename T>
322 struct EnumHashImpl { 336 struct EnumHashImpl {
323 static_assert(std::is_enum<T>::value, "Incorrect hash function."); 337 static_assert(std::is_enum<T>::value, "Incorrect hash function.");
324 338
325 size_t operator()(T input) const { 339 size_t operator()(T input) const {
326 using UnderlyingType = typename base::underlying_type<T>::type; 340 using UnderlyingType = typename base::underlying_type<T>::type;
327 return std::hash<UnderlyingType>()(static_cast<UnderlyingType>(input)); 341 return std::hash<UnderlyingType>()(static_cast<UnderlyingType>(input));
328 } 342 }
329 }; 343 };
330 344
345 template <typename T>
346 struct DataViewTraits {
347 using MojomType = T;
348 };
349
350 template <typename T>
351 struct DataViewTraits<ArrayDataView<T>> {
352 using MojomType = Array<typename DataViewTraits<T>::MojomType>;
353 };
354
355 template <typename K, typename V>
356 struct DataViewTraits<MapDataView<K, V>> {
357 using MojomType = Map<typename DataViewTraits<K>::MojomType,
358 typename DataViewTraits<V>::MojomType>;
359 };
360
361 template <>
362 struct DataViewTraits<StringDataView> {
363 using MojomType = String;
364 };
365
366 template <>
367 struct DataViewTraits<NativeStructDataView> {
368 using MojomType = NativeStructPtr;
369 };
370
331 } // namespace internal 371 } // namespace internal
332 } // namespace mojo 372 } // namespace mojo
333 373
334 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ 374 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/array_data_view.h ('k') | mojo/public/cpp/bindings/lib/string_serialization.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698