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 if (rdbuf()->connect(BOOST_PP_ENUM_PARAMS(n, x)) == 0) \
00053 this->setstate(std::ios_base::failbit); \
00054 } \
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 #define ASIO_PRIVATE_CONNECT_DEF(z, n, data) \
00067 template <BOOST_PP_ENUM_PARAMS(n, typename T)> \
00068 void connect(BOOST_PP_ENUM_BINARY_PARAMS(n, T, x)) \
00069 { \
00070 if (rdbuf()->connect(BOOST_PP_ENUM_PARAMS(n, x)) == 0) \
00071 this->setstate(std::ios_base::failbit); \
00072 } \
00073
00074
00075 namespace asio {
00076
00078 template <typename Protocol,
00079 typename StreamSocketService = stream_socket_service<Protocol> >
00080 class basic_socket_iostream
00081 : public boost::base_from_member<
00082 basic_socket_streambuf<Protocol, StreamSocketService> >,
00083 public std::basic_iostream<char>
00084 {
00085 public:
00087 basic_socket_iostream()
00088 : std::basic_iostream<char>(&this->boost::base_from_member<
00089 basic_socket_streambuf<Protocol, StreamSocketService> >::member)
00090 {
00091 }
00092
00093 #if defined(GENERATING_DOCUMENTATION)
00095
00100 template <typename T1, ..., typename TN>
00101 explicit basic_socket_iostream(T1 t1, ..., TN tn);
00102 #else
00103 BOOST_PP_REPEAT_FROM_TO(
00104 1, BOOST_PP_INC(ASIO_SOCKET_IOSTREAM_MAX_ARITY),
00105 ASIO_PRIVATE_CTR_DEF, _ )
00106 #endif
00107
00108 #if defined(GENERATING_DOCUMENTATION)
00110
00115 template <typename T1, ..., typename TN>
00116 void connect(T1 t1, ..., TN tn);
00117 #else
00118 BOOST_PP_REPEAT_FROM_TO(
00119 1, BOOST_PP_INC(ASIO_SOCKET_IOSTREAM_MAX_ARITY),
00120 ASIO_PRIVATE_CONNECT_DEF, _ )
00121 #endif
00122
00124 void close()
00125 {
00126 if (rdbuf()->close() == 0)
00127 this->setstate(std::ios_base::failbit);
00128 }
00129
00131 basic_socket_streambuf<Protocol, StreamSocketService>* rdbuf() const
00132 {
00133 return const_cast<basic_socket_streambuf<Protocol, StreamSocketService>*>(
00134 &this->boost::base_from_member<
00135 basic_socket_streambuf<Protocol, StreamSocketService> >::member);
00136 }
00137 };
00138
00139 }
00140
00141 #undef ASIO_PRIVATE_CTR_DEF
00142 #undef ASIO_PRIVATE_CONNECT_DEF
00143
00144 #include "asio/detail/pop_options.hpp"
00145
00146 #endif // ASIO_BASIC_SOCKET_IOSTREAM_HPP