foobar2000 SDK  2015-08-03
instance_tracker.h
Go to the documentation of this file.
1 namespace pfc {
2  template<typename t_object>
4  public:
5  void add(t_object * p_object) {
6  m_list.add_item(p_object);
7  }
8  void remove(t_object * p_object) {
9  m_list.remove_item(p_object);
10  }
11 
12  t_size get_count() const {return m_list.get_count();}
13  t_object * get_item(t_size p_index) {return m_list[p_index];}
14  t_object * operator[](t_size p_index) {return m_list[p_index];}
15 
16  private:
18  };
19 
20 
21  template<typename t_object,instance_tracker_server_t<t_object> & p_server>
23  public:
24  instance_tracker_client_t(t_object* p_ptr) : m_ptr(NULL), m_added(false) {initialize(p_ptr);}
25  instance_tracker_client_t() : m_ptr(NULL), m_added(false) {}
26 
27  void initialize(t_object * p_ptr) {
28  uninitialize();
29  p_server.add(p_ptr);
30  m_ptr = p_ptr;
31  m_added = true;
32  }
33 
34  void uninitialize() {
35  if (m_added) {
36  p_server.remove(m_ptr);
37  m_ptr = NULL;
38  m_added = false;
39  }
40  }
41 
43  uninitialize();
44  }
45  private:
46  bool m_added;
47  t_object * m_ptr;
48  };
49 }
ptr_list_hybrid_t< t_object, 4 > m_list
t_size get_count() const
Definition: list.h:365
void initialize(t_object *p_ptr)
t_object * operator[](t_size p_index)
t_object * get_item(t_size p_index)
void add(t_object *p_object)
size_t t_size
Definition: int_types.h:48
t_size add_item(const T &item)
Definition: list.h:522
void remove_item(const T &item)
Definition: list.h:532
instance_tracker_client_t(t_object *p_ptr)