summaryrefslogtreecommitdiffstats
path: root/remoting/protocol/name_value_map.h
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-15 01:43:00 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-15 01:43:00 +0000
commita5284efd883797a78f9c7be3120384079a532225 (patch)
tree441884130d9b6ea0b80a54c49ae56aeb0200fba5 /remoting/protocol/name_value_map.h
parent7c477f8cea24d9e667fa30ff6674d4098080f838 (diff)
downloadchromium_src-a5284efd883797a78f9c7be3120384079a532225.zip
chromium_src-a5284efd883797a78f9c7be3120384079a532225.tar.gz
chromium_src-a5284efd883797a78f9c7be3120384079a532225.tar.bz2
Add mux-stream transport support in session description
Also moved NameToValue() and ValueToName() from jingle_messages.cc to name_value_map.h . These functions simplify string<->enum mapping. BUG=137135 Review URL: https://chromiumcodereview.appspot.com/10829324 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151629 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol/name_value_map.h')
-rw-r--r--remoting/protocol/name_value_map.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/remoting/protocol/name_value_map.h b/remoting/protocol/name_value_map.h
new file mode 100644
index 0000000..79e8a47
--- /dev/null
+++ b/remoting/protocol/name_value_map.h
@@ -0,0 +1,40 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// Helper functions that allow to map enum values to strings.
+
+namespace remoting {
+namespace protocol {
+
+template <typename T>
+struct NameMapElement {
+ const T value;
+ const char* const name;
+};
+
+template <typename T, size_t N>
+const char* ValueToName(const NameMapElement<T> (&map)[N], T value) {
+ for (size_t i = 0; i < N; ++i) {
+ if (map[i].value == value)
+ return map[i].name;
+ }
+ NOTREACHED();
+ return NULL;
+}
+
+template <typename T, size_t N>
+bool NameToValue(const NameMapElement<T> (&map)[N],
+ const std::string& name,
+ T* result) {
+ for (size_t i = 0; i < N; ++i) {
+ if (map[i].name == name) {
+ *result = map[i].value;
+ return true;
+ }
+ }
+ return false;
+}
+
+} // namespace protocol
+} // namespace remoting