foobar2000 SDK  2015-08-03
Data Structures | Namespaces | Typedefs | Functions
filesystem_helper.h File Reference

Go to the source code of this file.

Data Structures

class  _IsTypeByte< TVal >
 
class  _stream_reader_formatter_translator< isBigEndian >
 
class  _stream_writer_formatter_translator< isBigEndian >
 
class  file_chain
 
class  file_chain_readonly
 
class  file_path_canonical
 
class  file_path_display
 
class  fileRestorePositionScope
 
class  reader_bigmem
 
class  reader_bigmem_mirror
 
class  reader_limited
 
class  reader_membuffer_base
 
class  reader_membuffer_mirror
 
class  reader_membuffer_simple
 
class  stream_reader_chunk
 
class  stream_reader_dummy
 
class  stream_reader_formatter< isBigEndian >
 
class  stream_reader_formatter_simple< BE >
 
class  stream_reader_formatter_simple_ref< BE >
 
class  stream_reader_limited_ref
 
class  stream_reader_memblock_ref
 
class  stream_writer_buffer_append_ref_t< t_storage >
 
class  stream_writer_buffer_simple
 
class  stream_writer_chunk
 
class  stream_writer_chunk_dwordheader
 
class  stream_writer_formatter< isBigEndian >
 
class  stream_writer_formatter_simple< BE >
 

Namespaces

 foobar2000_io
 

Typedefs

typedef std::function< void(const char *, t_filestats const &, bool) > foobar2000_io::listDirectoryFunc_t
 

Functions

 __DECLARE_INT_OVERLOADS (char)
 
 __DECLARE_INT_OVERLOADS (signed char)
 
 __DECLARE_INT_OVERLOADS (unsigned char)
 
 __DECLARE_INT_OVERLOADS (signed long long)
 
 __DECLARE_INT_OVERLOADS (unsigned long long)
 
 __DECLARE_INT_OVERLOADS (wchar_t)
 
 FB2K_STREAM_READER_OVERLOAD (GUID)
 
 FB2K_STREAM_READER_OVERLOAD (pfc::string)
 
 FB2K_STREAM_READER_OVERLOAD (pfc::string_base)
 
 FB2K_STREAM_READER_OVERLOAD (float)
 
 FB2K_STREAM_READER_OVERLOAD (double)
 
 FB2K_STREAM_READER_OVERLOAD (bool)
 
 FB2K_STREAM_WRITER_OVERLOAD (GUID)
 
 FB2K_STREAM_WRITER_OVERLOAD (pfc::string)
 
 FB2K_STREAM_WRITER_OVERLOAD (pfc::string_base)
 
 FB2K_STREAM_WRITER_OVERLOAD (float)
 
 FB2K_STREAM_WRITER_OVERLOAD (double)
 
 FB2K_STREAM_WRITER_OVERLOAD (bool)
 
bool fb2kFileSelfTest (file::ptr f, abort_callback &aborter)
 
void foobar2000_io::listDirectory (const char *path, abort_callback &aborter, listDirectoryFunc_t func)
 
template<bool isBigEndian, typename TVal , size_t Count>
stream_writer_formatter< isBigEndian > & operator<< (stream_writer_formatter< isBigEndian > &p_stream, TVal const (&p_array)[Count])
 
template<bool isBigEndian, typename TVal , size_t Count>
stream_reader_formatter< isBigEndian > & operator>> (stream_reader_formatter< isBigEndian > &p_stream, TVal(&p_array)[Count])
 

Data Structure Documentation

class _IsTypeByte

template<typename TVal>
class _IsTypeByte< TVal >

Definition at line 502 of file filesystem_helper.h.

Data Fields
__unnamed__

Function Documentation

__DECLARE_INT_OVERLOADS ( char  )
__DECLARE_INT_OVERLOADS ( signed  char)
__DECLARE_INT_OVERLOADS ( unsigned  char)
__DECLARE_INT_OVERLOADS ( signed long  long)
__DECLARE_INT_OVERLOADS ( unsigned long  long)
__DECLARE_INT_OVERLOADS ( wchar_t  )
FB2K_STREAM_READER_OVERLOAD ( GUID  )

Definition at line 531 of file filesystem_helper.h.

531  {
532  return stream >> value.Data1 >> value.Data2 >> value.Data3 >> value.Data4;
533 }
FB2K_STREAM_READER_OVERLOAD ( pfc::string  )

Definition at line 539 of file filesystem_helper.h.

539  {
540  t_uint32 len; stream >> len;
541  value = stream.m_stream.read_string_ex(len,stream.m_abort);
542  return stream;
543 }
uint32_t t_uint32
Definition: int_types.h:5
FB2K_STREAM_READER_OVERLOAD ( pfc::string_base  )

Definition at line 551 of file filesystem_helper.h.

551  {
552  stream.m_stream.read_string(value, stream.m_abort);
553  return stream;
554 }
FB2K_STREAM_READER_OVERLOAD ( float  )

Definition at line 571 of file filesystem_helper.h.

571  {
572  union { float f; t_uint32 i;} u;
573  stream >> u.i; value = u.f;
574  return stream;
575 }
uint32_t t_uint32
Definition: int_types.h:5
FB2K_STREAM_READER_OVERLOAD ( double  )

Definition at line 584 of file filesystem_helper.h.

584  {
585  union { double f; t_uint64 i;} u;
586  stream >> u.i; value = u.f;
587  return stream;
588 }
uint64_t t_uint64
Definition: int_types.h:3
FB2K_STREAM_READER_OVERLOAD ( bool  )

Definition at line 594 of file filesystem_helper.h.

594  {
595  t_uint8 temp; stream >> temp; value = temp != 0;
596  return stream;
597 }
uint8_t t_uint8
Definition: int_types.h:9
FB2K_STREAM_WRITER_OVERLOAD ( GUID  )

Definition at line 535 of file filesystem_helper.h.

535  {
536  return stream << value.Data1 << value.Data2 << value.Data3 << value.Data4;
537 }
FB2K_STREAM_WRITER_OVERLOAD ( pfc::string  )

Definition at line 545 of file filesystem_helper.h.

545  {
546  stream << pfc::downcast_guarded<t_uint32>(value.length());
547  stream.write_raw(value.ptr(),value.length());
548  return stream;
549 }
FB2K_STREAM_WRITER_OVERLOAD ( pfc::string_base  )

Definition at line 555 of file filesystem_helper.h.

555  {
556  const char * val = value.get_ptr();
557  const t_size len = strlen(val);
558  stream << pfc::downcast_guarded<t_uint32>(len);
559  stream.write_raw(val,len);
560  return stream;
561 }
size_t t_size
Definition: int_types.h:48
FB2K_STREAM_WRITER_OVERLOAD ( float  )

Definition at line 564 of file filesystem_helper.h.

564  {
565  union {
566  float f; t_uint32 i;
567  } u; u.f = value;
568  return stream << u.i;
569 }
uint32_t t_uint32
Definition: int_types.h:5
FB2K_STREAM_WRITER_OVERLOAD ( double  )

Definition at line 577 of file filesystem_helper.h.

577  {
578  union {
579  double f; t_uint64 i;
580  } u; u.f = value;
581  return stream << u.i;
582 }
uint64_t t_uint64
Definition: int_types.h:3
FB2K_STREAM_WRITER_OVERLOAD ( bool  )

Definition at line 590 of file filesystem_helper.h.

590  {
591  t_uint8 temp = value ? 1 : 0;
592  return stream << temp;
593 }
uint8_t t_uint8
Definition: int_types.h:9
bool fb2kFileSelfTest ( file::ptr  f,
abort_callback aborter 
)

Debug self-test function for testing a file object implementation, performs various behavior validity checks, random access etc. Output goes to fb2k console. Returns true on success, false on failure (buggy file object implementation).

Definition at line 139 of file filesystem_helper.cpp.

139  {
140  try {
141  pfc::array_t<uint8_t> fileContent;
142  f->reopen(aborter);
143  f->read_till_eof(fileContent, aborter);
144 
145  {
146  t_filesize sizeClaimed = f->get_size(aborter);
147  if (sizeClaimed == filesize_invalid) {
148  FB2K_console_formatter() << "File sanity: file reports unknown size, actual size read is " << fileContent.get_size();
149  }
150  else {
151  if (sizeClaimed != fileContent.get_size()) {
152  FB2K_console_formatter() << "File sanity: file reports size of " << sizeClaimed << ", actual size read is " << fileContent.get_size();
153  throw std::runtime_error("File size mismatch");
154  }
155  else {
156  FB2K_console_formatter() << "File sanity: file size check OK: " << sizeClaimed;
157  }
158  }
159  }
160 
161  {
162  FB2K_console_formatter() << "File sanity: testing N-first-bytes reads...";
163  const size_t sizeUpTo = pfc::min_t<size_t>(fileContent.get_size(), 1024 * 1024);
165  buf1.set_size_discard(sizeUpTo);
166 
167  for (size_t w = 1; w <= sizeUpTo; w <<= 1) {
168  f->reopen(aborter);
169  size_t did = f->read(buf1.get_ptr(), w, aborter);
170  if (did != w) {
171  FB2K_console_formatter() << "File sanity: premature EOF reading first " << w << " bytes, got " << did;
172  throw std::runtime_error("Premature EOF");
173  }
174  if (memcmp(fileContent.get_ptr(), buf1.get_ptr(), did) != 0) {
175  FB2K_console_formatter() << "File sanity: file content mismatch reading first " << w << " bytes";
176  throw std::runtime_error("File content mismatch");
177  }
178  }
179  }
180  if (f->can_seek()) {
181  FB2K_console_formatter() << "File sanity: testing random access...";
182 
183  {
184  size_t sizeUpTo = pfc::min_t<size_t>(fileContent.get_size(), 1024 * 1024);
185  for (size_t w = 1; w < sizeUpTo; w <<= 1) {
186  fileSanitySeek(f, fileContent, w, aborter);
187  }
188  fileSanitySeek(f, fileContent, fileContent.get_size(), aborter);
189  for (size_t w = 1; w < sizeUpTo; w <<= 1) {
190  fileSanitySeek(f, fileContent, fileContent.get_size() - w, aborter);
191  }
192  fileSanitySeek(f, fileContent, fileContent.get_size() / 2, aborter);
193  }
194  }
195  FB2K_console_formatter() << "File sanity test: all OK";
196  return true;
197  }
198  catch (std::exception const & e) {
199  FB2K_console_formatter() << "File sanity test failure: " << e.what();
200  return false;
201  }
202 }
const t_item * get_ptr() const
Definition: array.h:213
Special simplififed version of array class that avoids stepping on landmines with classes without pub...
Definition: array.h:11
static const t_filesize filesize_invalid
Invalid/unknown file size constant. Also see: t_filesize.
Definition: filesystem.h:16
std::exception exception
Definition: primitives.h:193
t_uint64 t_filesize
Type used for file size related variables.
Definition: filesystem.h:8
static void fileSanitySeek(file::ptr f, pfc::array_t< uint8_t > const &content, size_t offset, abort_callback &aborter)
void set_size_discard(t_size p_size)
Definition: array.h:36
t_size get_size() const
Definition: array.h:130
template<bool isBigEndian, typename TVal , size_t Count>
stream_writer_formatter<isBigEndian>& operator<< ( stream_writer_formatter< isBigEndian > &  p_stream,
TVal const (&)  p_array[Count] 
)

Definition at line 516 of file filesystem_helper.h.

516  {
518  p_stream.write_raw(p_array,Count);
519  } else {
520  for(t_size walk = 0; walk < Count; ++walk) p_stream << p_array[walk];
521  }
522  return p_stream;
523 }
size_t t_size
Definition: int_types.h:48
void write_raw(const void *p_buffer, t_size p_bytes)
template<bool isBigEndian, typename TVal , size_t Count>
stream_reader_formatter<isBigEndian>& operator>> ( stream_reader_formatter< isBigEndian > &  p_stream,
TVal(&)  p_array[Count] 
)

Definition at line 507 of file filesystem_helper.h.

507  {
509  p_stream.read_raw(p_array,Count);
510  } else {
511  for(t_size walk = 0; walk < Count; ++walk) p_stream >> p_array[walk];
512  }
513  return p_stream;
514 }
size_t t_size
Definition: int_types.h:48
void read_raw(void *p_buffer, t_size p_bytes)