diff --git a/Release/include/cpprest/streams.h b/Release/include/cpprest/streams.h index b6c3864028..cfb03fae0b 100644 --- a/Release/include/cpprest/streams.h +++ b/Release/include/cpprest/streams.h @@ -140,20 +140,22 @@ class basic_ostream } /// - /// Close the stream, preventing further write operations. + /// Close the stream, preventing further write [or read] operations. /// - pplx::task close() const + /// The opening mode of the file + pplx::task close(std::ios_base::openmode mode = std::ios_base::out) const { - return is_valid() ? helper()->m_buffer.close(std::ios_base::out) : pplx::task_from_result(); + return is_valid() ? helper()->m_buffer.close(mode) : pplx::task_from_result(); } /// - /// Close the stream with exception, preventing further write operations. + /// Close the stream with exception, preventing further write [or read] operations. /// /// Pointer to the exception. - pplx::task close(std::exception_ptr eptr) const + /// The opening mode of the file + pplx::task close(std::exception_ptr eptr, std::ios_base::openmode mode = std::ios_base::out) const { - return is_valid() ? helper()->m_buffer.close(std::ios_base::out, eptr) : pplx::task_from_result(); + return is_valid() ? helper()->m_buffer.close(mode, eptr) : pplx::task_from_result(); } /// @@ -325,36 +327,39 @@ class basic_ostream } /// - /// Seeks to the specified write position. + /// Seeks to the specified write[or read] position. /// /// An offset relative to the beginning of the stream. + /// The opening mode of the file /// The new position in the stream. - pos_type seek(pos_type pos) const + pos_type seek(pos_type pos, std::ios_base::openmode mode = std::ios_base::out) const { _verify_and_throw(details::_out_stream_msg); - return helper()->m_buffer.seekpos(pos, std::ios_base::out); + return helper()->m_buffer.seekpos(pos, mode); } /// - /// Seeks to the specified write position. + /// Seeks to the specified write[or read] position. /// - /// An offset relative to the beginning, current write position, or the end of the stream. + /// An offset relative to the beginning, current write[or read] position, or the end of the stream. /// The starting point (beginning, current, end) for the seek. + /// The opening mode of the file /// The new position in the stream. - pos_type seek(off_type off, std::ios_base::seekdir way) const + pos_type seek(off_type off, std::ios_base::seekdir way, std::ios_base::openmode mode = std::ios_base::out) const { _verify_and_throw(details::_out_stream_msg); - return helper()->m_buffer.seekoff(off, way, std::ios_base::out); + return helper()->m_buffer.seekoff(off, way, mode); } /// - /// Get the current write position, i.e. the offset from the beginning of the stream. + /// Get the current write[or read] position, i.e. the offset from the beginning of the stream. /// - /// The current write position. - pos_type tell() const + /// The opening mode of the file + /// The current write[or read] position. + pos_type tell(std::ios_base::openmode mode = std::ios_base::out) const { _verify_and_throw(details::_out_stream_msg); - return helper()->m_buffer.getpos(std::ios_base::out); + return helper()->m_buffer.getpos(mode); } /// @@ -379,7 +384,18 @@ class basic_ostream /// Test whether the stream is open for writing. /// /// true if the stream is open for writing, false otherwise. - bool is_open() const { return is_valid() && m_helper->m_buffer.can_write(); } + bool is_open(std::ios_base::openmode mode = std::ios_base::out) const + { + bool is_able = false; + if (mode == std::ios_base::out) + is_able = m_helper->m_buffer.can_write(); + else if (mode == std::ios_base::in) + is_able = m_helper->m_buffer.can_read(); + else + is_able = m_helper->m_buffer.can_read() && m_helper->m_buffer.can_write(); + + return is_valid() && is_able; + } /// /// Get the underlying stream buffer.