📄 std_streambuf.h
字号:
{ _M_in_beg = __gbeg; _M_in_cur = __gnext; _M_in_end = __gend; if (!(_M_mode & ios_base::in) && __gbeg && __gnext && __gend) _M_mode = _M_mode | ios_base::in; } // [27.5.2.3.2] put area access //@{ /** * @brief Access to the put area. * * These functions are only available to other protected functions, * including derived classes. * * - pbase() returns the beginning pointer for the output sequence * - pptr() returns the next pointer for the output sequence * - epptr() returns the end pointer for the output sequence */ char_type* pbase() const { return _M_out_beg; } char_type* pptr() const { return _M_out_cur; } char_type* epptr() const { return _M_out_end; } //@} /** * @brief Moving the write position. * @param n The delta by which to move. * * This just advances the write position without returning any data. */ void pbump(int __n) { _M_out_cur += __n; } /** * @brief Setting the three write area pointers. * @param pbeg A pointer. * @param pend A pointer. * @post @a pbeg == @c pbase(), @a pbeg == @c pptr(), and * @a pend == @c epptr() */ void setp(char_type* __pbeg, char_type* __pend) { _M_out_beg = _M_out_cur = __pbeg; _M_out_end = __pend; if (!(_M_mode & ios_base::out) && __pbeg && __pend) _M_mode = _M_mode | ios_base::out; } // [27.5.2.4] virtual functions // [27.5.2.4.1] locales /** * @brief Changes translations. * @param loc A new locale. * * Translations done during I/O which depend on the current locale * are changed by this call. The standard adds, "Between invocations * of this function a class derived from streambuf can safely cache * results of calls to locale functions and to members of facets * so obtained." * * @note Base class version does nothing. */ virtual void imbue(const locale&) { } // [27.5.2.4.2] buffer management and positioning /** * @brief Maniuplates the buffer. * * Each derived class provides its own appropriate behavior. See * the next-to-last paragraph of * http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#2 for * more on this function. * * @note Base class version does nothing, returns @c this. */ virtual basic_streambuf<char_type,_Traits>* setbuf(char_type*, streamsize) { return this; } /** * @brief Alters the stream positions. * * Each derived class provides its own appropriate behavior. * @note Base class version does nothing, returns a @c pos_type * that represents an invalid stream position. */ virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out) { return pos_type(off_type(-1)); } /** * @brief Alters the stream positions. * * Each derived class provides its own appropriate behavior. * @note Base class version does nothing, returns a @c pos_type * that represents an invalid stream position. */ virtual pos_type seekpos(pos_type, ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out) { return pos_type(off_type(-1)); } /** * @brief Synchronizes the buffer arrays with the controlled sequences. * @return -1 on failure. * * Each derived class provides its own appropriate behavior, * including the definition of "failure". * @note Base class version does nothing, returns zero. */ virtual int sync() { return 0; } // [27.5.2.4.3] get area /** * @brief Investigating the data available. * @return An estimate of the number of characters available in the * input sequence, or -1. * * "If it returns a positive value, then successive calls to * @c underflow() will not return @c traits::eof() until at least that * number of characters have been supplied. If @c showmanyc() * returns -1, then calls to @c underflow() or @c uflow() will fail." * [27.5.2.4.3]/1 * * @note Base class version does nothing, returns zero. * @note The standard adds that "the intention is not only that the * calls [to underflow or uflow] will not return @c eof() but * that they will return "immediately". * @note The standard adds that "the morphemes of @c showmanyc are * "es-how-many-see", not "show-manic". */ virtual streamsize showmanyc() { return 0; } /** * @brief Multiple character extraction. * @param s A buffer area. * @param n Maximum number of characters to assign. * @return The number of characters assigned. * * Fills @a s[0] through @a s[n-1] with characters from the input * sequence, as if by @c sbumpc(). Stops when either @a n characters * have been copied, or when @c traits::eof() would be copied. * * It is expected that derived classes provide a more efficient * implementation by overriding this definition. */ virtual streamsize xsgetn(char_type* __s, streamsize __n); /** * @brief Fetches more data from the controlled sequence. * @return The first character from the <em>pending sequence</em>. * * Informally, this function is called when the input buffer is * exhausted (or does not exist, as buffering need not actually be * done). If a buffer exists, it is "refilled". In either case, the * next available character is returned, or @c traits::eof() to * indicate a null pending sequence. * * For a formal definiton of the pending sequence, see a good text * such as Langer & Kreft, or [27.5.2.4.3]/7-14. * * A functioning input streambuf can be created by overriding only * this function (no buffer area will be used). For an example, see * http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#6 * * @note Base class version does nothing, returns eof(). */ virtual int_type underflow() { return traits_type::eof(); } /** * @brief Fetches more data from the controlled sequence. * @return The first character from the <em>pending sequence</em>. * * Informally, this function does the same thing as @c underflow(), * and in fact is required to call that function. It also returns * the new character, like @c underflow() does. However, this * function also moves the read position forward by one. */ virtual int_type uflow() { int_type __ret = traits_type::eof(); bool __testeof = traits_type::eq_int_type(this->underflow(), __ret); bool __testpending = _M_in_cur && _M_in_cur < _M_in_end; if (!__testeof && __testpending) { __ret = traits_type::to_int_type(*_M_in_cur); ++_M_in_cur; if (_M_buf_unified && _M_mode & ios_base::out) ++_M_out_cur; } return __ret; } // [27.5.2.4.4] putback /** * @brief Tries to back up the input sequence. * @param c The character to be inserted back into the sequence. * @return eof() on failure, "some other value" on success * @post The constraints of @c gptr(), @c eback(), and @c pptr() * are the same as for @c underflow(). * * @note Base class version does nothing, returns eof(). */ virtual int_type pbackfail(int_type /* __c */ = traits_type::eof()) { return traits_type::eof(); } // Put area: /** * @brief Multiple character insertion. * @param s A buffer area. * @param n Maximum number of characters to write. * @return The number of characters written. * * Writes @a s[0] through @a s[n-1] to the output sequence, as if * by @c sputc(). Stops when either @a n characters have been * copied, or when @c sputc() would return @c traits::eof(). * * It is expected that derived classes provide a more efficient * implementation by overriding this definition. */ virtual streamsize xsputn(const char_type* __s, streamsize __n); /** * @brief Consumes data from the buffer; writes to the * controlled sequence. * @param c An additional character to consume. * @return eof() to indicate failure, something else (usually * @a c, or not_eof()) * * Informally, this function is called when the output buffer is full * (or does not exist, as buffering need not actually be done). If a * buffer exists, it is "consumed", with "some effect" on the * controlled sequence. (Typically, the buffer is written out to the * sequence verbatim.) In either case, the character @a c is also * written out, if @a c is not @c eof(). * * For a formal definiton of this function, see a good text * such as Langer & Kreft, or [27.5.2.4.5]/3-7. * * A functioning output streambuf can be created by overriding only * this function (no buffer area will be used). * * @note Base class version does nothing, returns eof(). */ virtual int_type overflow(int_type /* __c */ = traits_type::eof()) { return traits_type::eof(); }#ifdef _GLIBCPP_DEPRECATED // Annex D.6 public: /** * @brief Tosses a character. * * Advances the read pointer, ignoring the character that would have * been read. * * See http://gcc.gnu.org/ml/libstdc++/2002-05/msg00168.html * * @note This function has been deprecated by the standard. You * must define @c _GLIBCPP_DEPRECATED to make this visible; see * c++config.h. */ void stossc() { if (_M_in_cur < _M_in_end) ++_M_in_cur; else this->uflow(); }#endif#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS // Side effect of DR 50. private: basic_streambuf(const __streambuf_type&) { }; __streambuf_type& operator=(const __streambuf_type&) { return *this; };#endif };} // namespace std#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT# define export#endif#ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS#include <bits/streambuf.tcc>#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -