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

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

Issue 1358353002: * Change C++ serialization/deserialization to not be move-only operations (with the except of |Ha… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: (*it).get() to it->, and other formatting 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_INTERNAL_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_INTERNAL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_INTERNAL_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_INTERNAL_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "mojo/public/cpp/bindings/array.h" 10 #include "mojo/public/cpp/bindings/array.h"
(...skipping 22 matching lines...) Expand all
33 typedef const Value& ValueConstRefType; 33 typedef const Value& ValueConstRefType;
34 typedef ValueConstRefType ValueForwardType; 34 typedef ValueConstRefType ValueForwardType;
35 35
36 static inline void InitializeFrom( 36 static inline void InitializeFrom(
37 std::map<KeyStorageType, ValueStorageType>* m, 37 std::map<KeyStorageType, ValueStorageType>* m,
38 mojo::Array<Key> keys, 38 mojo::Array<Key> keys,
39 mojo::Array<Value> values) { 39 mojo::Array<Value> values) {
40 for (size_t i = 0; i < keys.size(); ++i) 40 for (size_t i = 0; i < keys.size(); ++i)
41 Insert(m, keys[i], values[i]); 41 Insert(m, keys[i], values[i]);
42 } 42 }
43 static inline void Decompose(std::map<KeyStorageType, ValueStorageType>* m,
44 mojo::Array<Key>* keys,
45 mojo::Array<Value>* values) {
46 keys->resize(m->size());
47 values->resize(m->size());
48 int i = 0;
49 for (typename std::map<KeyStorageType, ValueStorageType>::iterator
50 it = m->begin();
51 it != m->end();
52 ++it, ++i) {
53 (*keys)[i] = it->first;
54 (*values)[i] = it->second;
55 }
56 }
57 static inline void Finalize(std::map<KeyStorageType, ValueStorageType>* m) {} 43 static inline void Finalize(std::map<KeyStorageType, ValueStorageType>* m) {}
58 static inline ValueRefType at(std::map<KeyStorageType, ValueStorageType>* m, 44 static inline ValueRefType at(std::map<KeyStorageType, ValueStorageType>* m,
59 KeyForwardType key) { 45 KeyForwardType key) {
60 // We don't have C++11 library support yet, so we have to emulate the crash 46 // We don't have C++11 library support yet, so we have to emulate the crash
61 // on a non-existent key. 47 // on a non-existent key.
62 auto it = m->find(key); 48 auto it = m->find(key);
63 MOJO_CHECK(it != m->end()); 49 MOJO_CHECK(it != m->end());
64 return it->second; 50 return it->second;
65 } 51 }
66 static inline ValueConstRefType at( 52 static inline ValueConstRefType at(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 typedef const Value& ValueConstRefType; 112 typedef const Value& ValueConstRefType;
127 typedef Value ValueForwardType; 113 typedef Value ValueForwardType;
128 114
129 static inline void InitializeFrom( 115 static inline void InitializeFrom(
130 std::map<KeyStorageType, ValueStorageType>* m, 116 std::map<KeyStorageType, ValueStorageType>* m,
131 mojo::Array<Key> keys, 117 mojo::Array<Key> keys,
132 mojo::Array<Value> values) { 118 mojo::Array<Value> values) {
133 for (size_t i = 0; i < keys.size(); ++i) 119 for (size_t i = 0; i < keys.size(); ++i)
134 Insert(m, keys[i], values[i]); 120 Insert(m, keys[i], values[i]);
135 } 121 }
136 static inline void Decompose(std::map<KeyStorageType, ValueStorageType>* m,
137 mojo::Array<Key>* keys,
138 mojo::Array<Value>* values) {
139 keys->resize(m->size());
140 values->resize(m->size());
141 int i = 0;
142 for (typename std::map<KeyStorageType, ValueStorageType>::iterator
143 it = m->begin();
144 it != m->end();
145 ++it, ++i) {
146 (*keys)[i] = it->first;
147 (*values)[i] = GetValue(it).Pass();
148 }
149 }
150 static inline void Finalize(std::map<KeyStorageType, ValueStorageType>* m) { 122 static inline void Finalize(std::map<KeyStorageType, ValueStorageType>* m) {
151 for (auto& pair : *m) 123 for (auto& pair : *m)
152 reinterpret_cast<Value*>(pair.second.buf)->~Value(); 124 reinterpret_cast<Value*>(pair.second.buf)->~Value();
153 } 125 }
154 static inline ValueRefType at(std::map<KeyStorageType, ValueStorageType>* m, 126 static inline ValueRefType at(std::map<KeyStorageType, ValueStorageType>* m,
155 KeyForwardType key) { 127 KeyForwardType key) {
156 // We don't have C++11 library support yet, so we have to emulate the crash 128 // We don't have C++11 library support yet, so we have to emulate the crash
157 // on a non-existent key. 129 // on a non-existent key.
158 auto it = m->find(key); 130 auto it = m->find(key);
159 MOJO_CHECK(it != m->end()); 131 MOJO_CHECK(it != m->end());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 dst->clear(); 183 dst->clear();
212 for (auto it = src.begin(); it != src.end(); ++it) 184 for (auto it = src.begin(); it != src.end(); ++it)
213 new ((*dst)[it->first].buf) Value(GetValue(it).Clone()); 185 new ((*dst)[it->first].buf) Value(GetValue(it).Clone());
214 } 186 }
215 }; 187 };
216 188
217 } // namespace internal 189 } // namespace internal
218 } // namespace mojo 190 } // namespace mojo
219 191
220 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_INTERNAL_H_ 192 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_INTERNAL_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/control_message_proxy.cc ('k') | mojo/public/cpp/bindings/lib/map_serialization.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698