RSB  0.7.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Types.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is part of the RSB project.
4  *
5  * Copyright (C) 2011 Jan Moringen <jmoringe@techfak.uni-bielefeld.de>
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #pragma once
28 
29 #include <stdexcept>
30 #include <string>
31 #include <iostream>
32 
33 #include <boost/cstdint.hpp>
34 #include <boost/format.hpp>
35 
36 namespace rsb {
37 namespace transport {
38 namespace socket {
39 
40 enum Server {
41  SERVER_NO = 0,
44 };
45 
46 template <typename Ch, typename Tr>
47 std::basic_istream<Ch, Tr>& operator>>(std::basic_istream<Ch, Tr>& stream,
48  Server& value) {
49  // Read one whitespace-delimited token.
50  std::basic_string<Ch, Tr> string;
51  stream >> string;
52 
53  // Interpret the value.
54  if (string == "0") {
55  value = SERVER_NO;
56  } else if (string == "1") {
57  value = SERVER_YES;
58  } else if (string == "auto") {
59  value = SERVER_AUTO;
60  } else {
61  throw std::invalid_argument(boost::str(boost::format("Invalid server/client specification: %1%")
62  % string));
63  }
64 
65  return stream;
66 }
67 
68 template <typename Ch, typename Tr>
69 std::basic_ostream<Ch, Tr>& operator<<(std::basic_ostream<Ch, Tr>& stream,
70  const Server& value) {
71  switch (value) {
72  case SERVER_NO:
73  stream << "0";
74  break;
75  case SERVER_YES:
76  stream << "1";
77  break;
78  case SERVER_AUTO:
79  stream << "auto";
80  break;
81  }
82 
83  return stream;
84 }
85 
86 extern const std::string DEFAULT_HOST;
87 
88 extern const boost::uint16_t DEFAULT_PORT;
89 
90 }
91 }
92 }