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_DETAIL_CHAINBUF_HPP_INCLUDED Chris@16: #define BOOST_IOSTREAMS_DETAIL_CHAINBUF_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 // BOOST_MSVC, template friends. Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include 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: //--------------Definition of chainbuf----------------------------------------// Chris@16: Chris@16: // Chris@16: // Template name: chainbuf. Chris@16: // Description: Stream buffer which operates by delegating to the first Chris@16: // linked_streambuf in a chain. Chris@16: // Template parameters: Chris@16: // Chain - The chain type. Chris@16: // Chris@16: template Chris@16: class chainbuf Chris@16: : public BOOST_IOSTREAMS_BASIC_STREAMBUF( Chris@16: typename Chain::char_type, Chris@16: typename Chain::traits_type Chris@16: ), Chris@16: public access_control, Chris@16: private noncopyable Chris@16: { Chris@16: private: Chris@16: typedef access_control, Access> client_type; Chris@16: public: Chris@16: typedef typename Chain::char_type char_type; Chris@16: BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(typename Chain::traits_type) Chris@16: protected: Chris@16: typedef linked_streambuf delegate_type; Chris@16: chainbuf() { client_type::set_chain(&chain_); } Chris@16: int_type underflow() Chris@16: { sentry t(this); return translate(delegate().underflow()); } Chris@16: int_type pbackfail(int_type c) Chris@16: { sentry t(this); return translate(delegate().pbackfail(c)); } Chris@16: std::streamsize xsgetn(char_type* s, std::streamsize n) Chris@16: { sentry t(this); return delegate().xsgetn(s, n); } Chris@16: int_type overflow(int_type c) Chris@16: { sentry t(this); return translate(delegate().overflow(c)); } Chris@16: std::streamsize xsputn(const char_type* s, std::streamsize n) Chris@16: { sentry t(this); return delegate().xsputn(s, n); } Chris@16: int sync() { sentry t(this); return delegate().sync(); } Chris@16: pos_type seekoff( off_type off, BOOST_IOS::seekdir way, Chris@16: BOOST_IOS::openmode which = Chris@16: BOOST_IOS::in | BOOST_IOS::out ) Chris@16: { sentry t(this); return delegate().seekoff(off, way, which); } Chris@16: pos_type seekpos( pos_type sp, Chris@16: BOOST_IOS::openmode which = Chris@16: BOOST_IOS::in | BOOST_IOS::out ) Chris@16: { sentry t(this); return delegate().seekpos(sp, which); } Chris@16: protected: Chris@16: typedef BOOST_IOSTREAMS_BASIC_STREAMBUF( Chris@16: typename Chain::char_type, Chris@16: typename Chain::traits_type Chris@16: ) base_type; Chris@16: //#if !BOOST_WORKAROUND(__GNUC__, == 2) Chris@16: // BOOST_IOSTREAMS_USING_PROTECTED_STREAMBUF_MEMBERS(base_type) Chris@16: //#endif Chris@16: private: Chris@16: Chris@16: // Translate from std int_type to chain's int_type. Chris@16: typedef BOOST_IOSTREAMS_CHAR_TRAITS(char_type) std_traits; Chris@16: typedef typename Chain::traits_type chain_traits; Chris@16: static typename chain_traits::int_type Chris@16: translate(typename std_traits::int_type c) Chris@16: { return translate_int_type(c); } Chris@16: Chris@16: delegate_type& delegate() Chris@16: { return static_cast(chain_.front()); } Chris@16: void get_pointers() Chris@16: { Chris@16: this->setg(delegate().eback(), delegate().gptr(), delegate().egptr()); Chris@16: this->setp(delegate().pbase(), delegate().epptr()); Chris@16: this->pbump((int) (delegate().pptr() - delegate().pbase())); Chris@16: } Chris@16: void set_pointers() Chris@16: { Chris@16: delegate().setg(this->eback(), this->gptr(), this->egptr()); Chris@16: delegate().setp(this->pbase(), this->epptr()); Chris@16: delegate().pbump((int) (this->pptr() - this->pbase())); Chris@16: } Chris@16: struct sentry { Chris@16: sentry(chainbuf* buf) : buf_(buf) Chris@16: { buf_->set_pointers(); } Chris@16: ~sentry() { buf_->get_pointers(); } Chris@16: chainbuf* buf_; Chris@16: }; Chris@16: friend struct sentry; Chris@16: Chain chain_; Chris@16: }; Chris@16: Chris@16: } } } // End namespaces detail, iostreams, boost. Chris@16: Chris@16: #endif // #ifndef BOOST_IOSTREAMS_DETAIL_CHAINBUF_HPP_INCLUDED