| OLD | NEW |
| 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_MAP_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "mojo/public/cpp/bindings/lib/map_internal.h" | 10 #include "mojo/public/cpp/bindings/lib/map_internal.h" |
| 11 | 11 |
| 12 namespace mojo { | 12 namespace mojo { |
| 13 | 13 |
| 14 template <typename Key, typename Value> | 14 template <typename Key, typename Value> |
| 15 class Map { | 15 class Map { |
| 16 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(Map, RValue) | 16 MOJO_MOVE_ONLY_TYPE(Map) |
| 17 |
| 17 public: | 18 public: |
| 18 // Map keys can not be move only classes. | 19 // Map keys can not be move only classes. |
| 19 static_assert(!internal::IsMoveOnlyType<Key>::value, | 20 static_assert(!internal::IsMoveOnlyType<Key>::value, |
| 20 "Map keys can not be move only types."); | 21 "Map keys can not be move only types."); |
| 21 | 22 |
| 22 typedef internal::MapTraits<Key, | 23 typedef internal::MapTraits<Key, |
| 23 Value, | 24 Value, |
| 24 internal::IsMoveOnlyType<Value>::value> Traits; | 25 internal::IsMoveOnlyType<Value>::value> Traits; |
| 25 typedef typename Traits::KeyStorageType KeyStorageType; | 26 typedef typename Traits::KeyStorageType KeyStorageType; |
| 26 typedef typename Traits::KeyRefType KeyRefType; | 27 typedef typename Traits::KeyRefType KeyRefType; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 38 | 39 |
| 39 Map() : is_null_(true) {} | 40 Map() : is_null_(true) {} |
| 40 | 41 |
| 41 Map(mojo::Array<Key> keys, mojo::Array<Value> values) : is_null_(false) { | 42 Map(mojo::Array<Key> keys, mojo::Array<Value> values) : is_null_(false) { |
| 42 MOJO_DCHECK(keys.size() == values.size()); | 43 MOJO_DCHECK(keys.size() == values.size()); |
| 43 Traits::InitializeFrom(&map_, keys.Pass(), values.Pass()); | 44 Traits::InitializeFrom(&map_, keys.Pass(), values.Pass()); |
| 44 } | 45 } |
| 45 | 46 |
| 46 ~Map() { Traits::Finalize(&map_); } | 47 ~Map() { Traits::Finalize(&map_); } |
| 47 | 48 |
| 48 Map(RValue other) : is_null_(true) { Take(other.object); } | 49 Map(Map&& other) : is_null_(true) { Take(&other); } |
| 49 Map& operator=(RValue other) { | 50 Map& operator=(Map&& other) { |
| 50 Take(other.object); | 51 Take(&other); |
| 51 return *this; | 52 return *this; |
| 52 } | 53 } |
| 53 | 54 |
| 54 template <typename U> | 55 template <typename U> |
| 55 static Map From(const U& other) { | 56 static Map From(const U& other) { |
| 56 return TypeConverter<Map, U>::Convert(other); | 57 return TypeConverter<Map, U>::Convert(other); |
| 57 } | 58 } |
| 58 | 59 |
| 59 template <typename U> | 60 template <typename U> |
| 60 U To() const { | 61 U To() const { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 TypeConverter<STLValue, MojoValue>::Convert(it.GetValue()))); | 222 TypeConverter<STLValue, MojoValue>::Convert(it.GetValue()))); |
| 222 } | 223 } |
| 223 } | 224 } |
| 224 return result; | 225 return result; |
| 225 } | 226 } |
| 226 }; | 227 }; |
| 227 | 228 |
| 228 } // namespace mojo | 229 } // namespace mojo |
| 229 | 230 |
| 230 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ | 231 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ |
| OLD | NEW |