foobar2000 SDK  2015-08-03
Functions
metadb_handle_list_helper Namespace Reference

Functions

t_size bsearch_by_pointer (const pfc::list_base_const_t< metadb_handle_ptr > &p_list, const metadb_handle_ptr &val)
 
double calc_total_duration (const pfc::list_base_const_t< metadb_handle_ptr > &p_list)
 
t_filesize calc_total_size (metadb_handle_list_cref list, bool skipUnknown=false)
 
t_filesize calc_total_size_ex (metadb_handle_list_cref list, bool &foundUnknown)
 
bool extract_single_path (metadb_handle_list_cref list, const char *&path)
 
void remove_duplicates (pfc::list_base_t< metadb_handle_ptr > &p_list)
 
void sort_by_format (metadb_handle_list_ref p_list, const char *spec, titleformat_hook *p_hook)
 
void sort_by_format (metadb_handle_list_ref p_list, const service_ptr_t< titleformat_object > &p_script, titleformat_hook *p_hook, int direction=1)
 
void sort_by_format_get_order (metadb_handle_list_cref p_list, t_size *order, const char *spec, titleformat_hook *p_hook)
 
void sort_by_format_get_order (metadb_handle_list_cref p_list, t_size *order, const service_ptr_t< titleformat_object > &p_script, titleformat_hook *p_hook, int p_direction=1)
 
void sort_by_path (pfc::list_base_t< metadb_handle_ptr > &p_list)
 
void sort_by_path_quick (pfc::list_base_t< metadb_handle_ptr > &p_list)
 
void sort_by_pointer (pfc::list_base_t< metadb_handle_ptr > &p_list)
 
void sort_by_pointer_remove_duplicates (pfc::list_base_t< metadb_handle_ptr > &p_list)
 
void sort_by_relative_path (metadb_handle_list_ref p_list)
 
void sort_by_relative_path_get_order (metadb_handle_list_cref p_list, t_size *order)
 
void sorted_by_pointer_extract_difference (metadb_handle_list const &p_list_1, metadb_handle_list const &p_list_2, metadb_handle_list &p_list_1_specific, metadb_handle_list &p_list_2_specific)
 

Function Documentation

t_size metadb_handle_list_helper::bsearch_by_pointer ( const pfc::list_base_const_t< metadb_handle_ptr > &  p_list,
const metadb_handle_ptr val 
)
double metadb_handle_list_helper::calc_total_duration ( const pfc::list_base_const_t< metadb_handle_ptr > &  p_list)
t_filesize metadb_handle_list_helper::calc_total_size ( metadb_handle_list_cref  list,
bool  skipUnknown = false 
)

Definition at line 348 of file metadb_handle_list.cpp.

348  {
350 // metadb_handle_list list(p_list);
351 // list.sort_t(metadb::path_compare_metadb_handle);
352 
353  t_filesize ret = 0;
354  t_size n, m = p_list.get_count();
355  for(n=0;n<m;n++) {
356  bool isNew;
357  metadb_handle_ptr h; p_list.get_item_ex(h, n);
358  beenHere.add_ex( h->get_path(), isNew);
359  if (isNew) {
360  t_filesize t = h->get_filesize();
361  if (t == filesize_invalid) {
362  if (!skipUnknown) return filesize_invalid;
363  } else {
364  ret += t;
365  }
366  }
367  }
368  return ret;
369 }
static const t_filesize filesize_invalid
Invalid/unknown file size constant. Also see: t_filesize.
Definition: filesystem.h:16
t_storage & add_ex(const t_param &p_item, bool &p_isnew)
Definition: avltree.h:476
size_t t_size
Definition: int_types.h:48
t_uint64 t_filesize
Type used for file size related variables.
Definition: filesystem.h:8
t_filesize metadb_handle_list_helper::calc_total_size_ex ( metadb_handle_list_cref  list,
bool &  foundUnknown 
)

Definition at line 371 of file metadb_handle_list.cpp.

371  {
372  foundUnknown = false;
373  metadb_handle_list list(p_list);
375 
376  t_filesize ret = 0;
377  t_size n, m = list.get_count();
378  for(n=0;n<m;n++) {
379  if (n==0 || metadb::path_compare(list[n-1]->get_path(),list[n]->get_path())) {
380  t_filesize t = list[n]->get_filesize();
381  if (t == filesize_invalid) {
382  foundUnknown = true;
383  } else {
384  ret += t;
385  }
386  }
387  }
388  return ret;
389 }
static const t_filesize filesize_invalid
Invalid/unknown file size constant. Also see: t_filesize.
Definition: filesystem.h:16
size_t t_size
Definition: int_types.h:48
virtual t_size get_count() const =0
static int path_compare(const char *p1, const char *p2)
Definition: metadb.h:245
t_uint64 t_filesize
Type used for file size related variables.
Definition: filesystem.h:8
static int path_compare_metadb_handle(const metadb_handle_ptr &p1, const metadb_handle_ptr &p2)
Definition: metadb.h:246
bool metadb_handle_list_helper::extract_single_path ( metadb_handle_list_cref  list,
const char *&  path 
)

Definition at line 391 of file metadb_handle_list.cpp.

391  {
392  const t_size total = list.get_count();
393  if (total == 0) return false;
394  const char * path = list[0]->get_path();
395  for(t_size walk = 1; walk < total; ++walk) {
396  if (metadb::path_compare(path, list[walk]->get_path()) != 0) return false;
397  }
398  pathOut = path;
399  return true;
400 }
size_t t_size
Definition: int_types.h:48
virtual t_size get_count() const =0
static int path_compare(const char *p1, const char *p2)
Definition: metadb.h:245
void metadb_handle_list_helper::remove_duplicates ( pfc::list_base_t< metadb_handle_ptr > &  p_list)
void metadb_handle_list_helper::sort_by_format ( metadb_handle_list_ref  p_list,
const char *  spec,
titleformat_hook p_hook 
)

Definition at line 31 of file metadb_handle_list.cpp.

32 {
35  sort_by_format(p_list,script,p_hook);
36 }
This is free and unencumbered software released into the public domain Anyone is free to compile
Definition: pfc-license.txt:3
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
void sort_by_format(metadb_handle_list_ref p_list, const char *spec, titleformat_hook *p_hook)
void metadb_handle_list_helper::sort_by_format ( metadb_handle_list_ref  p_list,
const service_ptr_t< titleformat_object > &  p_script,
titleformat_hook p_hook,
int  direction = 1 
)

Definition at line 45 of file metadb_handle_list.cpp.

46 {
47  const t_size count = p_list.get_count();
48  pfc::array_t<t_size> order; order.set_size(count);
49  sort_by_format_get_order(p_list,order.get_ptr(),p_script,p_hook,direction);
50  p_list.reorder(order.get_ptr());
51 }
const t_item * get_ptr() const
Definition: array.h:213
size_t t_size
Definition: int_types.h:48
void set_size(t_size p_size)
Definition: array.h:104
virtual t_size get_count() const =0
void sort_by_format_get_order(metadb_handle_list_cref p_list, t_size *order, const char *spec, titleformat_hook *p_hook)
void reorder(const t_size *p_data)
Definition: list.h:201
void metadb_handle_list_helper::sort_by_format_get_order ( metadb_handle_list_cref  p_list,
t_size order,
const char *  spec,
titleformat_hook p_hook 
)

Definition at line 38 of file metadb_handle_list.cpp.

39 {
42  sort_by_format_get_order(p_list,order,script,p_hook);
43 }
This is free and unencumbered software released into the public domain Anyone is free to compile
Definition: pfc-license.txt:3
void sort_by_format_get_order(metadb_handle_list_cref p_list, t_size *order, const char *spec, titleformat_hook *p_hook)
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
void metadb_handle_list_helper::sort_by_format_get_order ( metadb_handle_list_cref  p_list,
t_size order,
const service_ptr_t< titleformat_object > &  p_script,
titleformat_hook p_hook,
int  p_direction = 1 
)

Definition at line 121 of file metadb_handle_list.cpp.

122 {
123 // pfc::hires_timer timer; timer.start();
124 
125  const t_size count = p_list.get_count();
126  pfc::array_t<custom_sort_data> data; data.set_size(count);
127 
128  {
129  pfc::counter counter(0);
131  PFC_ASSERT( threads.get_size() > 0 );
132  for(t_size walk = 0; walk < threads.get_size(); ++walk) {
133  threads[walk].new_t(&counter,p_list,data.get_ptr(),p_script,p_hook);
134  }
135  for(t_size walk = 1; walk < threads.get_size(); ++walk) threads[walk]->start();
136  threads[0]->threadProc();
137  for(t_size walk = 1; walk < threads.get_size(); ++walk) threads[walk]->waitTillDone();
138  }
139 // console::formatter() << "metadb_handle sort: prepared in " << pfc::format_time_ex(timer.query(),6);
140 
141  pfc::sort_t(data, p_direction > 0 ? custom_sort_compare<1> : custom_sort_compare<-1>,count);
142  //qsort(data.get_ptr(),count,sizeof(custom_sort_data),p_direction > 0 ? _custom_sort_compare<1> : _custom_sort_compare<-1>);
143 
144 
145 // console::formatter() << "metadb_handle sort: sorted in " << pfc::format_time_ex(timer.query(),6);
146 
147  for(t_size n=0;n<count;n++)
148  {
149  order[n]=data[n].index;
150  delete[] data[n].text;
151  }
152 
153 // console::formatter() << "metadb_handle sort: finished in " << pfc::format_time_ex(timer.query(),6);
154 }
const t_item * get_ptr() const
Definition: array.h:213
t_size getOptimalWorkerThreadCountEx(t_size taskCountLimit)
Definition: threads.cpp:43
size_t t_size
Definition: int_types.h:48
void set_size(t_size p_size)
Definition: array.h:104
virtual t_size get_count() const =0
static void sort_t(t_container &p_data, t_compare p_compare, t_size p_count)
Definition: sort.h:162
t_size get_size() const
Definition: array.h:130
void metadb_handle_list_helper::sort_by_path ( pfc::list_base_t< metadb_handle_ptr > &  p_list)
void metadb_handle_list_helper::sort_by_path_quick ( pfc::list_base_t< metadb_handle_ptr > &  p_list)
void metadb_handle_list_helper::sort_by_pointer ( pfc::list_base_t< metadb_handle_ptr > &  p_list)
void metadb_handle_list_helper::sort_by_pointer_remove_duplicates ( pfc::list_base_t< metadb_handle_ptr > &  p_list)
void metadb_handle_list_helper::sort_by_relative_path ( metadb_handle_list_ref  p_list)

Definition at line 156 of file metadb_handle_list.cpp.

157 {
158  const t_size count = p_list.get_count();
159  pfc::array_t<t_size> order; order.set_size(count);
161  p_list.reorder(order.get_ptr());
162 }
void sort_by_relative_path_get_order(metadb_handle_list_cref p_list, t_size *order)
const t_item * get_ptr() const
Definition: array.h:213
size_t t_size
Definition: int_types.h:48
void set_size(t_size p_size)
Definition: array.h:104
virtual t_size get_count() const =0
void reorder(const t_size *p_data)
Definition: list.h:201
void metadb_handle_list_helper::sort_by_relative_path_get_order ( metadb_handle_list_cref  p_list,
t_size order 
)

Definition at line 164 of file metadb_handle_list.cpp.

165 {
166  const t_size count = p_list.get_count();
167  t_size n;
169  data.set_size(count);
171 
173  temp.prealloc(512);
174  for(n=0;n<count;n++)
175  {
176  metadb_handle_ptr item;
177  p_list.get_item_ex(item,n);
178  if (!api->get_relative_path(item,temp)) temp = "";
179  data[n].index = n;
180  data[n].text = makeSortString(temp);
181  //data[n].subsong = item->get_subsong_index();
182  }
183 
184  pfc::sort_t(data,custom_sort_compare<1>,count);
185  //qsort(data.get_ptr(),count,sizeof(custom_sort_data),(int (__cdecl *)(const void *elem1, const void *elem2 ))custom_sort_compare);
186 
187  for(n=0;n<count;n++)
188  {
189  order[n]=data[n].index;
190  delete[] data[n].text;
191  }
192 }
size_t t_size
Definition: int_types.h:48
void set_size(t_size p_size)
Definition: array.h:104
virtual t_size get_count() const =0
static void sort_t(t_container &p_data, t_compare p_compare, t_size p_count)
Definition: sort.h:162
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
virtual void get_item_ex(T &p_out, t_size n) const =0
string8_t< pfc::alloc_fast_aggressive > string8_fastalloc
Definition: string_base.h:436
void metadb_handle_list_helper::sorted_by_pointer_extract_difference ( metadb_handle_list const &  p_list_1,
metadb_handle_list const &  p_list_2,
metadb_handle_list p_list_1_specific,
metadb_handle_list p_list_2_specific 
)

Definition at line 272 of file metadb_handle_list.cpp.

273 {
274  t_size found_1, found_2;
275  const t_size count_1 = p_list_1.get_count(), count_2 = p_list_2.get_count();
276  t_size ptr_1, ptr_2;
277 
278  found_1 = found_2 = 0;
279  ptr_1 = ptr_2 = 0;
280  while(ptr_1 < count_1 || ptr_2 < count_2)
281  {
282  while(ptr_1 < count_1 && (ptr_2 == count_2 || p_list_1[ptr_1] < p_list_2[ptr_2]))
283  {
284  found_1++;
285  t_size ptr_1_new = ptr_1 + 1;
286  while(ptr_1_new < count_1 && p_list_1[ptr_1_new] == p_list_1[ptr_1]) ptr_1_new++;
287  ptr_1 = ptr_1_new;
288  }
289  while(ptr_2 < count_2 && (ptr_1 == count_1 || p_list_2[ptr_2] < p_list_1[ptr_1]))
290  {
291  found_2++;
292  t_size ptr_2_new = ptr_2 + 1;
293  while(ptr_2_new < count_2 && p_list_2[ptr_2_new] == p_list_2[ptr_2]) ptr_2_new++;
294  ptr_2 = ptr_2_new;
295  }
296  while(ptr_1 < count_1 && ptr_2 < count_2 && p_list_1[ptr_1] == p_list_2[ptr_2]) {ptr_1++; ptr_2++;}
297  }
298 
299 
300 
301  p_list_1_specific.set_count(found_1);
302  p_list_2_specific.set_count(found_2);
303  if (found_1 > 0 || found_2 > 0)
304  {
305  found_1 = found_2 = 0;
306  ptr_1 = ptr_2 = 0;
307 
308  while(ptr_1 < count_1 || ptr_2 < count_2)
309  {
310  while(ptr_1 < count_1 && (ptr_2 == count_2 || p_list_1[ptr_1] < p_list_2[ptr_2]))
311  {
312  p_list_1_specific[found_1++] = p_list_1[ptr_1];
313  t_size ptr_1_new = ptr_1 + 1;
314  while(ptr_1_new < count_1 && p_list_1[ptr_1_new] == p_list_1[ptr_1]) ptr_1_new++;
315  ptr_1 = ptr_1_new;
316  }
317  while(ptr_2 < count_2 && (ptr_1 == count_1 || p_list_2[ptr_2] < p_list_1[ptr_1]))
318  {
319  p_list_2_specific[found_2++] = p_list_2[ptr_2];
320  t_size ptr_2_new = ptr_2 + 1;
321  while(ptr_2_new < count_2 && p_list_2[ptr_2_new] == p_list_2[ptr_2]) ptr_2_new++;
322  ptr_2 = ptr_2_new;
323  }
324  while(ptr_1 < count_1 && ptr_2 < count_2 && p_list_1[ptr_1] == p_list_2[ptr_2]) {ptr_1++; ptr_2++;}
325  }
326 
327  }
328 }
void set_count(t_size p_count)
Definition: list.h:315
size_t t_size
Definition: int_types.h:48