foobar2000 SDK  2015-08-03
Public Types | Public Member Functions | Private Types | Private Attributes
pfc::array_t< _t_item, t_alloc >

#include <array.h>

Public Types

typedef _t_item t_item
 

Public Member Functions

 array_t ()
 
 array_t (const t_self &p_source)
 
template<typename t_source >
 array_t (const t_source &p_source)
 
 array_t (t_self &&p_source)
 
template<typename t_array >
void append (const t_array &p_source)
 
template<typename t_append >
void append_fromptr (const t_append *p_buffer, t_size p_count)
 
template<typename t_append >
void append_multi (const t_append &value, t_size count)
 
template<typename t_append >
void append_single (const t_append &p_item)
 
template<typename t_append >
void append_single_val (t_append item)
 
template<typename t_callback >
void enumerate (t_callback &p_callback) const
 
template<typename t_filler >
void fill (const t_filler &p_filler)
 
void fill_null ()
 
void force_reset ()
 
t_size get_count () const
 
const t_itemget_ptr () const
 
t_itemget_ptr ()
 
t_size get_size () const
 
void grow_size (t_size p_size)
 
template<typename t_array >
bool has_owned_items (const t_array &p_source)
 
void increase_size (t_size p_delta)
 
template<typename t_insert >
void insert_multi (const t_insert &value, t_size base, t_size count)
 
template<typename t_source >
bool is_owned (const t_source &p_item)
 
void move_from (t_self &other)
 
const t_selfoperator= (const t_self &p_source)
 
template<typename t_source >
const t_selfoperator= (const t_source &p_source)
 
const t_selfoperator= (t_self &&p_source)
 
const t_itemoperator[] (t_size p_index) const
 
t_itemoperator[] (t_size p_index)
 
void prealloc (t_size p_size)
 
void set_count (t_size p_count)
 
template<typename t_source >
void set_data_fromptr (const t_source *p_buffer, t_size p_count)
 
template<typename t_item >
void set_single (const t_item &p_item)
 
void set_size (t_size p_size)
 
void set_size_discard (t_size p_size)
 
template<typename fill_t >
void set_size_fill (size_t p_size, fill_t const &filler)
 
void set_size_in_range (size_t minSize, size_t maxSize)
 

Private Types

typedef array_t< t_item, t_alloc > t_self
 

Private Attributes

t_alloc< t_itemm_alloc
 

Detailed Description

template<typename _t_item, template< typename > class t_alloc>
class pfc::array_t< _t_item, t_alloc >

Definition at line 6 of file array.h.

Member Typedef Documentation

template<typename _t_item, template< typename > class t_alloc>
typedef _t_item pfc::array_t< _t_item, t_alloc >::t_item

Definition at line 92 of file array.h.

template<typename _t_item, template< typename > class t_alloc>
typedef array_t<t_item,t_alloc> pfc::array_t< _t_item, t_alloc >::t_self
private

Definition at line 93 of file array.h.

Constructor & Destructor Documentation

template<typename _t_item, template< typename > class t_alloc>
pfc::array_t< _t_item, t_alloc >::array_t ( )
inline

Definition at line 95 of file array.h.

95 {}
template<typename _t_item, template< typename > class t_alloc>
pfc::array_t< _t_item, t_alloc >::array_t ( const t_self p_source)
inline

Definition at line 96 of file array.h.

96 {copy_array_t(*this,p_source);}
void copy_array_t(t_to &p_to, const t_from &p_from)
Definition: array.h:71
template<typename _t_item, template< typename > class t_alloc>
template<typename t_source >
pfc::array_t< _t_item, t_alloc >::array_t ( const t_source &  p_source)
inline

Definition at line 97 of file array.h.

97 {copy_array_t(*this,p_source);}
void copy_array_t(t_to &p_to, const t_from &p_from)
Definition: array.h:71
template<typename _t_item, template< typename > class t_alloc>
pfc::array_t< _t_item, t_alloc >::array_t ( t_self &&  p_source)
inline

Definition at line 101 of file array.h.

101 {move_from(p_source);}
void move_from(t_self &other)
Definition: array.h:242

Member Function Documentation

template<typename _t_item, template< typename > class t_alloc>
template<typename t_array >
void pfc::array_t< _t_item, t_alloc >::append ( const t_array &  p_source)
inline

Definition at line 145 of file array.h.

145  {
146  if (has_owned_items(p_source)) append(array_t<t_item>(p_source));
147  else {
148  const t_size source_size = array_size_t(p_source);
149  const t_size base = get_size();
150  increase_size(source_size);
151  for(t_size n=0;n<source_size;n++) m_alloc[base+n] = p_source[n];
152  }
153  }
void increase_size(t_size p_delta)
Definition: array.h:174
t_alloc< t_item > m_alloc
Definition: array.h:246
size_t t_size
Definition: int_types.h:48
bool has_owned_items(const t_array &p_source)
Definition: array.h:219
t_size array_size_t(const t_array &p_array)
Definition: primitives.h:309
void append(const t_array &p_source)
Definition: array.h:145
t_size get_size() const
Definition: array.h:130
template<typename _t_item, template< typename > class t_alloc>
template<typename t_append >
void pfc::array_t< _t_item, t_alloc >::append_fromptr ( const t_append *  p_buffer,
t_size  p_count 
)
inline

Warning: buffer pointer must not point to buffer allocated by this array (fixme).

Definition at line 167 of file array.h.

167  {
168  PFC_ASSERT( !is_owned(&p_buffer[0]) );
169  t_size base = get_size();
170  increase_size(p_count);
171  for(t_size n=0;n<p_count;n++) m_alloc[base+n] = p_buffer[n];
172  }
void increase_size(t_size p_delta)
Definition: array.h:174
t_alloc< t_item > m_alloc
Definition: array.h:246
size_t t_size
Definition: int_types.h:48
t_size get_size() const
Definition: array.h:130
bool is_owned(const t_source &p_item)
Definition: array.h:230
template<typename _t_item, template< typename > class t_alloc>
template<typename t_append >
void pfc::array_t< _t_item, t_alloc >::append_multi ( const t_append &  value,
t_size  count 
)
inline

Definition at line 163 of file array.h.

163 {insert_multi(value,~0,count);}
void insert_multi(const t_insert &value, t_size base, t_size count)
Definition: array.h:156
template<typename _t_item, template< typename > class t_alloc>
template<typename t_append >
void pfc::array_t< _t_item, t_alloc >::append_single ( const t_append &  p_item)
inline

Definition at line 188 of file array.h.

188  {
189  if (is_owned(p_item)) append_single(t_append(p_item));
190  else {
191  const t_size base = get_size();
192  increase_size(1);
193  m_alloc[base] = p_item;
194  }
195  }
void increase_size(t_size p_delta)
Definition: array.h:174
t_alloc< t_item > m_alloc
Definition: array.h:246
void append_single(const t_append &p_item)
Definition: array.h:188
size_t t_size
Definition: int_types.h:48
t_size get_size() const
Definition: array.h:130
bool is_owned(const t_source &p_item)
Definition: array.h:230
template<typename _t_item, template< typename > class t_alloc>
template<typename t_append >
void pfc::array_t< _t_item, t_alloc >::append_single_val ( t_append  item)
inline

Definition at line 181 of file array.h.

181  {
182  const t_size base = get_size();
183  increase_size(1);
184  m_alloc[base] = item;
185  }
void increase_size(t_size p_delta)
Definition: array.h:174
t_alloc< t_item > m_alloc
Definition: array.h:246
size_t t_size
Definition: int_types.h:48
t_size get_size() const
Definition: array.h:130
template<typename _t_item, template< typename > class t_alloc>
template<typename t_callback >
void pfc::array_t< _t_item, t_alloc >::enumerate ( t_callback &  p_callback) const
inline

Definition at line 240 of file array.h.

240 { for(t_size n = 0; n < get_size(); n++ ) { p_callback((*this)[n]); } }
size_t t_size
Definition: int_types.h:48
t_size get_size() const
Definition: array.h:130
template<typename _t_item, template< typename > class t_alloc>
template<typename t_filler >
void pfc::array_t< _t_item, t_alloc >::fill ( const t_filler &  p_filler)
inline

Definition at line 198 of file array.h.

198  {
199  const t_size max = get_size();
200  for(t_size n=0;n<max;n++) m_alloc[n] = p_filler;
201  }
t_alloc< t_item > m_alloc
Definition: array.h:246
size_t t_size
Definition: int_types.h:48
t_size get_size() const
Definition: array.h:130
template<typename _t_item, template< typename > class t_alloc>
void pfc::array_t< _t_item, t_alloc >::fill_null ( )
inline

Definition at line 203 of file array.h.

203  {
204  const t_size max = get_size();
205  for(t_size n=0;n<max;n++) m_alloc[n] = 0;
206  }
t_alloc< t_item > m_alloc
Definition: array.h:246
size_t t_size
Definition: int_types.h:48
t_size get_size() const
Definition: array.h:130
template<typename _t_item, template< typename > class t_alloc>
void pfc::array_t< _t_item, t_alloc >::force_reset ( )
inline

Definition at line 132 of file array.h.

132 {m_alloc.force_reset();}
t_alloc< t_item > m_alloc
Definition: array.h:246
template<typename _t_item, template< typename > class t_alloc>
t_size pfc::array_t< _t_item, t_alloc >::get_count ( ) const
inline

Definition at line 131 of file array.h.

131 {return m_alloc.get_size();}
t_alloc< t_item > m_alloc
Definition: array.h:246
template<typename _t_item, template< typename > class t_alloc>
const t_item* pfc::array_t< _t_item, t_alloc >::get_ptr ( ) const
inline

Definition at line 213 of file array.h.

213 {return m_alloc.get_ptr();}
t_alloc< t_item > m_alloc
Definition: array.h:246
template<typename _t_item, template< typename > class t_alloc>
t_item* pfc::array_t< _t_item, t_alloc >::get_ptr ( )
inline

Definition at line 214 of file array.h.

214 {return m_alloc.get_ptr();}
t_alloc< t_item > m_alloc
Definition: array.h:246
template<typename _t_item, template< typename > class t_alloc>
t_size pfc::array_t< _t_item, t_alloc >::get_size ( ) const
inline

Definition at line 130 of file array.h.

130 {return m_alloc.get_size();}
t_alloc< t_item > m_alloc
Definition: array.h:246
template<typename _t_item, template< typename > class t_alloc>
void pfc::array_t< _t_item, t_alloc >::grow_size ( t_size  p_size)
inline

Definition at line 208 of file array.h.

208  {
209  if (p_size > get_size()) set_size(p_size);
210  }
void set_size(t_size p_size)
Definition: array.h:104
t_size get_size() const
Definition: array.h:130
template<typename _t_item, template< typename > class t_alloc>
template<typename t_array >
bool pfc::array_t< _t_item, t_alloc >::has_owned_items ( const t_array &  p_source)
inline

Definition at line 219 of file array.h.

219  {
220  if (array_size_t(p_source) == 0) return false;
221 
222  //how the hell would we properly check if any of source items is owned by us, in case source array implements some weird mixing of references of items from different sources?
223  //the most obvious way means evil bottleneck here (whether it matters or not from caller's point of view which does something O(n) already is another question)
224  //at least this will work fine with all standard classes which don't crossreference anyhow and always use own storage
225  //perhaps we'll traitify this someday later
226  return is_owned(p_source[0]);
227  }
t_size array_size_t(const t_array &p_array)
Definition: primitives.h:309
bool is_owned(const t_source &p_item)
Definition: array.h:230
template<typename _t_item, template< typename > class t_alloc>
void pfc::array_t< _t_item, t_alloc >::increase_size ( t_size  p_delta)
inline

Definition at line 174 of file array.h.

174  {
175  t_size new_size = get_size() + p_delta;
176  if (new_size < p_delta) throw std::bad_alloc();
177  set_size(new_size);
178  }
size_t t_size
Definition: int_types.h:48
void set_size(t_size p_size)
Definition: array.h:104
t_size get_size() const
Definition: array.h:130
template<typename _t_item, template< typename > class t_alloc>
template<typename t_insert >
void pfc::array_t< _t_item, t_alloc >::insert_multi ( const t_insert &  value,
t_size  base,
t_size  count 
)
inline

Definition at line 156 of file array.h.

156  {
157  const t_size oldSize = get_size();
158  if (base > oldSize) base = oldSize;
159  increase_size(count);
160  pfc::memmove_t(get_ptr() + base + count, get_ptr() + base, oldSize - base);
161  pfc::fill_ptr_t(get_ptr() + base, count, value);
162  }
void increase_size(t_size p_delta)
Definition: array.h:174
const t_item * get_ptr() const
Definition: array.h:213
void fill_ptr_t(t_array *p_buffer, const t_size p_count, const t_filler &p_filler)
Definition: primitives.h:330
size_t t_size
Definition: int_types.h:48
void memmove_t(T *p_dst, const T *p_src, t_size p_count)
Definition: primitives.h:649
t_size get_size() const
Definition: array.h:130
template<typename _t_item, template< typename > class t_alloc>
template<typename t_source >
bool pfc::array_t< _t_item, t_alloc >::is_owned ( const t_source &  p_item)
inline

Definition at line 230 of file array.h.

230  {
231  return m_alloc.is_ptr_owned(&p_item);
232  }
t_alloc< t_item > m_alloc
Definition: array.h:246
template<typename _t_item, template< typename > class t_alloc>
void pfc::array_t< _t_item, t_alloc >::move_from ( t_self other)
inline

Definition at line 242 of file array.h.

242  {
243  m_alloc.move_from(other.m_alloc);
244  }
t_alloc< t_item > m_alloc
Definition: array.h:246
template<typename _t_item, template< typename > class t_alloc>
const t_self& pfc::array_t< _t_item, t_alloc >::operator= ( const t_self p_source)
inline

Definition at line 98 of file array.h.

98 {copy_array_t(*this,p_source); return *this;}
void copy_array_t(t_to &p_to, const t_from &p_from)
Definition: array.h:71
template<typename _t_item, template< typename > class t_alloc>
template<typename t_source >
const t_self& pfc::array_t< _t_item, t_alloc >::operator= ( const t_source &  p_source)
inline

Definition at line 99 of file array.h.

99 {copy_array_t(*this,p_source); return *this;}
void copy_array_t(t_to &p_to, const t_from &p_from)
Definition: array.h:71
template<typename _t_item, template< typename > class t_alloc>
const t_self& pfc::array_t< _t_item, t_alloc >::operator= ( t_self &&  p_source)
inline

Definition at line 102 of file array.h.

102 {move_from(p_source); return *this;}
void move_from(t_self &other)
Definition: array.h:242
template<typename _t_item, template< typename > class t_alloc>
const t_item& pfc::array_t< _t_item, t_alloc >::operator[] ( t_size  p_index) const
inline

Definition at line 134 of file array.h.

134 {PFC_ASSERT(p_index < get_size());return m_alloc[p_index];}
t_alloc< t_item > m_alloc
Definition: array.h:246
t_size get_size() const
Definition: array.h:130
template<typename _t_item, template< typename > class t_alloc>
t_item& pfc::array_t< _t_item, t_alloc >::operator[] ( t_size  p_index)
inline

Definition at line 135 of file array.h.

135 {PFC_ASSERT(p_index < get_size());return m_alloc[p_index];}
t_alloc< t_item > m_alloc
Definition: array.h:246
t_size get_size() const
Definition: array.h:130
template<typename _t_item, template< typename > class t_alloc>
void pfc::array_t< _t_item, t_alloc >::prealloc ( t_size  p_size)
inline

Definition at line 216 of file array.h.

216 {m_alloc.prealloc(p_size);}
t_alloc< t_item > m_alloc
Definition: array.h:246
template<typename _t_item, template< typename > class t_alloc>
void pfc::array_t< _t_item, t_alloc >::set_count ( t_size  p_count)
inline

Definition at line 129 of file array.h.

129 {m_alloc.set_size(p_count);}
t_alloc< t_item > m_alloc
Definition: array.h:246
template<typename _t_item, template< typename > class t_alloc>
template<typename t_source >
void pfc::array_t< _t_item, t_alloc >::set_data_fromptr ( const t_source *  p_buffer,
t_size  p_count 
)
inline

Warning: buffer pointer must not point to buffer allocated by this array (fixme).

Definition at line 139 of file array.h.

139  {
140  set_size(p_count);
141  pfc::copy_array_loop_t(*this,p_buffer,p_count);
142  }
void copy_array_loop_t(t_dst &p_dst, const t_src &p_src, t_size p_count)
Definition: primitives.h:616
void set_size(t_size p_size)
Definition: array.h:104
template<typename _t_item, template< typename > class t_alloc>
template<typename t_item >
void pfc::array_t< _t_item, t_alloc >::set_single ( const t_item p_item)
inline

Definition at line 235 of file array.h.

235  {
236  set_size(1);
237  (*this)[0] = p_item;
238  }
void set_size(t_size p_size)
Definition: array.h:104
template<typename _t_item, template< typename > class t_alloc>
void pfc::array_t< _t_item, t_alloc >::set_size ( t_size  p_size)
inline

Definition at line 104 of file array.h.

104 {m_alloc.set_size(p_size);}
t_alloc< t_item > m_alloc
Definition: array.h:246
template<typename _t_item, template< typename > class t_alloc>
void pfc::array_t< _t_item, t_alloc >::set_size_discard ( t_size  p_size)
inline

Definition at line 128 of file array.h.

128 {m_alloc.set_size(p_size);}
t_alloc< t_item > m_alloc
Definition: array.h:246
template<typename _t_item, template< typename > class t_alloc>
template<typename fill_t >
void pfc::array_t< _t_item, t_alloc >::set_size_fill ( size_t  p_size,
fill_t const &  filler 
)
inline

Definition at line 107 of file array.h.

107  {
108  size_t before = get_size();
109  set_size( p_size );
110  for(size_t w = before; w < p_size; ++w) this->get_ptr()[w] = filler;
111  }
const t_item * get_ptr() const
Definition: array.h:213
void set_size(t_size p_size)
Definition: array.h:104
t_size get_size() const
Definition: array.h:130
template<typename _t_item, template< typename > class t_alloc>
void pfc::array_t< _t_item, t_alloc >::set_size_in_range ( size_t  minSize,
size_t  maxSize 
)
inline

Definition at line 113 of file array.h.

113  {
114  if (minSize >= maxSize) { set_size( minSize); return; }
115  size_t walk = maxSize;
116  for(;;) {
117  try {
118  set_size(walk);
119  return;
120  } catch(std::bad_alloc) {
121  if (walk <= minSize) throw;
122  // go on
123  }
124  walk >>= 1;
125  if (walk < minSize) walk = minSize;
126  }
127  }
void set_size(t_size p_size)
Definition: array.h:104

Field Documentation

template<typename _t_item, template< typename > class t_alloc>
t_alloc<t_item> pfc::array_t< _t_item, t_alloc >::m_alloc
private

Definition at line 246 of file array.h.


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