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

#include <filesystem_helper.h>

+ Inheritance diagram for reader_limited:

Public Member Functions

 reader_limited ()
 
 reader_limited (const service_ptr_t< file > &p_r, t_filesize p_begin, t_filesize p_end, abort_callback &p_abort)
 
bool can_seek ()
 
bool get_content_type (pfc::string_base &)
 
t_filesize get_position (abort_callback &p_abort)
 
t_filesize get_size (abort_callback &p_abort)
 
t_filetimestamp get_timestamp (abort_callback &p_abort)
 
void init (const service_ptr_t< file > &p_r, t_filesize p_begin, t_filesize p_end, abort_callback &p_abort)
 
bool is_remote ()
 
t_size read (void *p_buffer, t_size p_bytes, abort_callback &p_abort)
 
void reopen (abort_callback &p_abort)
 
void seek (t_filesize position, abort_callback &p_abort)
 

Static Public Member Functions

static file::ptr g_create (file::ptr base, t_filesize offset, t_filesize size, abort_callback &abort)
 

Private Member Functions

void seekInternal (t_filesize position, abort_callback &abort)
 

Private Attributes

t_filesize begin
 
t_filesize end
 
service_ptr_t< filer
 

Detailed Description

Definition at line 120 of file filesystem_helper.h.

Constructor & Destructor Documentation

reader_limited::reader_limited ( )
inline

Definition at line 132 of file filesystem_helper.h.

132 {begin=0;end=0;}
reader_limited::reader_limited ( const service_ptr_t< file > &  p_r,
t_filesize  p_begin,
t_filesize  p_end,
abort_callback p_abort 
)
inline

Definition at line 133 of file filesystem_helper.h.

133  {
134  r = p_r;
135  begin = p_begin;
136  end = p_end;
137  reopen(p_abort);
138  }
service_ptr_t< file > r
void reopen(abort_callback &p_abort)

Member Function Documentation

bool reader_limited::can_seek ( )
inline

Definition at line 165 of file filesystem_helper.h.

165 {return r->can_seek();}
service_ptr_t< file > r
static file::ptr reader_limited::g_create ( file::ptr  base,
t_filesize  offset,
t_filesize  size,
abort_callback abort 
)
inlinestatic

Definition at line 126 of file filesystem_helper.h.

126  {
128  if (offset + size < offset) throw pfc::exception_overflow();
129  r->init(base, offset, offset + size, abort);
130  return r;
131  }
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
Definition: service_impl.h:4
service_ptr_t< file > r
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
bool reader_limited::get_content_type ( pfc::string_base )
inline

Definition at line 168 of file filesystem_helper.h.

168 {return false;}
t_filesize reader_limited::get_position ( abort_callback p_abort)
inline

Definition at line 158 of file filesystem_helper.h.

158  {
159  return r->get_position(p_abort) - begin;
160  }
service_ptr_t< file > r
t_filesize reader_limited::get_size ( abort_callback p_abort)
inline

Definition at line 156 of file filesystem_helper.h.

156 {return end-begin;}
t_filetimestamp reader_limited::get_timestamp ( abort_callback p_abort)
inline

Definition at line 147 of file filesystem_helper.h.

147 {return r->get_timestamp(p_abort);}
service_ptr_t< file > r
void reader_limited::init ( const service_ptr_t< file > &  p_r,
t_filesize  p_begin,
t_filesize  p_end,
abort_callback p_abort 
)
inline

Definition at line 140 of file filesystem_helper.h.

140  {
141  r = p_r;
142  begin = p_begin;
143  end = p_end;
144  reopen(p_abort);
145  }
service_ptr_t< file > r
void reopen(abort_callback &p_abort)
bool reader_limited::is_remote ( )
inline

Definition at line 166 of file filesystem_helper.h.

166 {return r->is_remote();}
service_ptr_t< file > r
t_size reader_limited::read ( void *  p_buffer,
t_size  p_bytes,
abort_callback p_abort 
)
inline

Definition at line 149 of file filesystem_helper.h.

149  {
150  t_filesize pos;
151  pos = r->get_position(p_abort);
152  if (p_bytes > end - pos) p_bytes = (t_size)(end - pos);
153  return r->read(p_buffer,p_bytes,p_abort);
154  }
service_ptr_t< file > r
size_t t_size
Definition: int_types.h:48
t_uint64 t_filesize
Type used for file size related variables.
Definition: filesystem.h:8
void reader_limited::reopen ( abort_callback p_abort)
inline

Definition at line 170 of file filesystem_helper.h.

170  {
171  seekInternal(begin, p_abort);
172  }
void seekInternal(t_filesize position, abort_callback &abort)
void reader_limited::seek ( t_filesize  position,
abort_callback p_abort 
)
inline

Definition at line 162 of file filesystem_helper.h.

162  {
163  r->seek(position+begin,p_abort);
164  }
service_ptr_t< file > r
void reader_limited::seekInternal ( t_filesize  position,
abort_callback abort 
)
inlineprivate

Definition at line 174 of file filesystem_helper.h.

174  {
175  if (r->can_seek()) {
176  r->seek(position, abort);
177  } else {
178  t_filesize positionWas = r->get_position(abort);
179  if (positionWas == filesize_invalid || positionWas > position) {
180  r->reopen(abort);
181  try { r->skip_object(position, abort); }
182  catch (exception_io_data) { throw exception_io_seek_out_of_range(); }
183  } else {
184  t_filesize skipMe = position - positionWas;
185  if (skipMe > 0) {
186  try { r->skip_object(skipMe, abort); }
187  catch (exception_io_data) { throw exception_io_seek_out_of_range(); }
188  }
189  }
190  }
191  }
static const t_filesize filesize_invalid
Invalid/unknown file size constant. Also see: t_filesize.
Definition: filesystem.h:16
service_ptr_t< file > r
t_uint64 t_filesize
Type used for file size related variables.
Definition: filesystem.h:8

Field Documentation

t_filesize reader_limited::begin
private

Definition at line 122 of file filesystem_helper.h.

t_filesize reader_limited::end
private

Definition at line 123 of file filesystem_helper.h.

service_ptr_t<file> reader_limited::r
private

Definition at line 121 of file filesystem_helper.h.


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