foobar2000 SDK  2015-08-03
metadb_handle.h
Go to the documentation of this file.
1 class titleformat_hook;
4 
5 
8 public:
9  virtual file_info const & info() = 0;
10  virtual t_filestats const & stats() = 0;
11  virtual bool isInfoPartial() = 0;
12 };
13 
18 
19 class NOVTABLE metadb_handle : public service_base
20 {
21 public:
23  virtual const playable_location & get_location() const = 0;//never fails, returned pointer valid till the object is released
24 
25 
32  virtual bool format_title(titleformat_hook * p_hook,pfc::string_base & p_out,const service_ptr_t<titleformat_object> & p_script,titleformat_text_filter * p_filter) = 0;
33 
35  __declspec(deprecated) virtual void metadb_lock() = 0;
37  __declspec(deprecated) virtual void metadb_unlock() = 0;
38 
40  virtual t_filestats get_filestats() const = 0;
41 
44  virtual bool is_info_loaded() const = 0;
47  virtual bool get_info(file_info & p_info) const = 0;
48 
50  __declspec(deprecated) virtual bool get_info_locked(const file_info * & p_info) const = 0;
51 
54  virtual bool is_info_loaded_async() const = 0;
57  virtual bool get_info_async(file_info & p_info) const = 0;
58 
60  __declspec(deprecated) virtual bool get_info_async_locked(const file_info * & p_info) const = 0;
61 
63  virtual void format_title_from_external_info(const file_info & p_info,titleformat_hook * p_hook,pfc::string_base & p_out,const service_ptr_t<titleformat_object> & p_script,titleformat_text_filter * p_filter) = 0;
64 
66  __declspec(deprecated) virtual bool format_title_nonlocking(titleformat_hook * p_hook,pfc::string_base & p_out,const service_ptr_t<titleformat_object> & p_script,titleformat_text_filter * p_filter) = 0;
68  __declspec(deprecated) virtual void format_title_from_external_info_nonlocking(const file_info & p_info,titleformat_hook * p_hook,pfc::string_base & p_out,const service_ptr_t<titleformat_object> & p_script,titleformat_text_filter * p_filter) = 0;
69 
70 #if FOOBAR2000_TARGET_VERSION >= 76
71  virtual bool get_browse_info(file_info & info, t_filetimestamp & ts) const = 0;
73 
75  __declspec(deprecated) virtual bool get_browse_info_locked(const file_info * & p_info, t_filetimestamp & ts) const = 0;
76 #endif
77 #if FOOBAR2000_TARGET_VERSION >= 78
78  virtual bool get_info_ref(metadb_info_container::ptr & outInfo) const = 0;
83 
88  virtual bool get_async_info_ref(metadb_info_container::ptr & outInfo) const = 0;
89 
94  virtual void get_browse_info_ref(metadb_info_container::ptr & outInfo, metadb_info_container::ptr & outBrowse) const = 0;
95 
97  virtual metadb_info_container::ptr get_info_ref() const = 0;
99  virtual metadb_info_container::ptr get_async_info_ref() const = 0;
100 
104  metadb_info_container::ptr get_full_info_ref( abort_callback & aborter ) const;
105 #endif
106 
112  bool get_browse_info_merged(file_info & infoMerged) const;
113 
114 
115  static bool g_should_reload(const t_filestats & p_old_stats,const t_filestats & p_new_stats,bool p_fresh);
116  bool should_reload(const t_filestats & p_new_stats,bool p_fresh) const;
117 
118 
122  bool format_title_legacy(titleformat_hook * p_hook,pfc::string_base & out,const char * p_spec,titleformat_text_filter * p_filter);
123 
125  inline const char * get_path() const {return get_location().get_path();}
127  inline t_uint32 get_subsong_index() const {return get_location().get_subsong_index();}
128 
129  double get_length();//helper
130 
131  t_filetimestamp get_filetimestamp();
132  t_filesize get_filesize();
133 
135 };
136 
138 
141 
143  void sort_by_format(metadb_handle_list_ref p_list,const char * spec,titleformat_hook * p_hook);
144  void sort_by_format_get_order(metadb_handle_list_cref p_list,t_size* order,const char * spec,titleformat_hook * p_hook);
145  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);
146  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);
147 
148  void sort_by_relative_path(metadb_handle_list_ref p_list);
149  void sort_by_relative_path_get_order(metadb_handle_list_cref p_list,t_size* order);
150 
154 
156  t_size bsearch_by_pointer(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,const metadb_handle_ptr & val);
157 
159 
161 
162  t_filesize calc_total_size(metadb_handle_list_cref list, bool skipUnknown = false);
163  t_filesize calc_total_size_ex(metadb_handle_list_cref list, bool & foundUnknown);
164 
165  bool extract_single_path(metadb_handle_list_cref list, const char * &path);
166 };
167 
168 template<template<typename> class t_alloc = pfc::alloc_fast >
169 class metadb_handle_list_t : public service_list_t<metadb_handle,t_alloc> {
170 private:
172  typedef list_base_const_t<metadb_handle_ptr> t_interface;
173 public:
174  inline void sort_by_format(const char * spec,titleformat_hook * p_hook) {
175  return metadb_handle_list_helper::sort_by_format(*this, spec, p_hook);
176  }
177  inline void sort_by_format_get_order(t_size* order,const char * spec,titleformat_hook * p_hook) const {
178  metadb_handle_list_helper::sort_by_format_get_order(*this, order, spec, p_hook);
179  }
180 
181  inline void sort_by_format(const service_ptr_t<titleformat_object> & p_script,titleformat_hook * p_hook, int direction = 1) {
182  metadb_handle_list_helper::sort_by_format(*this, p_script, p_hook, direction);
183  }
184  inline void sort_by_format_get_order(t_size* order,const service_ptr_t<titleformat_object> & p_script,titleformat_hook * p_hook) const {
185  metadb_handle_list_helper::sort_by_format_get_order(*this, order, p_script, p_hook);
186  }
187 
188  inline void sort_by_relative_path() {
190  }
191  inline void sort_by_relative_path_get_order(t_size* order) const {
193  }
194 
198 
200  inline t_size bsearch_by_pointer(const metadb_handle_ptr & val) const {return metadb_handle_list_helper::bsearch_by_pointer(*this,val);}
201 
203 
205 
206  const t_self & operator=(const t_self & p_source) {remove_all(); add_items(p_source);return *this;}
207  const t_self & operator=(const t_interface & p_source) {remove_all(); add_items(p_source);return *this;}
208  const t_self & operator=(t_self && p_source) {move_from(p_source); return *this; }
209  metadb_handle_list_t(const t_self & p_source) {add_items(p_source);}
210  metadb_handle_list_t(const t_interface & p_source) {add_items(p_source);}
212 
213  metadb_handle_list_t(t_self && p_source) {move_from(p_source);}
214 
215  t_self & operator+=(const t_interface & source) {add_items(source); return *this;}
216  t_self & operator+=(const metadb_handle_ptr & source) {add_item(source); return *this;}
217 
218  bool extract_single_path(const char * &path) const {return metadb_handle_list_helper::extract_single_path(*this, path);}
219 };
220 
222 
223 namespace metadb_handle_list_helper {
224  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);
225 };
226 
227 
228 inline pfc::string_base & operator<<(pfc::string_base & p_fmt,const metadb_handle_ptr & p_location) {
229  if (p_location.is_valid())
230  return p_fmt << p_location->get_location();
231  else
232  return p_fmt << "[invalid location]";
233 }
234 
235 
237 public:
238  string_format_title(metadb_handle_ptr p_item,const char * p_script) {
239  p_item->format_title_legacy(NULL,m_data,p_script,NULL);
240  }
242  p_item->format_title(NULL,m_data,p_script,NULL);
243  }
244 
245  const char * get_ptr() const {return m_data.get_ptr();}
246  operator const char * () const {return m_data.get_ptr();}
247 private:
249 };
void sort_by_format(const service_ptr_t< titleformat_object > &p_script, titleformat_hook *p_hook, int direction=1)
bool extract_single_path(metadb_handle_list_cref list, const char *&path)
void sort_by_relative_path_get_order(metadb_handle_list_cref p_list, t_size *order)
void sort_by_format_get_order(t_size *order, const service_ptr_t< titleformat_object > &p_script, titleformat_hook *p_hook) const
void remove_duplicates(pfc::list_base_t< metadb_handle_ptr > &p_list)
FB2K_MAKE_SERVICE_INTERFACE(metadb_info_container, service_base)
void sort_by_pointer(pfc::list_base_t< metadb_handle_ptr > &p_list)
t_self & operator+=(const t_interface &source)
string_format_title(metadb_handle_ptr p_item, service_ptr_t< class titleformat_object > p_script)
virtual bool isInfoPartial()=0
pfc::list_base_t< metadb_handle_ptr > & metadb_handle_list_ref
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)
const t_self & operator=(const t_interface &p_source)
double calc_total_duration() const
void sort_by_format_get_order(t_size *order, const char *spec, titleformat_hook *p_hook) const
__declspec(dllexport) foobar2000_client *_cdecl foobar2000_get_interface(foobar2000_api *p_api
void sort_by_path_quick(pfc::list_base_t< metadb_handle_ptr > &p_list)
void sort_by_pointer_remove_duplicates()
metadb_handle_list_t metadb_handle_list
A metadb_handle object represents interface to reference-counted file_info cache entry for the specif...
Definition: metadb_handle.h:19
const char * get_path() const
Retrieves path of item described by this metadb_handle instance. Returned string is valid until calli...
const t_self & operator=(t_self &&p_source)
bool is_valid() const
Definition: service.h:119
Main interface class for information about some playable object.
Definition: file_info.h:73
t_self & operator+=(const metadb_handle_ptr &source)
pfc::list_base_const_t< metadb_handle_ptr > const & metadb_handle_list_cref
const char * get_ptr() const
metadb_handle_list_t(const t_interface &p_source)
size_t t_size
Definition: int_types.h:48
void sort_by_format(const char *spec, titleformat_hook *p_hook)
metadb_handle_list_t(const t_self &p_source)
double calc_total_duration(const pfc::list_base_const_t< metadb_handle_ptr > &p_list)
Base class for all service classes. Provides interfaces for reference counter and querying for differ...
Definition: service.h:333
metadb_handle_list_t(t_self &&p_source)
list_base_const_t< metadb_handle_ptr > t_interface
void sort_by_relative_path_get_order(t_size *order) const
virtual file_info const & info()=0
t_size bsearch_by_pointer(const pfc::list_base_const_t< metadb_handle_ptr > &p_list, const metadb_handle_ptr &val)
void sort_by_format_get_order(metadb_handle_list_cref p_list, t_size *order, const char *spec, titleformat_hook *p_hook)
pfc::string8_fastalloc m_data
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)
t_uint64 t_filetimestamp
Type used for file timestamp related variables. 64-bit value representing the number of 100-nanosecon...
Definition: filesystem.h:12
pfc::string_base & operator<<(pfc::string_base &p_fmt, const metadb_handle_ptr &p_location)
const t_self & operator=(const t_self &p_source)
t_uint64 t_filesize
Type used for file size related variables.
Definition: filesystem.h:8
t_filesize calc_total_size(metadb_handle_list_cref list, bool skipUnknown=false)
metadb_handle_list_t< t_alloc > t_self
t_size bsearch_by_pointer(const metadb_handle_ptr &val) const
void sort_by_relative_path(metadb_handle_list_ref p_list)
bool extract_single_path(const char *&path) const
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)
service_ptr_t< metadb_handle > metadb_handle_ptr
t_filesize calc_total_size_ex(metadb_handle_list_cref list, bool &foundUnknown)
void sort_by_path(pfc::list_base_t< metadb_handle_ptr > &p_list)
void sort_by_pointer_remove_duplicates(pfc::list_base_t< metadb_handle_ptr > &p_list)
t_uint32 get_subsong_index() const
Retrieves subsong index of item described by this metadb_handle instance (used for multiple playable ...
string_format_title(metadb_handle_ptr p_item, const char *p_script)
string8_t< pfc::alloc_fast_aggressive > string8_fastalloc
Definition: string_base.h:436
Represents precompiled executable title-formatting script. Use titleformat_compiler to instantiate; d...
Definition: titleformat.h:41
virtual t_filestats const & stats()=0
uint32_t t_uint32
Definition: int_types.h:5
void sort_by_format(metadb_handle_list_ref p_list, const char *spec, titleformat_hook *p_hook)