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

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

Issue 10829324: Add mux-stream transport support in session description (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
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 namespace remoting {
8 namespace protocol {
9
10 template <typename T>
11 struct NameMapElement {
Wez 2012/08/14 20:56:32 nit: If you make both |value| and |name| template
Sergey Ulanov 2012/08/14 21:21:36 We need to store char* in the static array (to avo
12 const T value;
13 const char* const name;
14 };
15
16 template <typename T, size_t N>
17 const char* ValueToName(const NameMapElement<T> (&map)[N], T value) {
18 for (size_t i = 0; i < N; ++i) {
19 if (map[i].value == value)
20 return map[i].name;
21 }
22 return NULL;
23 }
24
25 template <typename T, size_t N>
26 bool NameToValue(const NameMapElement<T> (&map)[N],
27 const std::string& name,
28 T* result) {
Wez 2012/08/14 20:56:32 nit: Why not return const T* and have the caller c
Sergey Ulanov 2012/08/14 21:21:36 I think that would be more confusing and harder to
29 for (size_t i = 0; i < N; ++i) {
30 if (map[i].name == name) {
31 *result = map[i].value;
32 return true;
33 }
34 }
35 return false;
36 }
37
38 } // namespace protocol
39 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698