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

Side by Side Diff: remoting/protocol/name_value_map.h

Issue 810133003: replace NULL->nullptr in src/remoting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Helper functions that allow to map enum values to strings. 5 // Helper functions that allow to map enum values to strings.
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace remoting { 11 namespace remoting {
12 namespace protocol { 12 namespace protocol {
13 13
14 template <typename T> 14 template <typename T>
15 struct NameMapElement { 15 struct NameMapElement {
16 const T value; 16 const T value;
17 const char* const name; 17 const char* const name;
18 }; 18 };
19 19
20 template <typename T, size_t N> 20 template <typename T, size_t N>
21 const char* ValueToName(const NameMapElement<T> (&map)[N], T value) { 21 const char* ValueToName(const NameMapElement<T> (&map)[N], T value) {
22 for (size_t i = 0; i < N; ++i) { 22 for (size_t i = 0; i < N; ++i) {
23 if (map[i].value == value) 23 if (map[i].value == value)
24 return map[i].name; 24 return map[i].name;
25 } 25 }
26 NOTREACHED(); 26 NOTREACHED();
27 return NULL; 27 return nullptr;
28 } 28 }
29 29
30 template <typename T, size_t N> 30 template <typename T, size_t N>
31 bool NameToValue(const NameMapElement<T> (&map)[N], 31 bool NameToValue(const NameMapElement<T> (&map)[N],
32 const std::string& name, 32 const std::string& name,
33 T* result) { 33 T* result) {
34 for (size_t i = 0; i < N; ++i) { 34 for (size_t i = 0; i < N; ++i) {
35 if (map[i].name == name) { 35 if (map[i].name == name) {
36 *result = map[i].value; 36 *result = map[i].value;
37 return true; 37 return true;
38 } 38 }
39 } 39 }
40 return false; 40 return false;
41 } 41 }
42 42
43 } // namespace protocol 43 } // namespace protocol
44 } // namespace remoting 44 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/message_reader.cc ('k') | remoting/protocol/negotiating_authenticator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698