Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-14 08:27:55

0001 //-----------------------------------------------------------------------------
0002 // boost detail/templated_streams.hpp header file
0003 // See http://www.boost.org for updates, documentation, and revision history.
0004 //-----------------------------------------------------------------------------
0005 //
0006 // Copyright (c) 2013 John Maddock, Antony Polukhin
0007 // 
0008 //
0009 // Distributed under the Boost Software License, Version 1.0. (See
0010 // accompanying file LICENSE_1_0.txt or copy at
0011 // http://www.boost.org/LICENSE_1_0.txt)
0012 
0013 #ifndef BOOST_DETAIL_BASIC_POINTERBUF_HPP
0014 #define BOOST_DETAIL_BASIC_POINTERBUF_HPP
0015 
0016 // MS compatible compilers support #pragma once
0017 #if defined(_MSC_VER)
0018 # pragma once
0019 #endif
0020 
0021 #include <boost/config.hpp>
0022 #include <boost/integer.hpp>
0023 
0024 #include <streambuf>
0025 
0026 namespace boost { namespace detail {
0027 
0028 //
0029 // class basic_pointerbuf:
0030 // acts as a stream buffer which wraps around a pair of pointers:
0031 //
0032 template <class charT, class BufferT >
0033 class basic_pointerbuf : public BufferT {
0034 protected:
0035    typedef BufferT base_type;
0036    typedef basic_pointerbuf<charT, BufferT> this_type;
0037    typedef typename base_type::int_type int_type;
0038    typedef typename base_type::char_type char_type;
0039    typedef typename base_type::pos_type pos_type;
0040    typedef ::std::streamsize streamsize;
0041    typedef typename base_type::off_type off_type;
0042 
0043 public:
0044    basic_pointerbuf() : base_type() { this_type::setbuf(0, 0); }
0045    const charT* getnext() { return this->gptr(); }
0046 
0047     using base_type::pptr;
0048     using base_type::pbase;
0049 
0050 protected:
0051    // VC mistakenly assumes that `setbuf` and other functions are not referenced.
0052    // Marking those functions with `inline` suppresses the warnings.
0053    // There must be no harm from marking virtual functions as inline: inline virtual
0054    // call can be inlined ONLY when the compiler knows the "exact class".
0055    inline base_type* setbuf(char_type* s, streamsize n) BOOST_OVERRIDE;
0056    inline typename this_type::pos_type seekpos(pos_type sp, ::std::ios_base::openmode which) BOOST_OVERRIDE;
0057    inline typename this_type::pos_type seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which) BOOST_OVERRIDE;
0058 
0059 private:
0060    basic_pointerbuf& operator=(const basic_pointerbuf&);
0061    basic_pointerbuf(const basic_pointerbuf&);
0062 };
0063 
0064 template<class charT, class BufferT>
0065 BufferT*
0066 basic_pointerbuf<charT, BufferT>::setbuf(char_type* s, streamsize n)
0067 {
0068    this->setg(s, s, s + n);
0069    return this;
0070 }
0071 
0072 template<class charT, class BufferT>
0073 typename basic_pointerbuf<charT, BufferT>::pos_type
0074 basic_pointerbuf<charT, BufferT>::seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which)
0075 {
0076    typedef typename boost::int_t<sizeof(way) * CHAR_BIT>::least cast_type;
0077 
0078    if(which & ::std::ios_base::out)
0079       return pos_type(off_type(-1));
0080    std::ptrdiff_t size = this->egptr() - this->eback();
0081    std::ptrdiff_t pos = this->gptr() - this->eback();
0082    charT* g = this->eback();
0083    switch(static_cast<cast_type>(way))
0084    {
0085    case ::std::ios_base::beg:
0086       if((off < 0) || (off > size))
0087          return pos_type(off_type(-1));
0088       else
0089          this->setg(g, g + off, g + size);
0090       break;
0091    case ::std::ios_base::end:
0092       if((off < 0) || (off > size))
0093          return pos_type(off_type(-1));
0094       else
0095          this->setg(g, g + size - off, g + size);
0096       break;
0097    case ::std::ios_base::cur:
0098    {
0099       std::ptrdiff_t newpos = static_cast<std::ptrdiff_t>(pos + off);
0100       if((newpos < 0) || (newpos > size))
0101          return pos_type(off_type(-1));
0102       else
0103          this->setg(g, g + newpos, g + size);
0104       break;
0105    }
0106    default: ;
0107    }
0108 #ifdef BOOST_MSVC
0109 #pragma warning(push)
0110 #pragma warning(disable:4244)
0111 #endif
0112    return static_cast<pos_type>(this->gptr() - this->eback());
0113 #ifdef BOOST_MSVC
0114 #pragma warning(pop)
0115 #endif
0116 }
0117 
0118 template<class charT, class BufferT>
0119 typename basic_pointerbuf<charT, BufferT>::pos_type
0120 basic_pointerbuf<charT, BufferT>::seekpos(pos_type sp, ::std::ios_base::openmode which)
0121 {
0122    if(which & ::std::ios_base::out)
0123       return pos_type(off_type(-1));
0124    off_type size = static_cast<off_type>(this->egptr() - this->eback());
0125    charT* g = this->eback();
0126    if(off_type(sp) <= size)
0127    {
0128       this->setg(g, g + off_type(sp), g + size);
0129    }
0130    return pos_type(off_type(-1));
0131 }
0132 
0133 }} // namespace boost::detail
0134 
0135 #endif // BOOST_DETAIL_BASIC_POINTERBUF_HPP