Chris@16: // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) Chris@16: // (C) Copyright 2003-2007 Jonathan Turkanis Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) Chris@16: Chris@16: // See http://www.boost.org/libs/iostreams for documentation. Chris@16: Chris@16: #ifndef BOOST_IOSTREAMS_STREAM_HPP_INCLUDED Chris@16: #define BOOST_IOSTREAMS_STREAM_HPP_INCLUDED Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1020) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include // standard streams. Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace iostreams { namespace detail { Chris@16: Chris@16: template Chris@16: struct stream_traits { Chris@16: typedef typename char_type_of::type char_type; Chris@16: typedef Tr traits_type; Chris@16: typedef typename category_of::type mode; Chris@16: typedef typename Chris@16: iostreams::select< // Disambiguation required for Tru64. Chris@16: mpl::and_< Chris@16: is_convertible, Chris@16: is_convertible Chris@16: >, Chris@16: BOOST_IOSTREAMS_BASIC_IOSTREAM(char_type, traits_type), Chris@16: is_convertible, Chris@16: BOOST_IOSTREAMS_BASIC_ISTREAM(char_type, traits_type), Chris@16: else_, Chris@16: BOOST_IOSTREAMS_BASIC_OSTREAM(char_type, traits_type) Chris@16: >::type stream_type; Chris@16: typedef typename Chris@16: iostreams::select< // Disambiguation required for Tru64. Chris@16: mpl::and_< Chris@16: is_convertible, Chris@16: is_convertible Chris@16: >, Chris@16: iostream_tag, Chris@16: is_convertible, Chris@16: istream_tag, Chris@16: else_, Chris@16: ostream_tag Chris@16: >::type stream_tag; Chris@16: }; Chris@16: Chris@16: // By encapsulating initialization in a base, we can define the macro Chris@16: // BOOST_IOSTREAMS_DEFINE_FORWARDING_FUNCTIONS to generate constructors Chris@16: // without base member initializer lists. Chris@16: template< typename Device, Chris@16: typename Tr = Chris@16: BOOST_IOSTREAMS_CHAR_TRAITS( Chris@16: BOOST_DEDUCED_TYPENAME char_type_of::type Chris@16: ), Chris@16: typename Alloc = Chris@16: std::allocator< Chris@16: BOOST_DEDUCED_TYPENAME char_type_of::type Chris@16: >, Chris@16: typename Base = // VC6 Workaround. Chris@16: BOOST_DEDUCED_TYPENAME Chris@16: detail::stream_traits::stream_type > Chris@16: class stream_base Chris@16: : protected base_from_member< stream_buffer >, Chris@16: public Base Chris@16: { Chris@16: private: Chris@16: typedef base_from_member< stream_buffer > pbase_type; Chris@16: typedef typename stream_traits::stream_type stream_type; Chris@16: protected: Chris@16: using pbase_type::member; // Avoid warning about 'this' in initializer list. Chris@16: public: Chris@16: stream_base() : pbase_type(), stream_type(&member) { } Chris@16: }; Chris@16: Chris@16: } } } // End namespaces detail, iostreams, boost. Chris@16: Chris@16: #ifdef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION Chris@16: # include Chris@16: #else Chris@16: Chris@16: namespace boost { namespace iostreams { Chris@16: Chris@16: // Chris@16: // Template name: stream. Chris@16: // Description: A iostream which reads from and writes to an instance of a Chris@16: // designated device type. Chris@16: // Template parameters: Chris@16: // Device - A device type. Chris@16: // Alloc - The allocator type. Chris@16: // Chris@16: template< typename Device, Chris@16: typename Tr = Chris@16: BOOST_IOSTREAMS_CHAR_TRAITS( Chris@16: BOOST_DEDUCED_TYPENAME char_type_of::type Chris@16: ), Chris@16: typename Alloc = Chris@16: std::allocator< Chris@16: BOOST_DEDUCED_TYPENAME char_type_of::type Chris@16: > > Chris@16: struct stream : detail::stream_base { Chris@16: public: Chris@16: typedef typename char_type_of::type char_type; Chris@16: struct category Chris@16: : mode_of::type, Chris@16: closable_tag, Chris@16: detail::stream_traits::stream_tag Chris@16: { }; Chris@16: BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr) Chris@16: private: Chris@16: typedef typename Chris@16: detail::stream_traits< Chris@16: Device, Tr Chris@16: >::stream_type stream_type; Chris@16: public: Chris@16: stream() { } Chris@16: BOOST_IOSTREAMS_FORWARD( stream, open_impl, Device, Chris@16: BOOST_IOSTREAMS_PUSH_PARAMS, Chris@16: BOOST_IOSTREAMS_PUSH_ARGS ) Chris@16: bool is_open() const { return this->member.is_open(); } Chris@16: void close() { this->member.close(); } Chris@16: bool auto_close() const { return this->member.auto_close(); } Chris@16: void set_auto_close(bool close) { this->member.set_auto_close(close); } Chris@16: bool strict_sync() { return this->member.strict_sync(); } Chris@16: Device& operator*() { return *this->member; } Chris@16: Device* operator->() { return &*this->member; } Chris@16: Device* component() { return this->member.component(); } Chris@16: private: Chris@16: void open_impl(const Device& dev BOOST_IOSTREAMS_PUSH_PARAMS()) // For forwarding. Chris@16: { Chris@16: this->clear(); Chris@16: this->member.open(dev BOOST_IOSTREAMS_PUSH_ARGS()); Chris@16: } Chris@16: }; Chris@16: Chris@16: } } // End namespaces iostreams, boost. Chris@16: Chris@16: #endif // #ifdef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION Chris@16: Chris@16: #endif // #ifndef BOOST_IOSTREAMS_stream_HPP_INCLUDED