foobar2000 SDK  2015-01-14
playable_location.h
Go to the documentation of this file.
1 #ifndef _FOOBAR2000_PLAYABLE_LOCATION_H_
2 #define _FOOBAR2000_PLAYABLE_LOCATION_H_
3 
4 //playable_location stores location of a playable resource, currently implemented as file path and integer for indicating multiple playable "subsongs" per file
5 //also see: file_info.h
6 //for getting more info about resource referenced by a playable_location, see metadb.h
7 
8 //char* strings are all UTF-8
9 
10 class NOVTABLE playable_location//interface (for passing around between DLLs)
11 {
12 public:
13  virtual const char * get_path() const =0;
14  virtual void set_path(const char*)=0;
15  virtual t_uint32 get_subsong() const =0;
16  virtual void set_subsong(t_uint32)=0;
17 
18  void copy(const playable_location & p_other) {
19  set_path(p_other.get_path());
20  set_subsong(p_other.get_subsong());
21  }
22 
23  static int g_compare(const playable_location & p_item1,const playable_location & p_item2);
24  static bool g_equals( const playable_location & p_item1, const playable_location & p_item2);
25 
26  const playable_location & operator=(const playable_location & src) {copy(src);return *this;}
27 
28  bool operator==(const playable_location & p_other) const;
29  bool operator!=(const playable_location & p_other) const;
30 
31  inline bool is_empty() {return get_path()[0]==0 && get_subsong()==0;}
32  inline void reset() {set_path("");set_subsong(0);}
33  inline t_uint32 get_subsong_index() const {return get_subsong();}
34  inline void set_subsong_index(t_uint32 v) {set_subsong(v);}
35 
36  bool is_empty() const { return * get_path() == 0; }
37  bool is_valid() const { return !is_empty(); }
38 
39 
40  class comparator {
41  public:
42  static int compare(const playable_location & v1, const playable_location & v2) {return g_compare(v1,v2);}
43  };
44 
45 protected:
48 };
49 
54 
55 class playable_location_impl : public playable_location//implementation
56 {
57 public:
58  const char * get_path() const {return m_path;}
59  void set_path(const char* p_path) {m_path=p_path;}
60  t_uint32 get_subsong() const {return m_subsong;}
61  void set_subsong(t_uint32 p_subsong) {m_subsong=p_subsong;}
62 
63  const playable_location_impl & operator=(const playable_location & src) {copy(src);return *this;}
64  const playable_location_impl & operator=(const playable_location_impl & src) {copy(src);return *this;}
65 
67  playable_location_impl(const char * p_path,t_uint32 p_subsong) : m_path(p_path), m_subsong(p_subsong) {}
70 
71 private:
74 };
75 
76 // usage: somefunction( make_playable_location("file://c:\blah.ogg",0) );
77 // only for use as a parameter to a function taking const playable_location &
79 {
80  const char * path;
82 
83  void set_path(const char*) {throw pfc::exception_not_implemented();}
84  void set_subsong(t_uint32) {throw pfc::exception_not_implemented();}
85 
86 public:
87  const char * get_path() const {return path;}
88  t_uint32 get_subsong() const {return num;}
89 
90  make_playable_location(const char * p_path,t_uint32 p_num) : path(p_path), num(p_num) {}
91 };
92 
94 
95 #endif //_FOOBAR2000_PLAYABLE_LOCATION_H_
playable_location & rplayable_location
virtual t_uint32 get_subsong() const =0
playable_location_impl(const playable_location_impl &src)
const playable_location_impl & operator=(const playable_location_impl &src)
const char * get_path() const
const char * get_path() const
const playable_location & operator=(const playable_location &src)
bool is_empty() const
void set_subsong_index(t_uint32 v)
t_uint32 get_subsong() const
virtual const char * get_path() const =0
const playable_location_impl & operator=(const playable_location &src)
playable_location_impl(const playable_location &src)
void set_path(const char *p_path)
void set_subsong(t_uint32)
playable_location const & rcplayable_location
pfc::string_base & operator<<(pfc::string_base &p_fmt, const playable_location &p_location)
void set_subsong(t_uint32 p_subsong)
string_simple_t< char > string_simple
Definition: string_base.h:824
t_uint32 get_subsong() const
bool operator==(const replaygain_info &item1, const replaygain_info &item2)
Definition: file_info.h:66
t_uint32 get_subsong_index() const
void copy(const playable_location &p_other)
bool is_valid() const
bool operator!=(const replaygain_info &item1, const replaygain_info &item2)
Definition: file_info.h:67
pfc::string_simple m_path
playable_location const * pcplayable_location
playable_location * pplayable_location
playable_location_impl(const char *p_path, t_uint32 p_subsong)
make_playable_location(const char *p_path, t_uint32 p_num)
uint32_t t_uint32
Definition: int_types.h:5
static int compare(const playable_location &v1, const playable_location &v2)
void set_path(const char *)