Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:30:33

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 
0023 #include <streambuf>
0024 
0025 namespace boost { namespace detail {
0026 
0027 //
0028 // class basic_pointerbuf:
0029 // acts as a stream buffer which wraps around a pair of pointers:
0030 //
0031 template <class charT, class BufferT >
0032 class basic_pointerbuf : public BufferT {
0033 protected:
0034    typedef BufferT base_type;
0035    typedef basic_pointerbuf<charT, BufferT> this_type;
0036    typedef typename base_type::int_type int_type;
0037    typedef typename base_type::char_type char_type;
0038    typedef typename base_type::pos_type pos_type;
0039    typedef ::std::streamsize streamsize;
0040    typedef typename base_type::off_type off_type;
0041 
0042 public:
0043    basic_pointerbuf() : base_type() { this_type::setbuf(0, 0); }
0044    const charT* getnext() { return this->gptr(); }
0045 
0046     using base_type::pptr;
0047     using base_type::pbase;
0048 
0049 protected:
0050    // VC mistakenly assumes that `setbuf` and other functions are not referenced.
0051    // Marking those functions with `inline` suppresses the warnings.
0052    // There must be no harm from marking virtual functions as inline: inline virtual
0053    // call can be inlined ONLY when the compiler knows the "exact class".
0054    inline base_type* setbuf(char_type* s, streamsize n) BOOST_OVERRIDE;
0055    inline typename this_type::pos_type seekpos(pos_type sp, ::std::ios_base::openmode which) BOOST_OVERRIDE;
0056    inline typename this_type::pos_type seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which) BOOST_OVERRIDE;
0057 
0058 private:
0059    basic_pointerbuf& operator=(const basic_pointerbuf&);
0060    basic_pointerbuf(const basic_pointerbuf&);
0061 };
0062 
0063 template<class charT, class BufferT>
0064 BufferT*
0065 basic_pointerbuf<charT, BufferT>::setbuf(char_type* s, streamsize n)
0066 {
0067    this->setg(s, s, s + n);
0068    return this;
0069 }
0070 
0071 template<class charT, class BufferT>
0072 typename basic_pointerbuf<charT, BufferT>::pos_type
0073 basic_pointerbuf<charT, BufferT>::seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which)
0074 {
0075    typedef ::std::ios_base::seekdir cast_type;
0076 
0077    if(which & ::std::ios_base::out)
0078       return pos_type(off_type(-1));
0079    std::ptrdiff_t size = this->egptr() - this->eback();
0080    std::ptrdiff_t pos = this->gptr() - this->eback();
0081    charT* g = this->eback();
0082    switch(static_cast<cast_type>(way))
0083    {
0084    case ::std::ios_base::beg:
0085       if((off < 0) || (off > size))
0086          return pos_type(off_type(-1));
0087       else
0088          this->setg(g, g + off, g + size);
0089       break;
0090    case ::std::ios_base::end:
0091       if((off < 0) || (off > size))
0092          return pos_type(off_type(-1));
0093       else
0094          this->setg(g, g + size - off, g + size);
0095       break;
0096    case ::std::ios_base::cur:
0097    {
0098       std::ptrdiff_t newpos = static_cast<std::ptrdiff_t>(pos + off);
0099       if((newpos < 0) || (newpos > size))
0100          return pos_type(off_type(-1));
0101       else
0102          this->setg(g, g + newpos, g + size);
0103       break;
0104    }
0105    default: ;
0106    }
0107 #ifdef BOOST_MSVC
0108 #pragma warning(push)
0109 #pragma warning(disable:4244)
0110 #endif
0111    return static_cast<pos_type>(this->gptr() - this->eback());
0112 #ifdef BOOST_MSVC
0113 #pragma warning(pop)
0114 #endif
0115 }
0116 
0117 template<class charT, class BufferT>
0118 typename basic_pointerbuf<charT, BufferT>::pos_type
0119 basic_pointerbuf<charT, BufferT>::seekpos(pos_type sp, ::std::ios_base::openmode which)
0120 {
0121    if(which & ::std::ios_base::out)
0122       return pos_type(off_type(-1));
0123    off_type size = static_cast<off_type>(this->egptr() - this->eback());
0124    charT* g = this->eback();
0125    if(off_type(sp) <= size)
0126    {
0127       this->setg(g, g + off_type(sp), g + size);
0128    }
0129    return pos_type(off_type(-1));
0130 }
0131 
0132 }} // namespace boost::detail
0133 
0134 #endif // BOOST_DETAIL_BASIC_POINTERBUF_HPP