foobar2000 SDK  2015-01-14
input_file_type.h
Go to the documentation of this file.
1 class input_file_type : public service_base {
4 public:
5  virtual unsigned get_count()=0;
6  virtual bool get_name(unsigned idx,pfc::string_base & out)=0;//eg. "MPEG files"
7  virtual bool get_mask(unsigned idx,pfc::string_base & out)=0;//eg. "*.MP3;*.MP2"; separate with semicolons
8  virtual bool is_associatable(unsigned idx) = 0;
9 
10 #if FOOBAR2000_TARGET_VERSION >= 76
11  static void build_openfile_mask(pfc::string_base & out,bool b_include_playlists=true);
14 #endif
15 
17 };
18 
22 public:
23  virtual void get_format_name(unsigned idx, pfc::string_base & out, bool isPlural) = 0;
24  virtual void get_extensions(unsigned idx, pfc::string_base & out) = 0;
25 
26  //Deprecated input_file_type method implementations:
27  bool get_name(unsigned idx, pfc::string_base & out) {get_format_name(idx, out, true); return true;}
28  bool get_mask(unsigned idx, pfc::string_base & out) {
29  pfc::string_formatter temp; get_extensions(idx,temp);
31  if (exts.get_count() == 0) return false;//should not happen
32  temp.reset();
33  for(pfc::const_iterator<pfc::string> walk = exts.first(); walk.is_valid(); ++walk) {
34  if (!temp.is_empty()) temp << ";";
35  temp << "*." << walk->get_ptr();
36  }
37  out = temp;
38  return true;
39  }
40 
41  FB2K_MAKE_SERVICE_INTERFACE(input_file_type_v2,input_file_type)
42 };
43 
44 
46 class input_file_type_impl : public service_impl_single_t<input_file_type>
47 {
48  const char * name, * mask;
50 public:
51  input_file_type_impl(const char * p_name, const char * p_mask,bool p_associatable) : name(p_name), mask(p_mask), m_associatable(p_associatable) {}
52  unsigned get_count() {return 1;}
53  bool get_name(unsigned idx,pfc::string_base & out) {if (idx==0) {out = name; return true;} else return false;}
54  bool get_mask(unsigned idx,pfc::string_base & out) {if (idx==0) {out = mask; return true;} else return false;}
55  bool is_associatable(unsigned idx) {return m_associatable;}
56 };
57 
58 
61 #define DECLARE_FILE_TYPE(NAME,MASK) \
62  namespace { static input_file_type_impl g_filetype_instance(NAME,MASK,true); \
63  static service_factory_single_ref_t<input_file_type_impl> g_filetype_service(g_filetype_instance); }
64 
65 
66 
67 
71 {
72 public:
73  input_file_type_factory(const char * p_name,const char * p_mask,bool p_associatable)
74  : service_factory_single_transparent_t<input_file_type_impl>(p_name,p_mask,p_associatable) {}
75 };
76 
77 
78 
80 public:
81  input_file_type_v2_impl(const char * extensions,const char * name, const char * namePlural) : m_extensions(extensions), m_name(name), m_namePlural(namePlural) {}
82  unsigned get_count() {return 1;}
83  bool is_associatable(unsigned idx) {return true;}
84  void get_format_name(unsigned idx, pfc::string_base & out, bool isPlural) {
85  out = isPlural ? m_namePlural : m_name;
86  }
87  void get_extensions(unsigned idx, pfc::string_base & out) {
88  out = m_extensions;
89  }
90 
91 private:
93 };
94 
97 #define DECLARE_FILE_TYPE_EX(extensions, name, namePlural) \
98  namespace { static service_factory_single_t<input_file_type_v2_impl> g_myfiletype(extensions, name, namePlural); }
99 
100 
103  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(input_protocol_type)
104 public:
106  virtual void get_protocol_name(pfc::string_base & out) = 0;
108  virtual void get_description(pfc::string_base & out) = 0;
109 };
bool is_associatable(unsigned idx)
bool get_mask(unsigned idx, pfc::string_base &out)
void get_extensions(unsigned idx, pfc::string_base &out)
const pfc::string8 m_name
void get_format_name(unsigned idx, pfc::string_base &out, bool isPlural)
bool get_name(unsigned idx, pfc::string_base &out)
input_file_type_impl(const char *p_name, const char *p_mask, bool p_associatable)
virtual unsigned get_count()=0
virtual void get_extensions(unsigned idx, pfc::string_base &out)=0
virtual FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(input_protocol_type) public void get_description(pfc::string_base &out)=0
Returns a human-readable description of the protocol.
bool get_mask(unsigned idx, pfc::string_base &out)
input_file_type_factory(const char *p_name, const char *p_mask, bool p_associatable)
Differences between chain_list_v2_t<> and old chain_list_t<>: Iterators pointing to removed items as...
Definition: chain_list_v2.h:26
Implementation helper. Usage: static input_file_type_factory mytype("blah type","*.bla;*.meh",true);.
virtual bool is_associatable(unsigned idx)=0
Template implementing dummy version of reference-counting features of service_base. Intended for static/local/member instantiation: "static service_impl_single_t myvar(params);". Because reference counting features are disabled (dummy reference counter), code instantiating it is responsible for deleting it as well as ensuring that no references are active when the object gets deleted. Note that some constructor parameters such as NULL will need explicit typecasts to ensure correctly guessed types for constructor function template (null string needs to be (const char*)NULL rather than just NULL, etc).
Definition: service_impl.h:44
static void make_extension_support_fingerprint(pfc::string_base &str)
bool is_valid() const
Definition: iterators.h:24
Service for registering protocol types that can be associated with foobar2000.
t_size get_count() const
Definition: chain_list_v2.h:61
string8_fastalloc string_formatter
Definition: string_base.h:614
Extended interface for registering media file types that can be associated with foobar2000 applicatio...
virtual bool get_name(unsigned idx, pfc::string_base &out)=0
Base class for all service classes. Provides interfaces for reference counter and querying for differ...
Definition: service.h:333
bool is_associatable(unsigned idx)
static void make_filetype_support_fingerprint(pfc::string_base &str)
FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(input_file_type)
const pfc::string8 m_namePlural
Implementation helper.
static void build_openfile_mask(pfc::string_base &out, bool b_include_playlists=true)
bool get_name(unsigned idx, pfc::string_base &out)
virtual void get_format_name(unsigned idx, pfc::string_base &out, bool isPlural)=0
void splitStringSimple_toList(t_list &p_output, t_split p_split, const char *p_string, t_size p_stringLen=~0)
Definition: string_base.h:968
virtual bool get_mask(unsigned idx, pfc::string_base &out)=0
Entrypoint interface for registering media file types that can be opened through "open file" dialogs ...
const pfc::string8 m_extensions
input_file_type_v2_impl(const char *extensions, const char *name, const char *namePlural)