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

#include <stream_buffer_helper.h>

+ Inheritance diagram for stream_writer_buffered:

Public Member Functions

 stream_writer_buffered (stream_writer *p_base, t_size p_buffer)
 
void flush (abort_callback &p_abort)
 
void write (const void *p_buffer, t_size p_bytes, abort_callback &p_abort)
 

Private Attributes

stream_writerm_base
 
pfc::array_t< char > m_buffer
 
t_size m_buffer_ptr
 

Detailed Description

Definition at line 13 of file stream_buffer_helper.h.

Constructor & Destructor Documentation

stream_writer_buffered::stream_writer_buffered ( stream_writer p_base,
t_size  p_buffer 
)

Definition at line 48 of file stream_buffer_helper.cpp.

49  : m_base(p_base)
50 {
51  m_buffer.set_size_in_range(pfc::min_t<size_t>(1024, p_buffer), p_buffer);
52  m_buffer_ptr = 0;
53 }
void set_size_in_range(size_t minSize, size_t maxSize)
Definition: array.h:113
pfc::array_t< char > m_buffer

Member Function Documentation

void stream_writer_buffered::flush ( abort_callback p_abort)

Definition at line 82 of file stream_buffer_helper.cpp.

82  {
83  if (m_buffer_ptr > 0) {
84  m_base->write_object(m_buffer.get_ptr(),m_buffer_ptr,p_abort);
85  m_buffer_ptr = 0;
86  }
87 }
const t_item * get_ptr() const
Definition: array.h:213
pfc::array_t< char > m_buffer
void stream_writer_buffered::write ( const void *  p_buffer,
t_size  p_bytes,
abort_callback p_abort 
)

Definition at line 55 of file stream_buffer_helper.cpp.

55  {
56  p_abort.check_e();
57  const char * source = (const char*)p_buffer;
58  t_size source_remaining = p_bytes;
59  const t_size buffer_size = m_buffer.get_size();
60  if (source_remaining >= buffer_size)
61  {
62  flush(p_abort);
63  m_base->write_object(source,source_remaining,p_abort);
64  return;
65  }
66 
67  if (m_buffer_ptr + source_remaining >= buffer_size)
68  {
69  t_size delta = buffer_size - m_buffer_ptr;
70  memcpy(m_buffer.get_ptr() + m_buffer_ptr, source,delta);
71  source += delta;
72  source_remaining -= delta;
73  m_buffer_ptr += delta;
74  flush(p_abort);
75  }
76 
77  memcpy(m_buffer.get_ptr() + m_buffer_ptr, source,source_remaining);
78  m_buffer_ptr += source_remaining;
79 }
const t_item * get_ptr() const
Definition: array.h:213
pfc::array_t< char > m_buffer
size_t t_size
Definition: int_types.h:48
void flush(abort_callback &p_abort)
t_size get_size() const
Definition: array.h:130

Field Documentation

stream_writer* stream_writer_buffered::m_base
private

Definition at line 23 of file stream_buffer_helper.h.

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

Definition at line 24 of file stream_buffer_helper.h.

t_size stream_writer_buffered::m_buffer_ptr
private

Definition at line 25 of file stream_buffer_helper.h.


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