00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef BOOST_CMT_ASIO_BASIC_SOCKET_IOSTREAM_HPP
00012 #define BOOST_CMT_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 <boost/asio/detail/config.hpp>
00019
00020 #if !defined(BOOST_NO_IOSTREAM)
00021
00022 #include <boost/preprocessor/arithmetic/inc.hpp>
00023 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
00024 #include <boost/preprocessor/repetition/enum_params.hpp>
00025 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
00026 #include <boost/utility/base_from_member.hpp>
00027 #include <boost/cmt/asio/basic_socket_streambuf.hpp>
00028 #include <boost/asio/stream_socket_service.hpp>
00029
00030 #if !defined(BOOST_ASIO_SOCKET_IOSTREAM_MAX_ARITY)
00031 #define BOOST_ASIO_SOCKET_IOSTREAM_MAX_ARITY 5
00032 #endif // !defined(BOOST_ASIO_SOCKET_IOSTREAM_MAX_ARITY)
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #define BOOST_ASIO_PRIVATE_CTR_DEF(z, n, data) \
00046 template <BOOST_PP_ENUM_PARAMS(n, typename T)> \
00047 explicit basic_socket_iostream(BOOST_PP_ENUM_BINARY_PARAMS(n, T, x)) \
00048 : std::basic_iostream<char>(&this->boost::base_from_member< \
00049 boost::cmt::asio::basic_socket_streambuf<Protocol, StreamSocketService> >::member) \
00050 { \
00051 tie(this); \
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 BOOST_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 #include <boost/asio/detail/push_options.hpp>
00076
00077 namespace boost {
00078 namespace cmt {
00079 namespace asio {
00080
00082 template <typename Protocol,
00083 typename StreamSocketService = stream_socket_service<Protocol> >
00084 class basic_socket_iostream
00085 : public boost::base_from_member<
00086 boost::cmt::asio::basic_socket_streambuf<Protocol, StreamSocketService> >,
00087 public std::basic_iostream<char>
00088 {
00089 public:
00090 typedef boost::shared_ptr<basic_socket_iostream> ptr;
00091
00093 basic_socket_iostream()
00094 : std::basic_iostream<char>(&this->boost::base_from_member<
00095 basic_socket_streambuf<Protocol, StreamSocketService> >::member)
00096 {
00097 tie(this);
00098 }
00099
00100 #if defined(GENERATING_DOCUMENTATION)
00101
00102
00107 template <typename T1, ..., typename TN>
00108 explicit basic_socket_iostream(T1 t1, ..., TN tn);
00109 #else
00110 BOOST_PP_REPEAT_FROM_TO(
00111 1, BOOST_PP_INC(BOOST_ASIO_SOCKET_IOSTREAM_MAX_ARITY),
00112 BOOST_ASIO_PRIVATE_CTR_DEF, _ )
00113 #endif
00114
00115 #if defined(GENERATING_DOCUMENTATION)
00116
00117
00122 template <typename T1, ..., typename TN>
00123 void connect(T1 t1, ..., TN tn);
00124 #else
00125 BOOST_PP_REPEAT_FROM_TO(
00126 1, BOOST_PP_INC(BOOST_ASIO_SOCKET_IOSTREAM_MAX_ARITY),
00127 BOOST_ASIO_PRIVATE_CONNECT_DEF, _ )
00128 #endif
00129
00131 void close()
00132 {
00133 if (rdbuf()->close() == 0)
00134 this->setstate(std::ios_base::failbit);
00135 }
00136
00138 basic_socket_streambuf<Protocol, StreamSocketService>* rdbuf() const
00139 {
00140 return const_cast<basic_socket_streambuf<Protocol, StreamSocketService>*>(
00141 &this->boost::base_from_member<
00142 basic_socket_streambuf<Protocol, StreamSocketService> >::member);
00143 }
00144 };
00145
00146 }
00147 }
00148 }
00149
00150 #include <boost/asio/detail/pop_options.hpp>
00151
00152 #undef BOOST_ASIO_PRIVATE_CTR_DEF
00153 #undef BOOST_ASIO_PRIVATE_CONNECT_DEF
00154
00155 #endif // defined(BOOST_NO_IOSTREAM)
00156
00157 #endif // BOOST_CMT_ASIO_BASIC_SOCKET_IOSTREAM_HPP