Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ASIO_BASIC_SOCKET_IOSTREAM_HPP
00012 #define ASIO_BASIC_SOCKET_IOSTREAM_HPP
00013
00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00015 # pragma once
00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
00017
00018 #include "asio/detail/push_options.hpp"
00019
00020 #include "asio/detail/push_options.hpp"
00021 #include <boost/preprocessor/arithmetic/inc.hpp>
00022 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
00023 #include <boost/preprocessor/repetition/enum_params.hpp>
00024 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
00025 #include <boost/utility/base_from_member.hpp>
00026 #include "asio/detail/pop_options.hpp"
00027
00028 #include "asio/basic_socket_streambuf.hpp"
00029 #include "asio/stream_socket_service.hpp"
00030
00031 #if !defined(ASIO_SOCKET_IOSTREAM_MAX_ARITY)
00032 #define ASIO_SOCKET_IOSTREAM_MAX_ARITY 5
00033 #endif // !defined(ASIO_SOCKET_IOSTREAM_MAX_ARITY)
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #define ASIO_PRIVATE_CTR_DEF(z, n, data) \
00047 template <BOOST_PP_ENUM_PARAMS(n, typename T)> \
00048 explicit basic_socket_iostream(BOOST_PP_ENUM_BINARY_PARAMS(n, T, x)) \
00049 : std::basic_iostream<char>(&this->boost::base_from_member< \
00050 basic_socket_streambuf<Protocol, StreamSocketService> >::member) \
00051 { \
00052 tie(this); \
00053 if (rdbuf()->connect(BOOST_PP_ENUM_PARAMS(n, x)) == 0) \
00054 this->setstate(std::ios_base::failbit); \
00055 } \
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #define ASIO_PRIVATE_CONNECT_DEF(z, n, data) \
00068 template <BOOST_PP_ENUM_PARAMS(n, typename T)> \
00069 void connect(BOOST_PP_ENUM_BINARY_PARAMS(n, T, x)) \
00070 { \
00071 if (rdbuf()->connect(BOOST_PP_ENUM_PARAMS(n, x)) == 0) \
00072 this->setstate(std::ios_base::failbit); \
00073 } \
00074
00075
00076 namespace asio {
00077
00079 template <typename Protocol,
00080 typename StreamSocketService = stream_socket_service<Protocol> >
00081 class basic_socket_iostream
00082 : public boost::base_from_member<
00083 basic_socket_streambuf<Protocol, StreamSocketService> >,
00084 public std::basic_iostream<char>
00085 {
00086 public:
00088 basic_socket_iostream()
00089 : std::basic_iostream<char>(&this->boost::base_from_member<
00090 basic_socket_streambuf<Protocol, StreamSocketService> >::member)
00091 {
00092 tie(this);
00093 }
00094
00095 #if defined(GENERATING_DOCUMENTATION)
00096
00097
00102 template <typename T1, ..., typename TN>
00103 explicit basic_socket_iostream(T1 t1, ..., TN tn);
00104 #else
00105 BOOST_PP_REPEAT_FROM_TO(
00106 1, BOOST_PP_INC(ASIO_SOCKET_IOSTREAM_MAX_ARITY),
00107 ASIO_PRIVATE_CTR_DEF, _ )
00108 #endif
00109
00110 #if defined(GENERATING_DOCUMENTATION)
00111
00112
00117 template <typename T1, ..., typename TN>
00118 void connect(T1 t1, ..., TN tn);
00119 #else
00120 BOOST_PP_REPEAT_FROM_TO(
00121 1, BOOST_PP_INC(ASIO_SOCKET_IOSTREAM_MAX_ARITY),
00122 ASIO_PRIVATE_CONNECT_DEF, _ )
00123 #endif
00124
00126 void close()
00127 {
00128 if (rdbuf()->close() == 0)
00129 this->setstate(std::ios_base::failbit);
00130 }
00131
00133 basic_socket_streambuf<Protocol, StreamSocketService>* rdbuf() const
00134 {
00135 return const_cast<basic_socket_streambuf<Protocol, StreamSocketService>*>(
00136 &this->boost::base_from_member<
00137 basic_socket_streambuf<Protocol, StreamSocketService> >::member);
00138 }
00139 };
00140
00141 }
00142
00143 #undef ASIO_PRIVATE_CTR_DEF
00144 #undef ASIO_PRIVATE_CONNECT_DEF
00145
00146 #include "asio/detail/pop_options.hpp"
00147
00148 #endif // ASIO_BASIC_SOCKET_IOSTREAM_HPP