| 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 #include <type_traits> |
| 9 | 10 |
| 10 #include "mojo/public/cpp/bindings/lib/map_internal.h" | 11 #include "mojo/public/cpp/bindings/lib/map_internal.h" |
| 11 #include "mojo/public/cpp/bindings/lib/template_util.h" | 12 #include "mojo/public/cpp/bindings/lib/template_util.h" |
| 12 | 13 |
| 13 namespace mojo { | 14 namespace mojo { |
| 14 | 15 |
| 15 // A move-only map that can handle move-only values. Map has the following | 16 // A move-only map that can handle move-only values. Map has the following |
| 16 // characteristics: | 17 // characteristics: |
| 17 // - The map itself can be null, and this is distinct from empty. | 18 // - The map itself can be null, and this is distinct from empty. |
| 18 // - Keys must not be move-only. | 19 // - Keys must not be move-only. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 172 } |
| 172 | 173 |
| 173 private: | 174 private: |
| 174 // A Map Iterator, templated for mutable and const iterator behaviour. | 175 // A Map Iterator, templated for mutable and const iterator behaviour. |
| 175 // If |IsConstIterator| is true, the iterator behaves like a const-iterator. | 176 // If |IsConstIterator| is true, the iterator behaves like a const-iterator. |
| 176 // | 177 // |
| 177 // TODO(vardhan): Make this adhere to the BidirectionalIterator concept. | 178 // TODO(vardhan): Make this adhere to the BidirectionalIterator concept. |
| 178 enum class IteratorMutability { kConst, kMutable }; | 179 enum class IteratorMutability { kConst, kMutable }; |
| 179 template <IteratorMutability MutabilityType = IteratorMutability::kMutable> | 180 template <IteratorMutability MutabilityType = IteratorMutability::kMutable> |
| 180 class InternalIterator { | 181 class InternalIterator { |
| 181 using InternalIteratorType = typename internal::Conditional< | 182 using InternalIteratorType = typename std::conditional< |
| 182 MutabilityType == IteratorMutability::kConst, | 183 MutabilityType == IteratorMutability::kConst, |
| 183 typename std::map<KeyStorageType, ValueStorageType>::const_iterator, | 184 typename std::map<KeyStorageType, ValueStorageType>::const_iterator, |
| 184 typename std::map<KeyStorageType, ValueStorageType>::iterator>::type; | 185 typename std::map<KeyStorageType, ValueStorageType>::iterator>::type; |
| 185 | 186 |
| 186 using ReturnValueType = | 187 using ReturnValueType = |
| 187 typename internal::Conditional<MutabilityType == | 188 typename std::conditional<MutabilityType == IteratorMutability::kConst, |
| 188 IteratorMutability::kConst, | 189 ValueConstRefType, |
| 189 ValueConstRefType, | 190 ValueRefType>::type; |
| 190 ValueRefType>::type; | |
| 191 | 191 |
| 192 public: | 192 public: |
| 193 InternalIterator() : it_() {} | 193 InternalIterator() : it_() {} |
| 194 InternalIterator(InternalIteratorType it) : it_(it) {} | 194 InternalIterator(InternalIteratorType it) : it_(it) {} |
| 195 | 195 |
| 196 // The key is always a const reference, but the value is conditional on | 196 // The key is always a const reference, but the value is conditional on |
| 197 // whether this is a const iterator or not. | 197 // whether this is a const iterator or not. |
| 198 KeyConstRefType GetKey() { return Traits::GetKey(it_); } | 198 KeyConstRefType GetKey() { return Traits::GetKey(it_); } |
| 199 ReturnValueType GetValue() { return Traits::GetValue(it_); } | 199 ReturnValueType GetValue() { return Traits::GetValue(it_); } |
| 200 | 200 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 TypeConverter<STLValue, MojoValue>::Convert(it.GetValue()))); | 302 TypeConverter<STLValue, MojoValue>::Convert(it.GetValue()))); |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 return result; | 305 return result; |
| 306 } | 306 } |
| 307 }; | 307 }; |
| 308 | 308 |
| 309 } // namespace mojo | 309 } // namespace mojo |
| 310 | 310 |
| 311 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ | 311 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ |
| OLD | NEW |