Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:49

0001 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
0002 // (C) Copyright 2003-2007 Jonathan Turkanis
0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
0005 
0006 // See http://www.boost.org/libs/iostreams for documentation.
0007 
0008 #ifndef BOOST_IOSTREAMS_DETAIL_CHAINBUF_HPP_INCLUDED
0009 #define BOOST_IOSTREAMS_DETAIL_CHAINBUF_HPP_INCLUDED
0010 
0011 #if defined(_MSC_VER)
0012 # pragma once
0013 #endif      
0014 
0015 #include <boost/config.hpp>                    // BOOST_MSVC, template friends.
0016 #include <boost/detail/workaround.hpp>
0017 #include <boost/iostreams/chain.hpp>
0018 #include <boost/iostreams/detail/access_control.hpp>
0019 #include <boost/iostreams/detail/config/wide_streams.hpp>
0020 #include <boost/iostreams/detail/streambuf.hpp>
0021 #include <boost/iostreams/detail/streambuf/linked_streambuf.hpp>
0022 #include <boost/iostreams/detail/translate_int_type.hpp>
0023 #include <boost/iostreams/traits.hpp>
0024 #include <boost/noncopyable.hpp>
0025 
0026 namespace boost { namespace iostreams { namespace detail {
0027 
0028 //--------------Definition of chainbuf----------------------------------------//
0029 
0030 //
0031 // Template name: chainbuf.
0032 // Description: Stream buffer which operates by delegating to the first
0033 //      linked_streambuf in a chain.
0034 // Template parameters:
0035 //      Chain - The chain type.
0036 //
0037 template<typename Chain, typename Mode, typename Access>
0038 class chainbuf
0039     : public BOOST_IOSTREAMS_BASIC_STREAMBUF(
0040                  typename Chain::char_type,
0041                  typename Chain::traits_type
0042              ),
0043       public access_control<typename Chain::client_type, Access>,
0044       private noncopyable
0045 {
0046 private:
0047     typedef access_control<chain_client<Chain>, Access>      client_type;
0048 public:
0049     typedef typename Chain::char_type                        char_type;
0050     BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(typename Chain::traits_type)
0051 protected:
0052     typedef linked_streambuf<char_type, traits_type>         delegate_type;
0053     chainbuf() { client_type::set_chain(&chain_); }
0054     int_type underflow() 
0055         { sentry t(this); return translate(delegate().underflow()); }
0056     int_type pbackfail(int_type c)
0057         { sentry t(this); return translate(delegate().pbackfail(c)); }
0058     std::streamsize xsgetn(char_type* s, std::streamsize n)
0059         { sentry t(this); return delegate().xsgetn(s, n); }
0060     int_type overflow(int_type c)
0061         { sentry t(this); return translate(delegate().overflow(c)); }
0062     std::streamsize xsputn(const char_type* s, std::streamsize n)
0063         { sentry t(this); return delegate().xsputn(s, n); }
0064     int sync() { sentry t(this); return delegate().sync(); }
0065     pos_type seekoff( off_type off, BOOST_IOS::seekdir way,
0066                       BOOST_IOS::openmode which =
0067                           BOOST_IOS::in | BOOST_IOS::out )
0068         { sentry t(this); return delegate().seekoff(off, way, which); }
0069     pos_type seekpos( pos_type sp,
0070                       BOOST_IOS::openmode which =
0071                           BOOST_IOS::in | BOOST_IOS::out )
0072         { sentry t(this); return delegate().seekpos(sp, which); }
0073 protected:
0074     typedef BOOST_IOSTREAMS_BASIC_STREAMBUF(
0075                  typename Chain::char_type,
0076                  typename Chain::traits_type
0077              )                                               base_type;
0078 private:
0079 
0080     // Translate from std int_type to chain's int_type.
0081     typedef BOOST_IOSTREAMS_CHAR_TRAITS(char_type)           std_traits;
0082     typedef typename Chain::traits_type                      chain_traits;
0083     static typename chain_traits::int_type 
0084     translate(typename std_traits::int_type c)
0085         { return translate_int_type<std_traits, chain_traits>(c); }
0086 
0087     delegate_type& delegate() 
0088         { return static_cast<delegate_type&>(chain_.front()); }
0089     void get_pointers()
0090         {
0091             this->setg(delegate().eback(), delegate().gptr(), delegate().egptr());
0092             this->setp(delegate().pbase(), delegate().epptr());
0093             this->pbump((int) (delegate().pptr() - delegate().pbase()));
0094         }
0095     void set_pointers()
0096         {
0097             delegate().setg(this->eback(), this->gptr(), this->egptr());
0098             delegate().setp(this->pbase(), this->epptr());
0099             delegate().pbump((int) (this->pptr() - this->pbase()));
0100         }
0101     struct sentry {
0102         sentry(chainbuf<Chain, Mode, Access>* buf) : buf_(buf)
0103             { buf_->set_pointers(); }
0104         ~sentry() { buf_->get_pointers(); }
0105         chainbuf<Chain, Mode, Access>* buf_;
0106     };
0107     friend struct sentry;
0108     Chain chain_;
0109 };
0110 
0111 } } } // End namespaces detail, iostreams, boost.
0112 
0113 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_CHAINBUF_HPP_INCLUDED