bufferstream.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 445 行 · 第 1/2 页
HPP
445 行
} if(out) { std::ptrdiff_t n = this->epptr() - this->pbase(); if(off < 0 || off > n) return pos_type(off_type(-1)); else { this->setp(this->pbase(), this->pbase() + n); this->pbump(off); } } return pos_type(off); } virtual pos_type seekpos(pos_type pos, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) { return seekoff(pos - pos_type(off_type(0)), std::ios_base::beg, mode); } private: std::ios_base::openmode m_mode; CharT * m_buffer; std::size_t m_length; /// @endcond};//!A basic_istream class that uses a fixed size character buffer//!as its formatting buffer.template <class CharT, class CharTraits>class basic_ibufferstream : public std::basic_istream<CharT, CharTraits>{ public: // Typedefs typedef typename std::basic_ios <CharT, CharTraits>::char_type char_type; typedef typename std::basic_ios<char_type, CharTraits>::int_type int_type; typedef typename std::basic_ios<char_type, CharTraits>::pos_type pos_type; typedef typename std::basic_ios<char_type, CharTraits>::off_type off_type; typedef typename std::basic_ios<char_type, CharTraits>::traits_type traits_type; private: typedef std::basic_ios<char_type, CharTraits> basic_ios_t; typedef std::basic_istream<char_type, CharTraits> base_t; public: //!Constructor. //!Does not throw. basic_ibufferstream(std::ios_base::openmode mode = std::ios_base::in) : basic_ios_t(), base_t(0), m_buf(mode | std::ios_base::in) { basic_ios_t::init(&m_buf); } //!Constructor. Assigns formatting buffer. //!Does not throw. basic_ibufferstream(const CharT *buffer, std::size_t length, std::ios_base::openmode mode = std::ios_base::in) : basic_ios_t(), base_t(0), m_buf(const_cast<CharT*>(buffer), length, mode | std::ios_base::in) { basic_ios_t::init(&m_buf); } ~basic_ibufferstream(){}; public: //!Returns the address of the stored //!stream buffer. basic_bufferbuf<CharT, CharTraits>* rdbuf() const { return const_cast<basic_bufferbuf<CharT, CharTraits>*>(&m_buf); } //!Returns the pointer and size of the internal buffer. //!Does not throw. std::pair<const CharT *, std::size_t> buffer() const { return m_buf.buffer(); } //!Sets the underlying buffer to a new value. Resets //!stream position. Does not throw. void buffer(const CharT *buffer, std::size_t length) { m_buf.buffer(const_cast<CharT*>(buffer), length); } /// @cond private: basic_bufferbuf<CharT, CharTraits> m_buf; /// @endcond};//!A basic_ostream class that uses a fixed size character buffer//!as its formatting buffer.template <class CharT, class CharTraits>class basic_obufferstream : public std::basic_ostream<CharT, CharTraits>{ public: typedef typename std::basic_ios <CharT, CharTraits>::char_type char_type; typedef typename std::basic_ios<char_type, CharTraits>::int_type int_type; typedef typename std::basic_ios<char_type, CharTraits>::pos_type pos_type; typedef typename std::basic_ios<char_type, CharTraits>::off_type off_type; typedef typename std::basic_ios<char_type, CharTraits>::traits_type traits_type; /// @cond private: typedef std::basic_ios<char_type, CharTraits> basic_ios_t; typedef std::basic_ostream<char_type, CharTraits> base_t; /// @endcond public: //!Constructor. //!Does not throw. basic_obufferstream(std::ios_base::openmode mode = std::ios_base::out) : basic_ios_t(), base_t(0), m_buf(mode | std::ios_base::out) { basic_ios_t::init(&m_buf); } //!Constructor. Assigns formatting buffer. //!Does not throw. basic_obufferstream(CharT *buffer, std::size_t length, std::ios_base::openmode mode = std::ios_base::out) : basic_ios_t(), base_t(0), m_buf(buffer, length, mode | std::ios_base::out) { basic_ios_t::init(&m_buf); } ~basic_obufferstream(){} public: //!Returns the address of the stored //!stream buffer. basic_bufferbuf<CharT, CharTraits>* rdbuf() const { return const_cast<basic_bufferbuf<CharT, CharTraits>*>(&m_buf); } //!Returns the pointer and size of the internal buffer. //!Does not throw. std::pair<CharT *, std::size_t> buffer() const { return m_buf.buffer(); } //!Sets the underlying buffer to a new value. Resets //!stream position. Does not throw. void buffer(CharT *buffer, std::size_t length) { m_buf.buffer(buffer, length); } /// @cond private: basic_bufferbuf<CharT, CharTraits> m_buf; /// @endcond};//!A basic_iostream class that uses a fixed size character buffer//!as its formatting buffer.template <class CharT, class CharTraits>class basic_bufferstream : public std::basic_iostream<CharT, CharTraits>{ public: // Typedefs typedef typename std::basic_ios <CharT, CharTraits>::char_type char_type; typedef typename std::basic_ios<char_type, CharTraits>::int_type int_type; typedef typename std::basic_ios<char_type, CharTraits>::pos_type pos_type; typedef typename std::basic_ios<char_type, CharTraits>::off_type off_type; typedef typename std::basic_ios<char_type, CharTraits>::traits_type traits_type; /// @cond private: typedef std::basic_ios<char_type, CharTraits> basic_ios_t; typedef std::basic_iostream<char_type, CharTraits> base_t; /// @endcond public: //!Constructor. //!Does not throw. basic_bufferstream(std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) : basic_ios_t(), base_t(0), m_buf(mode) { basic_ios_t::init(&m_buf); } //!Constructor. Assigns formatting buffer. //!Does not throw. basic_bufferstream(CharT *buffer, std::size_t length, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) : basic_ios_t(), base_t(0), m_buf(buffer, length, mode) { basic_ios_t::init(&m_buf); } ~basic_bufferstream(){} public: //!Returns the address of the stored //!stream buffer. basic_bufferbuf<CharT, CharTraits>* rdbuf() const { return const_cast<basic_bufferbuf<CharT, CharTraits>*>(&m_buf); } //!Returns the pointer and size of the internal buffer. //!Does not throw. std::pair<CharT *, std::size_t> buffer() const { return m_buf.buffer(); } //!Sets the underlying buffer to a new value. Resets //!stream position. Does not throw. void buffer(CharT *buffer, std::size_t length) { m_buf.buffer(buffer, length); } /// @cond private: basic_bufferbuf<CharT, CharTraits> m_buf; /// @endcond};//Some typedefs to simplify usagetypedef basic_bufferbuf<char> bufferbuf;typedef basic_bufferstream<char> bufferstream;typedef basic_ibufferstream<char> ibufferstream;typedef basic_obufferstream<char> obufferstream;typedef basic_bufferbuf<wchar_t> wbufferbuf;typedef basic_bufferstream<wchar_t> wbufferstream;typedef basic_ibufferstream<wchar_t> wibufferstream;typedef basic_obufferstream<wchar_t> wobufferstream;}} //namespace boost { namespace interprocess {#include <boost/interprocess/detail/config_end.hpp>#endif /* BOOST_INTERPROCESS_BUFFERSTREAM_HPP */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?