Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

basic_isocketstream.h

Go to the documentation of this file.
00001 // -*- Socket Streams -*-
00002 
00003 // Copyright (C) 2003, 2004, 2005 Pedro LamarĂ£o <pedro.lamarao@mndfck.org>
00004 
00005 // This file is part of the Socket Streams Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU Lesser General Public License as published by the
00008 // Free Software Foundation; either version 2.1 of the License
00009 // or (at your option) any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU Lesser General Public License for more details.
00015 
00016 // You should have received a copy of the GNU Lesser General Public License along
00017 // with this library; see the file COPYING. If not, write to the Free
00018 // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
00019 // USA
00020 
00025 #ifndef SOCKETSTREAM_BASIC_ISOCKETSTREAM_H
00026 #define SOCKETSTREAM_BASIC_ISOCKETSTREAM_H 1
00027 
00028 #include <socketstream/config.h>
00029 
00030 #include <istream>
00031 #include <socketstream/basic_socketbuf.h>
00032 
00033 namespace ss {
00034 
00038   template <typename _CharT, typename _Traits>
00039   class basic_isocketstream
00040   : public std::basic_istream<_CharT, _Traits>,
00041     public sockets_base
00042   {
00043   public:
00044 
00046 
00053     typedef _CharT                    char_type;
00054     typedef _Traits                   traits_type;
00055 
00056     typedef typename traits_type::int_type int_type;
00057     typedef typename traits_type::pos_type pos_type;
00058     typedef typename traits_type::off_type off_type;
00060 
00061     typedef basic_socketbuf<char_type, traits_type> __streambuf_type;
00062     typedef std::basic_istream<char_type, traits_type> __stream_type;
00063 
00067     basic_isocketstream()
00068     : __stream_type(&_M_buffer), _M_buffer()
00069     { }
00070 
00077     basic_isocketstream(family __f, style __s)
00078     : __stream_type(&_M_buffer), _M_buffer(__f, __s)
00079     { }
00080 
00086     virtual
00087     ~basic_isocketstream() { }
00088 
00094     bool
00095     is_open ()
00096     { return _M_buffer.is_open(); }
00097 
00103     template <typename AddressT>
00104     void
00105     connect (AddressT& __addr)
00106     {
00107       if (!_M_buffer.connect(__addr))
00108         this->setstate(std::ios_base::failbit);
00109     }
00110 
00120     void
00121     shutdown (shutmode __mode = sockets_base::rw)
00122     {
00123       if (!_M_buffer.shutdown(__mode))
00124         this->setstate(std::ios_base::failbit);
00125     }
00126 
00130     __streambuf_type*
00131     rdbuf () const
00132     { return const_cast<__streambuf_type*>(&_M_buffer); }
00133 
00134     __stream_type&
00135     operator<< (flag& __flag)
00136     {
00137       _M_buffer.setf(__flag);
00138       return *this;
00139     }
00140     
00141   private:
00142 
00143     __streambuf_type _M_buffer;
00144 
00145   };
00146 
00147   typedef basic_isocketstream<char, std::char_traits<char> > isocketstream;
00148 
00149 }
00150 
00151 #endif  // SOCKETSTREAM_BASIC_ISOCKETSTREAM_H

Generated on Sat May 21 21:25:32 2005 for Socket Streams Library by  doxygen 1.4.3