00001 class titleformat_hook;
00002 class titleformat_text_filter;
00003
00008
00009 class NOVTABLE metadb_handle : public service_base
00010 {
00011 public:
00013 virtual const playable_location & get_location() const = 0;
00014
00015
00022 virtual bool format_title(titleformat_hook * p_hook,pfc::string_base & p_out,const service_ptr_t<class titleformat_object> & p_script,titleformat_text_filter * p_filter) = 0;
00023
00026 virtual void metadb_lock() = 0;
00029 virtual void metadb_unlock() = 0;
00030
00032 virtual t_filestats get_filestats() const = 0;
00033
00036 virtual bool is_info_loaded() const = 0;
00039 virtual bool get_info(file_info & p_info) const = 0;
00044 virtual bool get_info_locked(const file_info * & p_info) const = 0;
00045
00048 virtual bool is_info_loaded_async() const = 0;
00051 virtual bool get_info_async(file_info & p_info) const = 0;
00056 virtual bool get_info_async_locked(const file_info * & p_info) const = 0;
00057
00058
00060 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<class titleformat_object> & p_script,titleformat_text_filter * p_filter) = 0;
00061
00062
00064 virtual bool format_title_nonlocking(titleformat_hook * p_hook,pfc::string_base & p_out,const service_ptr_t<class titleformat_object> & p_script,titleformat_text_filter * p_filter) = 0;
00065
00067 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<class titleformat_object> & p_script,titleformat_text_filter * p_filter) = 0;
00068
00069 static bool g_should_reload(const t_filestats & p_old_stats,const t_filestats & p_new_stats,bool p_fresh);
00070 bool should_reload(const t_filestats & p_new_stats,bool p_fresh) const;
00071
00072
00076 bool format_title_legacy(titleformat_hook * p_hook,pfc::string_base & out,const char * p_spec,titleformat_text_filter * p_filter);
00077
00079 inline const char * get_path() const {return get_location().get_path();}
00081 inline t_uint32 get_subsong_index() const {return get_location().get_subsong_index();}
00082
00083 double get_length();
00084
00085 t_filetimestamp get_filetimestamp();
00086 t_filesize get_filesize();
00087
00088 FB2K_MAKE_SERVICE_INTERFACE(metadb_handle,service_base);
00089 };
00090
00091 typedef service_ptr_t<metadb_handle> metadb_handle_ptr;
00092
00093 typedef pfc::list_base_t<metadb_handle_ptr> & metadb_handle_list_ref;
00094 typedef pfc::list_base_const_t<metadb_handle_ptr> const & metadb_handle_list_cref;
00095
00096 namespace metadb_handle_list_helper {
00097 void sort_by_format(metadb_handle_list_ref p_list,const char * spec,titleformat_hook * p_hook);
00098 void sort_by_format_get_order(metadb_handle_list_cref p_list,t_size* order,const char * spec,titleformat_hook * p_hook);
00099 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);
00100 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);
00101
00102 void sort_by_relative_path(metadb_handle_list_ref p_list);
00103 void sort_by_relative_path_get_order(metadb_handle_list_cref p_list,t_size* order);
00104
00105 void remove_duplicates(pfc::list_base_t<metadb_handle_ptr> & p_list);
00106 void sort_by_pointer_remove_duplicates(pfc::list_base_t<metadb_handle_ptr> & p_list);
00107 void sort_by_path_quick(pfc::list_base_t<metadb_handle_ptr> & p_list);
00108
00109 void sort_by_pointer(pfc::list_base_t<metadb_handle_ptr> & p_list);
00110 t_size bsearch_by_pointer(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,const metadb_handle_ptr & val);
00111
00112 double calc_total_duration(const pfc::list_base_const_t<metadb_handle_ptr> & p_list);
00113
00114 void sort_by_path(pfc::list_base_t<metadb_handle_ptr> & p_list);
00115
00116 t_filesize calc_total_size(metadb_handle_list_cref list, bool skipUnknown = false);
00117 t_filesize calc_total_size_ex(metadb_handle_list_cref list, bool & foundUnknown);
00118 };
00119
00120 template<template<typename> class t_alloc = pfc::alloc_fast >
00121 class metadb_handle_list_t : public service_list_t<metadb_handle,t_alloc> {
00122 private:
00123 typedef metadb_handle_list_t<t_alloc> t_self;
00124 typedef list_base_const_t<metadb_handle_ptr> t_interface;
00125 public:
00126 inline void sort_by_format(const char * spec,titleformat_hook * p_hook) {
00127 return metadb_handle_list_helper::sort_by_format(*this, spec, p_hook);
00128 }
00129 inline void sort_by_format_get_order(t_size* order,const char * spec,titleformat_hook * p_hook) const {
00130 metadb_handle_list_helper::sort_by_format_get_order(*this, order, spec, p_hook);
00131 }
00132
00133 inline void sort_by_format(const service_ptr_t<titleformat_object> & p_script,titleformat_hook * p_hook, int direction = 1) {
00134 metadb_handle_list_helper::sort_by_format(*this, p_script, p_hook, direction);
00135 }
00136 inline void sort_by_format_get_order(t_size* order,const service_ptr_t<titleformat_object> & p_script,titleformat_hook * p_hook) const {
00137 metadb_handle_list_helper::sort_by_format_get_order(*this, order, p_script, p_hook);
00138 }
00139
00140 inline void sort_by_relative_path() {
00141 metadb_handle_list_helper::sort_by_relative_path(*this);
00142 }
00143 inline void sort_by_relative_path_get_order(t_size* order) const {
00144 metadb_handle_list_helper::sort_by_relative_path_get_order(*this,order);
00145 }
00146
00147 inline void remove_duplicates() {metadb_handle_list_helper::remove_duplicates(*this);}
00148 inline void sort_by_pointer_remove_duplicates() {metadb_handle_list_helper::sort_by_pointer_remove_duplicates(*this);}
00149 inline void sort_by_path_quick() {metadb_handle_list_helper::sort_by_path_quick(*this);}
00150
00151 inline void sort_by_pointer() {metadb_handle_list_helper::sort_by_pointer(*this);}
00152 inline t_size bsearch_by_pointer(const metadb_handle_ptr & val) const {return metadb_handle_list_helper::bsearch_by_pointer(*this,val);}
00153
00154 inline double calc_total_duration() const {return metadb_handle_list_helper::calc_total_duration(*this);}
00155
00156 inline void sort_by_path() {metadb_handle_list_helper::sort_by_path(*this);}
00157
00158 const t_self & operator=(const t_self & p_source) {remove_all(); add_items(p_source);return *this;}
00159 const t_self & operator=(const t_interface & p_source) {remove_all(); add_items(p_source);return *this;}
00160 metadb_handle_list_t(const t_self & p_source) {add_items(p_source);}
00161 metadb_handle_list_t(const t_interface & p_source) {add_items(p_source);}
00162 metadb_handle_list_t() {}
00163
00164 t_self & operator+=(const t_interface & source) {add_items(source); return *this;}
00165 t_self & operator+=(const metadb_handle_ptr & source) {add_item(source); return *this;}
00166 };
00167
00168 typedef metadb_handle_list_t<> metadb_handle_list;
00169
00170 namespace metadb_handle_list_helper {
00171 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);
00172 };
00173
00174 class metadb_handle_lock
00175 {
00176 metadb_handle_ptr m_ptr;
00177 public:
00178 inline metadb_handle_lock(const metadb_handle_ptr & param)
00179 {
00180 m_ptr = param;
00181 m_ptr->metadb_lock();
00182 }
00183 inline ~metadb_handle_lock() {m_ptr->metadb_unlock();}
00184 };
00185
00186 inline pfc::string_base & operator<<(pfc::string_base & p_fmt,const metadb_handle_ptr & p_location) {
00187 if (p_location.is_valid())
00188 return p_fmt << p_location->get_location();
00189 else
00190 return p_fmt << "[invalid location]";
00191 }
00192
00193
00194 class string_format_title {
00195 public:
00196 string_format_title(metadb_handle_ptr p_item,const char * p_script) {
00197 p_item->format_title_legacy(NULL,m_data,p_script,NULL);
00198 }
00199 string_format_title(metadb_handle_ptr p_item,service_ptr_t<class titleformat_object> p_script) {
00200 p_item->format_title(NULL,m_data,p_script,NULL);
00201 }
00202
00203 const char * get_ptr() const {return m_data.get_ptr();}
00204 operator const char * () const {return m_data.get_ptr();}
00205 private:
00206 pfc::string8_fastalloc m_data;
00207 };