C++ Rest SDK
The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Classes | Public Types | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
Concurrency::streams::details::basic_file_buffer< _CharType > Class Template Reference

Private stream buffer implementation for file streams. The class itself should not be used in application code, it is used by the stream definitions farther down in the header file. More...

#include <filestream.h>

Inheritance diagram for Concurrency::streams::details::basic_file_buffer< _CharType >:
Concurrency::streams::details::streambuf_state_manager< _CharType > Concurrency::streams::details::basic_streambuf< _CharType >

Public Types

typedef basic_streambuf< _CharType >::traits traits
 
typedef basic_streambuf< _CharType >::int_type int_type
 
typedef basic_streambuf< _CharType >::pos_type pos_type
 
typedef basic_streambuf< _CharType >::off_type off_type
 
- Public Types inherited from Concurrency::streams::details::streambuf_state_manager< _CharType >
typedef details::basic_streambuf< _CharType >::traits traits
 
typedef details::basic_streambuf< _CharType >::int_type int_type
 
typedef details::basic_streambuf< _CharType >::pos_type pos_type
 
typedef details::basic_streambuf< _CharType >::off_type off_type
 
- Public Types inherited from Concurrency::streams::details::basic_streambuf< _CharType >
typedef _CharType char_type
 
typedef ::concurrency::streams::char_traits< _CharType > traits
 
typedef traits::int_type int_type
 
typedef traits::pos_type pos_type
 
typedef traits::off_type off_type
 

Protected Member Functions

virtual bool can_seek () const
 can_seek is used to determine whether a stream buffer supports seeking. More...
 
virtual bool has_size () const
 has_size is used to determine whether a stream buffer supports size(). More...
 
virtual utility::size64_t size () const
 Gets the size of the stream, if known. Calls to has_size will determine whether the result of size can be relied on. More...
 
virtual size_t buffer_size (std::ios_base::openmode direction=std::ios_base::in) const
 Gets the stream buffer size, if one has been set. More...
 
virtual void set_buffer_size (size_t size, std::ios_base::openmode direction=std::ios_base::in)
 Sets the stream buffer implementation to buffer or not buffer. More...
 
virtual size_t in_avail () const
 For any input stream, in_avail returns the number of characters that are immediately available to be consumed without blocking. May be used in conjunction with <cref="::sbumpc method"/> to read data without incurring the overhead of using tasks. More...
 
size_t _in_avail_unprot () const
 
_file_info_close_stream ()
 
void _invoke_parent_close_read ()
 
pplx::task< void > _close_read ()
 The real read head close operation, implementation should override it if there is any resource to be released. More...
 
pplx::task< void > _close_write ()
 The real write head close operation, implementation should override it if there is any resource to be released. More...
 
virtual pplx::task< int_type > _putc (_CharType ch)
 Writes a single byte to an output stream. More...
 
_CharType * _alloc (size_t)
 Allocates a contiguous memory block and returns it. More...
 
void _commit (size_t)
 Submits a block already allocated by the stream buffer. More...
 
virtual bool acquire (_Out_ _CharType *&ptr, _Out_ size_t &count)
 Gets a pointer to the next already allocated contiguous block of data. More...
 
virtual void release (_Out_writes_(count) _CharType *, _In_ size_t count)
 Releases a block of data acquired using ::acquire method. This frees the stream buffer to de-allocate the memory, if it so desires. Move the read position ahead by the count. More...
 
virtual pplx::task< size_t > _putn (const _CharType *ptr, size_t count)
 Writes a number of characters to the stream. More...
 
virtual pplx::task< size_t > _putn (const _CharType *ptr, size_t count, bool copy)
 
virtual pplx::task< int_type > _bumpc ()
 Reads a single byte from the stream and advance the read position. More...
 
virtual int_type _sbumpc ()
 Reads a single byte from the stream and advance the read position. More...
 
pplx::task< int_type > _getcImpl ()
 
pplx::task< int_type > _getc ()
 Reads a single byte from the stream without advancing the read position. More...
 
int_type _sgetc ()
 Reads a single byte from the stream without advancing the read position. More...
 
virtual pplx::task< int_type > _nextc ()
 Advances the read position, then return the next character without advancing again. More...
 
virtual pplx::task< int_type > _ungetc ()
 Retreats the read position, then return the current character without advancing. More...
 
virtual pplx::task< size_t > _getn (_Out_writes_(count) _CharType *ptr, _In_ size_t count)
 Reads up to a given number of characters from the stream. More...
 
size_t _sgetn (_Out_writes_(count) _CharType *ptr, _In_ size_t count)
 Reads up to a given number of characters from the stream. More...
 
virtual size_t _scopy (_CharType *, size_t)
 Copies up to a given number of characters from the stream. More...
 
virtual pos_type getpos (std::ios_base::openmode mode) const
 Gets the current read or write position in the stream. More...
 
virtual pos_type seekpos (pos_type pos, std::ios_base::openmode mode)
 Seeks to the given position. More...
 
virtual pos_type seekoff (off_type offset, std::ios_base::seekdir way, std::ios_base::openmode mode)
 Seeks to a position given by a relative offset. More...
 
virtual pplx::task< bool > _sync ()
 For output streams, flush any internally buffered data to the underlying medium. More...
 
- Protected Member Functions inherited from Concurrency::streams::details::streambuf_state_manager< _CharType >
virtual size_t _scopy (_Out_writes_(count) _CharType *ptr, _In_ size_t count)=0
 
 streambuf_state_manager (std::ios_base::openmode mode)
 

Static Protected Member Functions

static pplx::task< void > _close_file (_In_ _file_info *fileInfo)
 

Friends

template<typename _CharType1 >
class ::concurrency::streams::file_buffer
 

Additional Inherited Members

- Public Member Functions inherited from Concurrency::streams::details::streambuf_state_manager< _CharType >
virtual bool can_read () const
 can_read is used to determine whether a stream buffer will support read operations (get). More...
 
virtual bool can_write () const
 can_write is used to determine whether a stream buffer will support write operations (put). More...
 
virtual bool is_open () const
 Checks if the stream buffer is open. More...
 
virtual pplx::task< void > close (std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out)
 Closes the stream buffer, preventing further read or write operations. More...
 
virtual pplx::task< void > close (std::ios_base::openmode mode, std::exception_ptr eptr)
 Closes the stream buffer with an exception. More...
 
virtual bool is_eof () const
 is_eof is used to determine whether a read head has reached the end of the buffer. More...
 
virtual pplx::task< int_type > putc (_CharType ch)
 Writes a single character to the stream. More...
 
virtual pplx::task< size_t > putn (const _CharType *ptr, size_t count)
 Writes a number of characters to the stream. More...
 
virtual pplx::task< size_t > putn_nocopy (const _CharType *ptr, size_t count)
 Writes a number of characters to the stream. Note: callers must make sure the data to be written is valid until the returned task completes. More...
 
virtual pplx::task< int_type > bumpc ()
 Reads a single character from the stream and advances the read position. More...
 
virtual int_type sbumpc ()
 Reads a single character from the stream and advances the read position. More...
 
virtual pplx::task< int_type > getc ()
 Reads a single character from the stream without advancing the read position. More...
 
virtual int_type sgetc ()
 Reads a single character from the stream without advancing the read position. More...
 
virtual pplx::task< int_type > nextc ()
 Advances the read position, then returns the next character without advancing again. More...
 
virtual pplx::task< int_type > ungetc ()
 Retreats the read position, then returns the current character without advancing. More...
 
virtual pplx::task< size_t > getn (_Out_writes_(count) _CharType *ptr, _In_ size_t count)
 Reads up to a given number of characters from the stream. More...
 
virtual size_t scopy (_Out_writes_(count) _CharType *ptr, _In_ size_t count)
 Copies up to a given number of characters from the stream, synchronously. More...
 
virtual pplx::task< void > sync ()
 For output streams, flush any internally buffered data to the underlying medium. More...
 
virtual std::exception_ptr exception () const
 Retrieves the stream buffer exception_ptr if it has been set. More...
 
_CharType * alloc (size_t count)
 Allocates a contiguous memory block and returns it. More...
 
void commit (size_t count)
 Submits a block already allocated by the stream buffer. More...
 
virtual bool acquire (_Out_writes_(count) _CharType *&ptr, _In_ size_t &count)=0
 
- Public Member Functions inherited from Concurrency::streams::details::basic_streambuf< _CharType >
virtual ~basic_streambuf ()
 Virtual constructor for stream buffers. More...
 
virtual _CharType * alloc (_In_ size_t count)=0
 Allocates a contiguous memory block and returns it. More...
 
virtual void commit (_In_ size_t count)=0
 Submits a block already allocated by the stream buffer. More...
 
- Protected Attributes inherited from Concurrency::streams::details::streambuf_state_manager< _CharType >
std::exception_ptr m_currentException
 
bool m_stream_can_read
 
bool m_stream_can_write
 
bool m_stream_read_eof
 
bool m_alloced
 

Detailed Description

template<typename _CharType>
class Concurrency::streams::details::basic_file_buffer< _CharType >

Private stream buffer implementation for file streams. The class itself should not be used in application code, it is used by the stream definitions farther down in the header file.

Member Function Documentation

template<typename _CharType >
_CharType* Concurrency::streams::details::basic_file_buffer< _CharType >::_alloc ( size_t  )
inlineprotectedvirtual

Allocates a contiguous memory block and returns it.

Parameters
countThe number of characters to allocate.
Returns
A pointer to a block to write to, null if the stream buffer implementation does not support alloc/commit.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual pplx::task<int_type> Concurrency::streams::details::basic_file_buffer< _CharType >::_bumpc ( )
inlineprotectedvirtual

Reads a single byte from the stream and advance the read position.

Returns
A task that holds the value of the byte read. This is EOF if the read fails.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
pplx::task<void> Concurrency::streams::details::basic_file_buffer< _CharType >::_close_read ( )
inlineprotectedvirtual

The real read head close operation, implementation should override it if there is any resource to be released.

Reimplemented from Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
pplx::task<void> Concurrency::streams::details::basic_file_buffer< _CharType >::_close_write ( )
inlineprotectedvirtual

The real write head close operation, implementation should override it if there is any resource to be released.

Reimplemented from Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
void Concurrency::streams::details::basic_file_buffer< _CharType >::_commit ( size_t  )
inlineprotectedvirtual

Submits a block already allocated by the stream buffer.

Parameters
ptrCount of characters to be commited.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
pplx::task<int_type> Concurrency::streams::details::basic_file_buffer< _CharType >::_getc ( )
inlineprotectedvirtual

Reads a single byte from the stream without advancing the read position.

Returns
The value of the byte. EOF if the read fails.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual pplx::task<size_t> Concurrency::streams::details::basic_file_buffer< _CharType >::_getn ( _Out_writes_(count) _CharType *  ptr,
_In_ size_t  count 
)
inlineprotectedvirtual

Reads up to a given number of characters from the stream.

Parameters
ptrThe address of the target memory area
countThe maximum number of characters to read
Returns
A task that holds the number of characters read. This number is O if the end of the stream is reached, EOF if there is some error.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual pplx::task<int_type> Concurrency::streams::details::basic_file_buffer< _CharType >::_nextc ( )
inlineprotectedvirtual

Advances the read position, then return the next character without advancing again.

Returns
A task that holds the value of the byte, which is EOF if the read fails.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual pplx::task<int_type> Concurrency::streams::details::basic_file_buffer< _CharType >::_putc ( _CharType  ch)
inlineprotectedvirtual

Writes a single byte to an output stream.

Parameters
chThe byte to write
Returns
A task that holds the value of the byte written. This is EOF if the write operation fails.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual pplx::task<size_t> Concurrency::streams::details::basic_file_buffer< _CharType >::_putn ( const _CharType *  ptr,
size_t  count 
)
inlineprotectedvirtual

Writes a number of characters to the stream.

Parameters
ptrA pointer to the block of data to be written.
countThe number of characters to write.
Returns
A task that holds the number of characters actually written, either 'count' or 0.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual int_type Concurrency::streams::details::basic_file_buffer< _CharType >::_sbumpc ( )
inlineprotectedvirtual

Reads a single byte from the stream and advance the read position.

Returns
The value of the byte. EOF if the read fails. ::requires_async method if an asynchronous read is required

This is a synchronous operation, but is guaranteed to never block.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual size_t Concurrency::streams::details::basic_file_buffer< _CharType >::_scopy ( _CharType *  ,
size_t   
)
inlineprotectedvirtual

Copies up to a given number of characters from the stream.

Parameters
ptrThe address of the target memory area
countThe maximum number of characters to copy
Returns
The number of characters copied. O if the end of the stream is reached or an asynchronous read is required.

This is a synchronous operation, but is guaranteed to never block.

template<typename _CharType >
int_type Concurrency::streams::details::basic_file_buffer< _CharType >::_sgetc ( )
inlineprotectedvirtual

Reads a single byte from the stream without advancing the read position.

Returns
The value of the byte. EOF if the read fails. ::requires_async method if an asynchronous read is required

This is a synchronous operation, but is guaranteed to never block.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
size_t Concurrency::streams::details::basic_file_buffer< _CharType >::_sgetn ( _Out_writes_(count) _CharType *  ptr,
_In_ size_t  count 
)
inlineprotected

Reads up to a given number of characters from the stream.

Parameters
ptrThe address of the target memory area
countThe maximum number of characters to read
Returns
The number of characters read. O if the end of the stream is reached or an asynchronous read is required.

This is a synchronous operation, but is guaranteed to never block.

template<typename _CharType >
virtual pplx::task<bool> Concurrency::streams::details::basic_file_buffer< _CharType >::_sync ( )
inlineprotectedvirtual

For output streams, flush any internally buffered data to the underlying medium.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual pplx::task<int_type> Concurrency::streams::details::basic_file_buffer< _CharType >::_ungetc ( )
inlineprotectedvirtual

Retreats the read position, then return the current character without advancing.

Returns
A task that holds the value of the byte. The value is EOF if the read fails, requires_async if an asynchronous read is required

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual bool Concurrency::streams::details::basic_file_buffer< _CharType >::acquire ( _Out_ _CharType *&  ptr,
_Out_ size_t &  count 
)
inlineprotectedvirtual

Gets a pointer to the next already allocated contiguous block of data.

Parameters
ptrA reference to a pointer variable that will hold the address of the block on success.
countThe number of contiguous characters available at the address in 'ptr.'
Returns
true if the operation succeeded, false otherwise.

A return of false does not necessarily indicate that a subsequent read operation would fail, only that there is no block to return immediately or that the stream buffer does not support the operation. The stream buffer may not de-allocate the block until ::release method is called. If the end of the stream is reached, the function will return true, a null pointer, and a count of zero; a subsequent read will not succeed.

Implements Concurrency::streams::details::basic_streambuf< _CharType >.

template<typename _CharType >
virtual size_t Concurrency::streams::details::basic_file_buffer< _CharType >::buffer_size ( std::ios_base::openmode  direction = std::ios_base::in) const
inlineprotectedvirtual

Gets the stream buffer size, if one has been set.

Parameters
directionThe direction of buffering (in or out)

An implementation that does not support buffering will always return '0'.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual bool Concurrency::streams::details::basic_file_buffer< _CharType >::can_seek ( ) const
inlineprotectedvirtual

can_seek is used to determine whether a stream buffer supports seeking.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual pos_type Concurrency::streams::details::basic_file_buffer< _CharType >::getpos ( std::ios_base::openmode  mode) const
inlineprotectedvirtual

Gets the current read or write position in the stream.

Parameters
directionThe I/O direction to seek (see remarks)
Returns
The current position. EOF if the operation fails.

Some streams may have separate write and read cursors. For such streams, the direction parameter defines whether to move the read or the write cursor.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual bool Concurrency::streams::details::basic_file_buffer< _CharType >::has_size ( ) const
inlineprotectedvirtual

has_size is used to determine whether a stream buffer supports size().

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual size_t Concurrency::streams::details::basic_file_buffer< _CharType >::in_avail ( ) const
inlineprotectedvirtual

For any input stream, in_avail returns the number of characters that are immediately available to be consumed without blocking. May be used in conjunction with <cref="::sbumpc method"/> to read data without incurring the overhead of using tasks.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual void Concurrency::streams::details::basic_file_buffer< _CharType >::release ( _Out_writes_(count) _CharType *  ,
_In_ size_t  count 
)
inlineprotectedvirtual

Releases a block of data acquired using ::acquire method. This frees the stream buffer to de-allocate the memory, if it so desires. Move the read position ahead by the count.

Parameters
ptrA pointer to the block of data to be released.
countThe number of characters that were read.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual pos_type Concurrency::streams::details::basic_file_buffer< _CharType >::seekoff ( off_type  offset,
std::ios_base::seekdir  way,
std::ios_base::openmode  mode 
)
inlineprotectedvirtual

Seeks to a position given by a relative offset.

Parameters
offsetThe relative position to seek to
wayThe starting point (beginning, end, current) for the seek.
modeThe I/O direction to seek (see remarks)
Returns
The position. EOF if the operation fails.

Some streams may have separate write and read cursors. For such streams, the mode parameter defines whether to move the read or the write cursor.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual pos_type Concurrency::streams::details::basic_file_buffer< _CharType >::seekpos ( pos_type  pos,
std::ios_base::openmode  mode 
)
inlineprotectedvirtual

Seeks to the given position.

Parameters
posThe offset from the beginning of the stream
directionThe I/O direction to seek (see remarks)
Returns
The position. EOF if the operation fails.

Some streams may have separate write and read cursors. For such streams, the direction parameter defines whether to move the read or the write cursor.

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual void Concurrency::streams::details::basic_file_buffer< _CharType >::set_buffer_size ( size_t  size,
std::ios_base::openmode  direction = std::ios_base::in 
)
inlineprotectedvirtual

Sets the stream buffer implementation to buffer or not buffer.

Parameters
sizeThe size to use for internal buffering, 0 if no buffering should be done.
directionThe direction of buffering (in or out)

An implementation that does not support buffering will silently ignore calls to this function and it will not have any effect on what is returned by subsequent calls to buffer_size().

Implements Concurrency::streams::details::streambuf_state_manager< _CharType >.

template<typename _CharType >
virtual utility::size64_t Concurrency::streams::details::basic_file_buffer< _CharType >::size ( ) const
inlineprotectedvirtual

Gets the size of the stream, if known. Calls to has_size will determine whether the result of size can be relied on.

Reimplemented from Concurrency::streams::details::streambuf_state_manager< _CharType >.


The documentation for this class was generated from the following file: