foobar2000 SDK  2015-08-03
mem_block_container.h
Go to the documentation of this file.
1 class NOVTABLE mem_block_container {
3 public:
4  virtual const void * get_ptr() const = 0;
5  virtual void * get_ptr() = 0;
6  virtual t_size get_size() const = 0;
7  virtual void set_size(t_size p_size) = 0;
8 
9  void from_stream(stream_reader * p_stream,t_size p_bytes,abort_callback & p_abort);
10 
11  void set(const void * p_buffer,t_size p_size);
12  void set(const mem_block_container & source) {copy(source);}
13  template<typename t_source> void set(const t_source & source) {
14  PFC_STATIC_ASSERT( sizeof(source[0]) == 1 );
15  set(source.get_ptr(), source.get_size());
16  }
17 
18  inline void copy(const mem_block_container & p_source) {set(p_source.get_ptr(),p_source.get_size());}
19  inline void reset() {set_size(0);}
20 
21  const mem_block_container & operator=(const mem_block_container & p_source) {copy(p_source);return *this;}
22 
23 protected:
26 };
27 
29 template<template<typename> class t_alloc = pfc::alloc_standard>
31 public:
32  const void * get_ptr() const {return m_data.get_ptr();}
33  void * get_ptr() {return m_data.get_ptr();}
34  t_size get_size() const {return m_data.get_size();}
35  void set_size(t_size p_size) {
36  m_data.set_size(p_size);
37  }
38 private:
40 };
41 
43 
44 template<unsigned alignBytes = 16> class mem_block_container_aligned_impl : public mem_block_container {
45 public:
46  const void * get_ptr() const {return m_data.get_ptr();}
47  void * get_ptr() {return m_data.get_ptr();}
48  t_size get_size() const {return m_data.get_size();}
49  void set_size(t_size p_size) {m_data.set_size(p_size);}
50 private:
52 };
53 
54 template<unsigned alignBytes = 16> class mem_block_container_aligned_incremental_impl : public mem_block_container {
55 public:
57  const void * get_ptr() const {return m_data.get_ptr();}
58  void * get_ptr() {return m_data.get_ptr();}
59  t_size get_size() const {return m_size;}
60  void set_size(t_size p_size) {
61  if (m_data.size() < p_size) {
62  m_data.resize( pfc::multiply_guarded<size_t>(p_size, 3) / 2 );
63  }
64  m_size = p_size;
65  }
66 private:
68  size_t m_size;
69 };
70 
72 public:
73  mem_block_container_temp_impl(void * p_buffer,t_size p_size) : m_buffer(p_buffer), m_buffer_size(p_size), m_size(0) {}
74  const void * get_ptr() const {return m_buffer;}
75  void * get_ptr() {return m_buffer;}
76  t_size get_size() const {return m_size;}
77  void set_size(t_size p_size) {if (p_size > m_buffer_size) throw pfc::exception_overflow(); m_size = p_size;}
78 private:
79  t_size m_size,m_buffer_size;
80  void * m_buffer;
81 };
82 
83 template<typename t_ref>
85 public:
86  mem_block_container_ref_impl(t_ref & ref) : m_ref(ref) {
87  PFC_STATIC_ASSERT( sizeof(ref[0]) == 1 );
88  }
89  const void * get_ptr() const {return m_ref.get_ptr();}
90  void * get_ptr() {return m_ref.get_ptr();}
91  t_size get_size() const {return m_ref.get_size();}
92  void set_size(t_size p_size) {m_ref.set_size(p_size);}
93 private:
94  t_ref & m_ref;
95 };
const void * get_ptr() const
mem_block_container_temp_impl(void *p_buffer, t_size p_size)
t_filesize get_size(HANDLE p_handle)
mem_block_container_impl_t mem_block_container_impl
void copy(const mem_block_container &p_source)
pfc::array_t< t_uint8, t_alloc > m_data
size_t t_size
Definition: int_types.h:48
pfc::mem_block_aligned< 16 > m_data
virtual const void * get_ptr() const =0
const void * get_ptr() const
Generic interface for a memory block; used by various other interfaces to return memory blocks while ...
void set_size(t_size p_size)
const mem_block_container & operator=(const mem_block_container &p_source)
This is free and unencumbered software released into the public domain Anyone is free to copy
Definition: pfc-license.txt:3
virtual t_size get_size() const =0
mem_block_container implementation.