Realistic 3D camera system
3D camera system components
basic_socket_iostream.hpp
Go to the documentation of this file.
1 //
2 // basic_socket_iostream.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 #ifndef ASIO_BASIC_SOCKET_IOSTREAM_HPP
12 #define ASIO_BASIC_SOCKET_IOSTREAM_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 
20 #if !defined(ASIO_NO_IOSTREAM)
21 
22 #include <istream>
23 #include <ostream>
26 
27 #if !defined(ASIO_HAS_VARIADIC_TEMPLATES)
28 
30 
31 // A macro that should expand to:
32 // template <typename T1, ..., typename Tn>
33 // explicit basic_socket_iostream(T1 x1, ..., Tn xn)
34 // : std::basic_iostream<char>(
35 // &this->detail::socket_iostream_base<
36 // Protocol, StreamSocketService, Time,
37 // TimeTraits, TimerService>::streambuf_)
38 // {
39 // if (rdbuf()->connect(x1, ..., xn) == 0)
40 // this->setstate(std::ios_base::failbit);
41 // }
42 // This macro should only persist within this file.
43 
44 # define ASIO_PRIVATE_CTR_DEF(n) \
45  template <ASIO_VARIADIC_TPARAMS(n)> \
46  explicit basic_socket_iostream(ASIO_VARIADIC_PARAMS(n)) \
47  : std::basic_iostream<char>( \
48  &this->detail::socket_iostream_base< \
49  Protocol, StreamSocketService, Time, \
50  TimeTraits, TimerService>::streambuf_) \
51  { \
52  this->setf(std::ios_base::unitbuf); \
53  if (rdbuf()->connect(ASIO_VARIADIC_ARGS(n)) == 0) \
54  this->setstate(std::ios_base::failbit); \
55  } \
56 
57 
58 // A macro that should expand to:
59 // template <typename T1, ..., typename Tn>
60 // void connect(T1 x1, ..., Tn xn)
61 // {
62 // if (rdbuf()->connect(x1, ..., xn) == 0)
63 // this->setstate(std::ios_base::failbit);
64 // }
65 // This macro should only persist within this file.
66 
67 # define ASIO_PRIVATE_CONNECT_DEF(n) \
68  template <ASIO_VARIADIC_TPARAMS(n)> \
69  void connect(ASIO_VARIADIC_PARAMS(n)) \
70  { \
71  if (rdbuf()->connect(ASIO_VARIADIC_ARGS(n)) == 0) \
72  this->setstate(std::ios_base::failbit); \
73  } \
74 
75 
76 #endif // !defined(ASIO_HAS_VARIADIC_TEMPLATES)
77 
79 
80 namespace asio {
81 namespace detail {
82 
83 // A separate base class is used to ensure that the streambuf is initialised
84 // prior to the basic_socket_iostream's basic_iostream base class.
85 template <typename Protocol, typename StreamSocketService,
86  typename Time, typename TimeTraits, typename TimerService>
88 {
89 protected:
90  basic_socket_streambuf<Protocol, StreamSocketService,
91  Time, TimeTraits, TimerService> streambuf_;
92 };
93 
94 }
95 
97 template <typename Protocol,
98  typename StreamSocketService = stream_socket_service<Protocol>,
99 #if defined(ASIO_HAS_BOOST_DATE_TIME) \
100  || defined(GENERATING_DOCUMENTATION)
101  typename Time = boost::posix_time::ptime,
102  typename TimeTraits = asio::time_traits<Time>,
103  typename TimerService = deadline_timer_service<Time, TimeTraits> >
104 #else
105  typename Time = steady_timer::clock_type,
106  typename TimeTraits = steady_timer::traits_type,
107  typename TimerService = steady_timer::service_type>
108 #endif
110  : private detail::socket_iostream_base<Protocol,
111  StreamSocketService, Time, TimeTraits, TimerService>,
112  public std::basic_iostream<char>
113 {
114 private:
115  // These typedefs are intended keep this class's implementation independent
116  // of whether it's using Boost.DateTime, Boost.Chrono or std::chrono.
117 #if defined(ASIO_HAS_BOOST_DATE_TIME)
118  typedef TimeTraits traits_helper;
119 #else
120  typedef detail::chrono_time_traits<Time, TimeTraits> traits_helper;
121 #endif
122 
123 public:
125  typedef typename Protocol::endpoint endpoint_type;
126 
127 #if defined(GENERATING_DOCUMENTATION)
128  typedef typename TimeTraits::time_type time_type;
130 
132  typedef typename TimeTraits::duration_type duration_type;
133 #else
136 #endif
137 
140  : std::basic_iostream<char>(
141  &this->detail::socket_iostream_base<
142  Protocol, StreamSocketService, Time,
143  TimeTraits, TimerService>::streambuf_)
144  {
145  this->setf(std::ios_base::unitbuf);
146  }
147 
148 #if defined(GENERATING_DOCUMENTATION)
149 
155  template <typename T1, ..., typename TN>
156  explicit basic_socket_iostream(T1 t1, ..., TN tn);
157 #elif defined(ASIO_HAS_VARIADIC_TEMPLATES)
158  template <typename... T>
159  explicit basic_socket_iostream(T... x)
160  : std::basic_iostream<char>(
162  Protocol, StreamSocketService, Time,
163  TimeTraits, TimerService>::streambuf_)
164  {
165  this->setf(std::ios_base::unitbuf);
166  if (rdbuf()->connect(x...) == 0)
167  this->setstate(std::ios_base::failbit);
168  }
169 #else
171 #endif
172 
173 #if defined(GENERATING_DOCUMENTATION)
174 
180  template <typename T1, ..., typename TN>
181  void connect(T1 t1, ..., TN tn);
182 #elif defined(ASIO_HAS_VARIADIC_TEMPLATES)
183  template <typename... T>
184  void connect(T... x)
185  {
186  if (rdbuf()->connect(x...) == 0)
187  this->setstate(std::ios_base::failbit);
188  }
189 #else
191 #endif
192 
194  void close()
195  {
196  if (rdbuf()->close() == 0)
197  this->setstate(std::ios_base::failbit);
198  }
199 
201  basic_socket_streambuf<Protocol, StreamSocketService,
202  Time, TimeTraits, TimerService>* rdbuf() const
203  {
204  return const_cast<basic_socket_streambuf<Protocol, StreamSocketService,
205  Time, TimeTraits, TimerService>*>(
207  Protocol, StreamSocketService, Time,
208  TimeTraits, TimerService>::streambuf_);
209  }
210 
212 
223  const asio::error_code& error() const
224  {
225  return rdbuf()->puberror();
226  }
227 
229 
232  time_type expires_at() const
233  {
234  return rdbuf()->expires_at();
235  }
236 
238 
246  void expires_at(const time_type& expiry_time)
247  {
248  rdbuf()->expires_at(expiry_time);
249  }
250 
252 
255  duration_type expires_from_now() const
256  {
257  return rdbuf()->expires_from_now();
258  }
259 
261 
269  void expires_from_now(const duration_type& expiry_time)
270  {
271  rdbuf()->expires_from_now(expiry_time);
272  }
273 };
274 
275 } // namespace asio
276 
278 
279 #if !defined(ASIO_HAS_VARIADIC_TEMPLATES)
280 # undef ASIO_PRIVATE_CTR_DEF
281 # undef ASIO_PRIVATE_CONNECT_DEF
282 #endif // !defined(ASIO_HAS_VARIADIC_TEMPLATES)
283 
284 #endif // !defined(ASIO_NO_IOSTREAM)
285 
286 #endif // ASIO_BASIC_SOCKET_IOSTREAM_HPP
Iostream interface for a socket.
duration_type expires_from_now() const
Get the timer&#39;s expiry time relative to now.
Default service implementation for a stream socket.
basic_socket_iostream()
Construct a basic_socket_iostream without establishing a connection.
STL namespace.
Iterator connect(basic_socket< Protocol, SocketService > &s, Iterator begin)
Establishes a socket connection by trying each endpoint in a sequence.
Definition: connect.hpp:44
const asio::error_code & error() const
Get the last error associated with the stream.
basic_socket_streambuf< Protocol, StreamSocketService, Time, TimeTraits, TimerService > streambuf_
Class to represent an error code value.
Definition: error_code.hpp:80
#define ASIO_VARIADIC_GENERATE(m)
void expires_at(const time_type &expiry_time)
Set the stream&#39;s expiry time as an absolute time.
traits_helper::duration_type duration_type
#define ASIO_PRIVATE_CONNECT_DEF(n)
time_type expires_at() const
Get the stream&#39;s expiry time as an absolute time.
ASIO_DECL int close(int d, state_type &state, asio::error_code &ec)
#define ASIO_PRIVATE_CTR_DEF(n)
Iostream streambuf for a socket.
traits_helper::time_type time_type
void expires_from_now(const duration_type &expiry_time)
Set the stream&#39;s expiry time relative to now.
Protocol::endpoint endpoint_type
The endpoint type.
void close()
Close the connection.
basic_socket_streambuf< Protocol, StreamSocketService, Time, TimeTraits, TimerService > * rdbuf() const
Return a pointer to the underlying streambuf.