OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef REMOTING_PROTOCOL_NAME_VALUE_MAP_H_ | 7 #ifndef REMOTING_BASE_NAME_VALUE_MAP_H_ |
8 #define REMOTING_PROTOCOL_NAME_VALUE_MAP_H_ | 8 #define REMOTING_BASE_NAME_VALUE_MAP_H_ |
9 | 9 |
10 #include <stddef.h> | 10 #include <stddef.h> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 | 13 |
14 namespace remoting { | 14 namespace remoting { |
15 namespace protocol { | |
16 | 15 |
17 template <typename T> | 16 template <typename T> |
18 struct NameMapElement { | 17 struct NameMapElement { |
19 const T value; | 18 const T value; |
20 const char* const name; | 19 const char* const name; |
21 }; | 20 }; |
22 | 21 |
23 template <typename T, size_t N> | 22 template <typename T, size_t N> |
24 const char* ValueToName(const NameMapElement<T> (&map)[N], T value) { | 23 const char* ValueToName(const NameMapElement<T> (&map)[N], T value) { |
25 for (size_t i = 0; i < N; ++i) { | 24 for (size_t i = 0; i < N; ++i) { |
(...skipping 10 matching lines...) Expand all Loading... |
36 T* result) { | 35 T* result) { |
37 for (size_t i = 0; i < N; ++i) { | 36 for (size_t i = 0; i < N; ++i) { |
38 if (map[i].name == name) { | 37 if (map[i].name == name) { |
39 *result = map[i].value; | 38 *result = map[i].value; |
40 return true; | 39 return true; |
41 } | 40 } |
42 } | 41 } |
43 return false; | 42 return false; |
44 } | 43 } |
45 | 44 |
46 } // namespace protocol | |
47 } // namespace remoting | 45 } // namespace remoting |
48 | 46 |
49 #endif // REMOTING_PROTOCOL_NAME_VALUE_MAP_H_ | 47 #endif // REMOTING_BASE_NAME_VALUE_MAP_H_ |
OLD | NEW |