diff options
author | kan <kan@FreeBSD.org> | 2004-07-28 03:12:05 +0000 |
---|---|---|
committer | kan <kan@FreeBSD.org> | 2004-07-28 03:12:05 +0000 |
commit | 96bad46eee8bf907dceb152bbb9d128bed5a4956 (patch) | |
tree | 75ef0e6da73746d6849e25a0996ae34e1aeff51d /contrib/libstdc++/include/ext/stdio_filebuf.h | |
parent | 5e00ec74d8ce58f99801200d4d3d0412c7cc1b28 (diff) | |
download | FreeBSD-src-96bad46eee8bf907dceb152bbb9d128bed5a4956.zip FreeBSD-src-96bad46eee8bf907dceb152bbb9d128bed5a4956.tar.gz |
Gcc 3.4.2 20040728 C++ support bits.
Diffstat (limited to 'contrib/libstdc++/include/ext/stdio_filebuf.h')
-rw-r--r-- | contrib/libstdc++/include/ext/stdio_filebuf.h | 111 |
1 files changed, 52 insertions, 59 deletions
diff --git a/contrib/libstdc++/include/ext/stdio_filebuf.h b/contrib/libstdc++/include/ext/stdio_filebuf.h index 4c6bf90..cc22972 100644 --- a/contrib/libstdc++/include/ext/stdio_filebuf.h +++ b/contrib/libstdc++/include/ext/stdio_filebuf.h @@ -1,6 +1,6 @@ // File descriptor layer for filebuf -*- C++ -*- -// Copyright (C) 2002 Free Software Foundation, Inc. +// Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -31,10 +31,11 @@ * This file is a GNU extension to the Standard C++ Library. */ -#ifndef _EXT_STDIO_FILEBUF -#define _EXT_STDIO_FILEBUF +#ifndef _STDIO_FILEBUF_H +#define _STDIO_FILEBUF_H 1 #pragma GCC system_header + #include <fstream> namespace __gnu_cxx @@ -53,47 +54,47 @@ namespace __gnu_cxx { public: // Types: - typedef _CharT char_type; - typedef _Traits traits_type; - typedef typename traits_type::int_type int_type; - typedef typename traits_type::pos_type pos_type; - typedef typename traits_type::off_type off_type; + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; typedef std::size_t size_t; - - protected: - // Stack-based buffer for unbuffered input. - char_type _M_unbuf[4]; - + public: /** + * deferred initialization + */ + stdio_filebuf() : std::basic_filebuf<_CharT, _Traits>() {} + + /** * @param fd An open file descriptor. * @param mode Same meaning as in a standard filebuf. - * @param del Whether to close the file on destruction. - * @param size Optimal or preferred size of internal buffer, in bytes. + * @param size Optimal or preferred size of internal buffer, in chars. * * This constructor associates a file stream buffer with an open - * POSIX file descriptor. Iff @a del is true, then the associated - * file will be closed when the stdio_filebuf is closed/destroyed. + * POSIX file descriptor. The file descriptor will be automatically + * closed when the stdio_filebuf is closed/destroyed. */ - stdio_filebuf(int __fd, std::ios_base::openmode __mode, bool __del, - size_t __size); + stdio_filebuf(int __fd, std::ios_base::openmode __mode, + size_t __size = static_cast<size_t>(BUFSIZ)); /** * @param f An open @c FILE*. * @param mode Same meaning as in a standard filebuf. - * @param size Optimal or preferred size of internal buffer, in bytes. + * @param size Optimal or preferred size of internal buffer, in chars. * Defaults to system's @c BUFSIZ. * * This constructor associates a file stream buffer with an open * C @c FILE*. The @c FILE* will not be automatically closed when the * stdio_filebuf is closed/destroyed. */ - stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, + stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, size_t __size = static_cast<size_t>(BUFSIZ)); /** - * Possibly closes the external data stream, in the case of the file - * descriptor constructor and @c del @c == @c true. + * Closes the external data stream if the file descriptor constructor + * was used. */ virtual ~stdio_filebuf(); @@ -107,8 +108,17 @@ namespace __gnu_cxx * descriptor, so be careful. */ int - fd() - { return _M_file.fd(); } + fd() { return this->_M_file.fd(); } + + /** + * @return The underlying FILE*. + * + * This function can be used to access the underlying "C" file pointer. + * Note that there is no way for the library to track what you do + * with the file, so be careful. + */ + std::__c_file* + file() { return this->_M_file.file(); } }; template<typename _CharT, typename _Traits> @@ -117,53 +127,36 @@ namespace __gnu_cxx template<typename _CharT, typename _Traits> stdio_filebuf<_CharT, _Traits>:: - stdio_filebuf(int __fd, std::ios_base::openmode __mode, bool __del, - size_t __size) + stdio_filebuf(int __fd, std::ios_base::openmode __mode, size_t __size) { - _M_file.sys_open(__fd, __mode, __del); + this->_M_file.sys_open(__fd, __mode); if (this->is_open()) { - _M_mode = __mode; - if (__size > 0 && __size < 4) - { - // Specify not to use an allocated buffer. - _M_buf = _M_unbuf; - _M_buf_size = __size; - _M_buf_size_opt = 0; - } - else - { - _M_buf_size_opt = __size; - _M_allocate_internal_buffer(); - } - _M_set_indeterminate(); + this->_M_mode = __mode; + this->_M_buf_size = __size; + this->_M_allocate_internal_buffer(); + this->_M_reading = false; + this->_M_writing = false; + this->_M_set_buffer(-1); } } template<typename _CharT, typename _Traits> stdio_filebuf<_CharT, _Traits>:: - stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, + stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, size_t __size) { - _M_file.sys_open(__f, __mode); + this->_M_file.sys_open(__f, __mode); if (this->is_open()) { - _M_mode = __mode; - if (__size > 0 && __size < 4) - { - // Specify not to use an allocated buffer. - _M_buf = _M_unbuf; - _M_buf_size = __size; - _M_buf_size_opt = 0; - } - else - { - _M_buf_size_opt = __size; - _M_allocate_internal_buffer(); - } - _M_set_indeterminate(); + this->_M_mode = __mode; + this->_M_buf_size = __size; + this->_M_allocate_internal_buffer(); + this->_M_reading = false; + this->_M_writing = false; + this->_M_set_buffer(-1); } } } // namespace __gnu_cxx -#endif /* _EXT_STDIO_FILEBUF */ +#endif |