File indexing completed on 2025-01-18 09:30:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_DETAIL_BASIC_POINTERBUF_HPP
0014 #define BOOST_DETAIL_BASIC_POINTERBUF_HPP
0015
0016
0017 #if defined(_MSC_VER)
0018 # pragma once
0019 #endif
0020
0021 #include "boost/config.hpp"
0022 #include <streambuf>
0023
0024 namespace boost { namespace detail {
0025
0026
0027
0028
0029
0030 template <class charT, class BufferT >
0031 class basic_pointerbuf : public BufferT {
0032 protected:
0033 typedef BufferT base_type;
0034 typedef basic_pointerbuf<charT, BufferT> this_type;
0035 typedef typename base_type::int_type int_type;
0036 typedef typename base_type::char_type char_type;
0037 typedef typename base_type::pos_type pos_type;
0038 typedef ::std::streamsize streamsize;
0039 typedef typename base_type::off_type off_type;
0040
0041 public:
0042 basic_pointerbuf() : base_type() { this_type::setbuf(0, 0); }
0043 const charT* getnext() { return this->gptr(); }
0044
0045 using base_type::pptr;
0046 using base_type::pbase;
0047
0048 protected:
0049
0050
0051
0052
0053 inline base_type* setbuf(char_type* s, streamsize n) BOOST_OVERRIDE;
0054 inline typename this_type::pos_type seekpos(pos_type sp, ::std::ios_base::openmode which) BOOST_OVERRIDE;
0055 inline typename this_type::pos_type seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which) BOOST_OVERRIDE;
0056
0057 private:
0058 basic_pointerbuf& operator=(const basic_pointerbuf&);
0059 basic_pointerbuf(const basic_pointerbuf&);
0060 };
0061
0062 template<class charT, class BufferT>
0063 BufferT*
0064 basic_pointerbuf<charT, BufferT>::setbuf(char_type* s, streamsize n)
0065 {
0066 this->setg(s, s, s + n);
0067 return this;
0068 }
0069
0070 template<class charT, class BufferT>
0071 typename basic_pointerbuf<charT, BufferT>::pos_type
0072 basic_pointerbuf<charT, BufferT>::seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which)
0073 {
0074 typedef typename boost::int_t<sizeof(way) * CHAR_BIT>::least cast_type;
0075
0076 if(which & ::std::ios_base::out)
0077 return pos_type(off_type(-1));
0078 std::ptrdiff_t size = this->egptr() - this->eback();
0079 std::ptrdiff_t pos = this->gptr() - this->eback();
0080 charT* g = this->eback();
0081 switch(static_cast<cast_type>(way))
0082 {
0083 case ::std::ios_base::beg:
0084 if((off < 0) || (off > size))
0085 return pos_type(off_type(-1));
0086 else
0087 this->setg(g, g + off, g + size);
0088 break;
0089 case ::std::ios_base::end:
0090 if((off < 0) || (off > size))
0091 return pos_type(off_type(-1));
0092 else
0093 this->setg(g, g + size - off, g + size);
0094 break;
0095 case ::std::ios_base::cur:
0096 {
0097 std::ptrdiff_t newpos = static_cast<std::ptrdiff_t>(pos + off);
0098 if((newpos < 0) || (newpos > size))
0099 return pos_type(off_type(-1));
0100 else
0101 this->setg(g, g + newpos, g + size);
0102 break;
0103 }
0104 default: ;
0105 }
0106 #ifdef BOOST_MSVC
0107 #pragma warning(push)
0108 #pragma warning(disable:4244)
0109 #endif
0110 return static_cast<pos_type>(this->gptr() - this->eback());
0111 #ifdef BOOST_MSVC
0112 #pragma warning(pop)
0113 #endif
0114 }
0115
0116 template<class charT, class BufferT>
0117 typename basic_pointerbuf<charT, BufferT>::pos_type
0118 basic_pointerbuf<charT, BufferT>::seekpos(pos_type sp, ::std::ios_base::openmode which)
0119 {
0120 if(which & ::std::ios_base::out)
0121 return pos_type(off_type(-1));
0122 off_type size = static_cast<off_type>(this->egptr() - this->eback());
0123 charT* g = this->eback();
0124 if(off_type(sp) <= size)
0125 {
0126 this->setg(g, g + off_type(sp), g + size);
0127 }
0128 return pos_type(off_type(-1));
0129 }
0130
0131 }}
0132
0133 #endif