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

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

Issue 1395533005: Use <type_traits> in the C++ bindings library wherever possible. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_MAP_SERIALIZATION_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_
7 7
8 #include <type_traits>
9
8 #include "mojo/public/cpp/bindings/lib/array_internal.h" 10 #include "mojo/public/cpp/bindings/lib/array_internal.h"
9 #include "mojo/public/cpp/bindings/lib/array_serialization.h" 11 #include "mojo/public/cpp/bindings/lib/array_serialization.h"
10 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" 12 #include "mojo/public/cpp/bindings/lib/bindings_internal.h"
11 #include "mojo/public/cpp/bindings/lib/iterator_util.h" 13 #include "mojo/public/cpp/bindings/lib/iterator_util.h"
12 #include "mojo/public/cpp/bindings/lib/map_data_internal.h" 14 #include "mojo/public/cpp/bindings/lib/map_data_internal.h"
13 #include "mojo/public/cpp/bindings/lib/map_internal.h" 15 #include "mojo/public/cpp/bindings/lib/map_internal.h"
14 #include "mojo/public/cpp/bindings/lib/string_serialization.h" 16 #include "mojo/public/cpp/bindings/lib/string_serialization.h"
17 #include "mojo/public/cpp/bindings/lib/template_util.h"
15 #include "mojo/public/cpp/bindings/map.h" 18 #include "mojo/public/cpp/bindings/map.h"
16 19
17 namespace mojo { 20 namespace mojo {
18 namespace internal { 21 namespace internal {
19 22
20 template <typename MapType, 23 template <typename MapType,
21 typename DataType, 24 typename DataType,
22 bool value_is_move_only_type = IsMoveOnlyType<MapType>::value, 25 bool value_is_move_only_type = IsMoveOnlyType<MapType>::value,
23 bool is_union = 26 bool is_union = IsUnionDataType<
24 IsUnionDataType<typename RemovePointer<DataType>::type>::value> 27 typename std::remove_pointer<DataType>::type>::value>
25 struct MapSerializer; 28 struct MapSerializer;
26 29
27 template <typename MapType, typename DataType> 30 template <typename MapType, typename DataType>
28 struct MapSerializer<MapType, DataType, false, false> { 31 struct MapSerializer<MapType, DataType, false, false> {
29 static size_t GetBaseArraySize(size_t count) { 32 static size_t GetBaseArraySize(size_t count) {
30 return Align(count * sizeof(DataType)); 33 return Align(count * sizeof(DataType));
31 } 34 }
32 static size_t GetItemSize(const MapType& item) { return 0; } 35 static size_t GetItemSize(const MapType& item) { return 0; }
33 }; 36 };
34 37
(...skipping 11 matching lines...) Expand all
46 return Align(count * sizeof(H)); 49 return Align(count * sizeof(H));
47 } 50 }
48 static size_t GetItemSize(const ScopedHandleBase<H>& item) { return 0; } 51 static size_t GetItemSize(const ScopedHandleBase<H>& item) { return 0; }
49 }; 52 };
50 53
51 // This template must only apply to pointer mojo entity (structs and arrays). 54 // This template must only apply to pointer mojo entity (structs and arrays).
52 // This is done by ensuring that WrapperTraits<S>::DataType is a pointer. 55 // This is done by ensuring that WrapperTraits<S>::DataType is a pointer.
53 template <typename S> 56 template <typename S>
54 struct MapSerializer< 57 struct MapSerializer<
55 S, 58 S,
56 typename EnableIf<IsPointer<typename WrapperTraits<S>::DataType>::value, 59 typename std::enable_if<
57 typename WrapperTraits<S>::DataType>::type, 60 std::is_pointer<typename WrapperTraits<S>::DataType>::value,
61 typename WrapperTraits<S>::DataType>::type,
58 true, 62 true,
59 false> { 63 false> {
60 typedef 64 typedef
61 typename RemovePointer<typename WrapperTraits<S>::DataType>::type S_Data; 65 typename std::remove_pointer<typename WrapperTraits<S>::DataType>::type
66 S_Data;
62 static size_t GetBaseArraySize(size_t count) { 67 static size_t GetBaseArraySize(size_t count) {
63 return count * sizeof(StructPointer<S_Data>); 68 return count * sizeof(StructPointer<S_Data>);
64 } 69 }
65 static size_t GetItemSize(const S& item) { 70 static size_t GetItemSize(const S& item) {
66 return GetSerializedSize_(*UnwrapConstStructPtr<S>::value(item)); 71 return GetSerializedSize_(*UnwrapConstStructPtr<S>::value(item));
67 } 72 }
68 }; 73 };
69 74
70 template <typename U, typename U_Data> 75 template <typename U, typename U_Data>
71 struct MapSerializer<U, U_Data, true, true> { 76 struct MapSerializer<U, U_Data, true, true> {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 203
199 *output = Map<MapKey, MapValue>(keys.Pass(), values.Pass()); 204 *output = Map<MapKey, MapValue>(keys.Pass(), values.Pass());
200 } else { 205 } else {
201 output->reset(); 206 output->reset();
202 } 207 }
203 } 208 }
204 209
205 } // namespace mojo 210 } // namespace mojo
206 211
207 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ 212 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/bindings_internal.h ('k') | mojo/public/cpp/bindings/lib/template_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698