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

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

Issue 2807803002: Move name_value_map to remoting/base (Closed)
Patch Set: sync Created 3 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4 //
5 // Helper functions that allow to map enum values to strings.
6
7 #ifndef REMOTING_PROTOCOL_NAME_VALUE_MAP_H_
8 #define REMOTING_PROTOCOL_NAME_VALUE_MAP_H_
9
10 #include <stddef.h>
11
12 #include "base/logging.h"
13
14 namespace remoting {
15 namespace protocol {
16
17 template <typename T>
18 struct NameMapElement {
19 const T value;
20 const char* const name;
21 };
22
23 template <typename T, size_t N>
24 const char* ValueToName(const NameMapElement<T> (&map)[N], T value) {
25 for (size_t i = 0; i < N; ++i) {
26 if (map[i].value == value)
27 return map[i].name;
28 }
29 NOTREACHED();
30 return nullptr;
31 }
32
33 template <typename T, size_t N>
34 bool NameToValue(const NameMapElement<T> (&map)[N],
35 const std::string& name,
36 T* result) {
37 for (size_t i = 0; i < N; ++i) {
38 if (map[i].name == name) {
39 *result = map[i].value;
40 return true;
41 }
42 }
43 return false;
44 }
45
46 } // namespace protocol
47 } // namespace remoting
48
49 #endif // REMOTING_PROTOCOL_NAME_VALUE_MAP_H_
OLDNEW
« no previous file with comments | « remoting/protocol/jingle_messages.cc ('k') | remoting/protocol/negotiating_authenticator_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698