foobar2000 SDK  2015-08-03
Public Member Functions | Private Attributes
stream_reader_buffered

#include <stream_buffer_helper.h>

+ Inheritance diagram for stream_reader_buffered:

Public Member Functions

 stream_reader_buffered (stream_reader *p_base, t_size p_buffer)
 
t_size read (void *p_buffer, t_size p_bytes, abort_callback &p_abort)
 

Private Attributes

stream_readerm_base
 
pfc::array_t< char > m_buffer
 
const char * m_bufferPtr
 
size_t m_bufferRemaining
 

Detailed Description

Definition at line 1 of file stream_buffer_helper.h.

Constructor & Destructor Documentation

stream_reader_buffered::stream_reader_buffered ( stream_reader p_base,
t_size  p_buffer 
)

Definition at line 3 of file stream_buffer_helper.cpp.

3  : m_base(p_base)
4 {
5  m_buffer.set_size_in_range(pfc::min_t<size_t>(1024, p_buffer), p_buffer);
7 }
void set_size_in_range(size_t minSize, size_t maxSize)
Definition: array.h:113
pfc::array_t< char > m_buffer

Member Function Documentation

t_size stream_reader_buffered::read ( void *  p_buffer,
t_size  p_bytes,
abort_callback p_abort 
)

Definition at line 9 of file stream_buffer_helper.cpp.

9  {
10  if (p_bytes <= m_bufferRemaining) {
11  memcpy( p_buffer, m_bufferPtr, p_bytes );
12  m_bufferRemaining -= p_bytes;
13  m_bufferPtr += p_bytes;
14  return p_bytes;
15  }
16 
17  p_abort.check();
18  char * output = (char*) p_buffer;
19  t_size output_ptr = 0;
20 
21  while(output_ptr < p_bytes) {
22  {
23  t_size delta = pfc::min_t(p_bytes - output_ptr, m_bufferRemaining);
24  if (delta > 0)
25  {
26  memcpy(output + output_ptr, m_bufferPtr, delta);
27  output_ptr += delta;
28  m_bufferPtr += delta;
29  m_bufferRemaining -= delta;
30  }
31  }
32 
33  if (m_bufferRemaining == 0)
34  {
35  t_size bytes_read;
36  bytes_read = m_base->read(m_buffer.get_ptr(), m_buffer.get_size(), p_abort);
38  m_bufferRemaining = bytes_read;
39 
40  if (m_bufferRemaining == 0) break;
41  }
42 
43  }
44 
45  return output_ptr;
46 }
const t_item * get_ptr() const
Definition: array.h:213
T min_t(const T &item1, const T &item2)
Definition: primitives.h:556
pfc::array_t< char > m_buffer
size_t t_size
Definition: int_types.h:48
t_size get_size() const
Definition: array.h:130
Definition: output.h:95

Field Documentation

stream_reader* stream_reader_buffered::m_base
private

Definition at line 7 of file stream_buffer_helper.h.

pfc::array_t<char> stream_reader_buffered::m_buffer
private

Definition at line 8 of file stream_buffer_helper.h.

const char* stream_reader_buffered::m_bufferPtr
private

Definition at line 9 of file stream_buffer_helper.h.

size_t stream_reader_buffered::m_bufferRemaining
private

Definition at line 10 of file stream_buffer_helper.h.


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