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

Side by Side Diff: mojo/public/cpp/bindings/string.h

Issue 2339413004: Allow Mojo structs as map keys (Closed)
Patch Set: Address sammc's comments and improve Blink tests Created 4 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_STRING_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_STRING_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRING_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <functional>
10 #include <string> 11 #include <string>
11 12
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "mojo/public/cpp/bindings/lib/array_internal.h" 14 #include "mojo/public/cpp/bindings/lib/array_internal.h"
15 #include "mojo/public/cpp/bindings/lib/hash_util.h"
14 #include "mojo/public/cpp/bindings/type_converter.h" 16 #include "mojo/public/cpp/bindings/type_converter.h"
15 17
16 namespace mojo { 18 namespace mojo {
17 19
18 // A UTF-8 encoded character string that can be null. Provides functions that 20 // A UTF-8 encoded character string that can be null. Provides functions that
19 // are similar to std::string, along with access to the underlying std::string 21 // are similar to std::string, along with access to the underlying std::string
20 // object. 22 // object.
21 class String { 23 class String {
22 public: 24 public:
23 // Constructs an empty string. 25 // Constructs an empty string.
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 }; 188 };
187 189
188 template <> 190 template <>
189 struct TypeConverter<String, const char*> { 191 struct TypeConverter<String, const char*> {
190 // |input| may be null, in which case a null String will be returned. 192 // |input| may be null, in which case a null String will be returned.
191 static String Convert(const char* input) { return String(input); } 193 static String Convert(const char* input) { return String(input); }
192 }; 194 };
193 195
194 } // namespace mojo 196 } // namespace mojo
195 197
198 namespace std {
199
200 template <>
201 struct hash<mojo::String> {
202 size_t operator()(const mojo::String& value) const {
203 return value.is_null() ? 0 : hash<std::string>()(value.get());
204 }
205 };
206
207 } // namespace std
208
196 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRING_H_ 209 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698