foobar2000 SDK  2015-08-03
service_impl.h
Go to the documentation of this file.
1 template<typename T>
4 class service_impl_t : public T
5 {
6 public:
7  int service_release() throw() {
8  int ret = (int) --m_counter;
9  if (ret == 0) {
10  PFC_ASSERT_NO_EXCEPTION( delete this );
11  }
12  return ret;
13  }
14  int service_add_ref() throw() {return (int) ++m_counter;}
15 
16  TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD(service_impl_t,T)
17 private:
18  pfc::refcounter m_counter;
19 };
20 
23 template<typename class_t>
25 public:
26  int service_release() throw() {
27  int ret = --m_counter;
28  if (ret == 0) {
29  this->service_shutdown();
30  } else {
31  return ret;
32  }
33  }
34  int service_add_ref() throw() {return ++m_counter;}
35 
36  TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD(service_impl_explicitshutdown_t,class_t)
37 private:
38  pfc::refcounter m_counter;
39 };
40 
43 template<typename T>
44 class service_impl_single_t : public T
45 {
46 public:
47  int service_release() throw() {return 1;}
48  int service_add_ref() throw() {return 1;}
49 
50  TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD(service_impl_single_t,T)
51 };
52 
53 
54 namespace service_impl_helper {
56 };
57 
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
Definition: service_impl.h:4
int service_add_ref()
Definition: service_impl.h:14
Template implementing dummy version of reference-counting features of service_base. Intended for static/local/member instantiation: "static service_impl_single_t<someclass> 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
Alternate version of service_impl_t<> - calls this->service_shutdown() instead of delete this...
Definition: service_impl.h:24
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
int service_release()
Definition: service_impl.h:7
void release_object_delayed(service_ptr obj)
Definition: service.cpp:42