Merge pull request #25808 from CastagnaIT/fix_url_parse
[xbmc.git] / xbmc / interfaces / legacy / CallbackFunction.h
blob90360d57f96dd5ba18edb7fa590860ddcbaef8ba
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "AddonClass.h"
13 namespace XBMCAddon
15 /**
16 * <p>This is the parent class for the class templates that hold
17 * a callback. A callback is essentially a templatized
18 * functor (functoid?) for a call to a member function.</p>
20 * <p>This class combined with the attending CallbackHandlers should make
21 * sure that the AddonClass isn't in the midst of deallocating when
22 * the callback executes. In this way the Callback class acts as
23 * a weak reference.</p>
25 class Callback : public AddonClass
27 protected:
28 AddonClass* addonClassObject;
29 explicit Callback(AddonClass* _object) : addonClassObject(_object) { XBMC_TRACE; }
31 public:
32 virtual void executeCallback() = 0;
33 ~Callback() override;
35 AddonClass* getObject() { XBMC_TRACE; return addonClassObject; }
38 struct cb_null_type {};
40 // stub type template to be partial specialized
41 template<typename M = cb_null_type, typename T1 = cb_null_type,
42 typename T2 = cb_null_type, typename T3 = cb_null_type,
43 typename T4 = cb_null_type, typename Extraneous = cb_null_type>
44 class CallbackFunction {};
46 /**
47 * This is the template to carry a callback to a member function
48 * that returns 'void' (has no return) and takes no parameters.
50 template<class M> class CallbackFunction<M, cb_null_type, cb_null_type, cb_null_type, cb_null_type, cb_null_type> : public Callback
52 public:
53 typedef void (M::*MemberFunction)();
55 protected:
56 MemberFunction meth;
57 M* obj;
59 public:
60 CallbackFunction(M* object, MemberFunction method) :
61 Callback(object), meth(method), obj(object) { XBMC_TRACE; }
63 ~CallbackFunction() override { XBMC_TRACE; deallocating(); }
65 void executeCallback() override { XBMC_TRACE; ((*obj).*(meth))(); }
68 /**
69 * This is the template to carry a callback to a member function
70 * that returns 'void' (has no return) and takes one parameter.
72 template<class M, typename P1> class CallbackFunction<M,P1, cb_null_type, cb_null_type, cb_null_type, cb_null_type> : public Callback
74 public:
75 typedef void (M::*MemberFunction)(P1);
77 protected:
78 MemberFunction meth;
79 M* obj;
80 P1 param;
82 public:
83 CallbackFunction(M* object, MemberFunction method, P1 parameter) :
84 Callback(object), meth(method), obj(object),
85 param(parameter) { XBMC_TRACE; }
87 ~CallbackFunction() override { XBMC_TRACE; deallocating(); }
89 void executeCallback() override { XBMC_TRACE; ((*obj).*(meth))(param); }
92 /**
93 * This is the template to carry a callback to a member function
94 * that returns 'void' (has no return) and takes one parameter
95 * that can be held in an AddonClass::Ref
97 template<class M, typename P1> class CallbackFunction<M,AddonClass::Ref<P1>, cb_null_type, cb_null_type, cb_null_type, cb_null_type> : public Callback
99 public:
100 typedef void (M::*MemberFunction)(P1*);
102 protected:
103 MemberFunction meth;
104 M* obj;
105 AddonClass::Ref<P1> param;
107 public:
108 CallbackFunction(M* object, MemberFunction method, P1* parameter) :
109 Callback(object), meth(method), obj(object),
110 param(parameter) { XBMC_TRACE; }
112 ~CallbackFunction() override { XBMC_TRACE; deallocating(); }
114 void executeCallback() override { XBMC_TRACE; ((*obj).*(meth))(param); }
119 * This is the template to carry a callback to a member function
120 * that returns 'void' (has no return) and takes two parameters.
122 template<class M, typename P1, typename P2> class CallbackFunction<M,P1,P2, cb_null_type, cb_null_type, cb_null_type> : public Callback
124 public:
125 typedef void (M::*MemberFunction)(P1,P2);
127 protected:
128 MemberFunction meth;
129 M* obj;
130 P1 param1;
131 P2 param2;
133 public:
134 CallbackFunction(M* object, MemberFunction method, P1 parameter, P2 parameter2) :
135 Callback(object), meth(method), obj(object),
136 param1(parameter), param2(parameter2) { XBMC_TRACE; }
138 ~CallbackFunction() override { XBMC_TRACE; deallocating(); }
140 void executeCallback() override { XBMC_TRACE; ((*obj).*(meth))(param1,param2); }
145 * This is the template to carry a callback to a member function
146 * that returns 'void' (has no return) and takes three parameters.
148 template<class M, typename P1, typename P2, typename P3> class CallbackFunction<M,P1,P2,P3, cb_null_type, cb_null_type> : public Callback
150 public:
151 typedef void (M::*MemberFunction)(P1,P2,P3);
153 protected:
154 MemberFunction meth;
155 M* obj;
156 P1 param1;
157 P2 param2;
158 P3 param3;
160 public:
161 CallbackFunction(M* object, MemberFunction method, P1 parameter, P2 parameter2, P3 parameter3) :
162 Callback(object), meth(method), obj(object),
163 param1(parameter), param2(parameter2), param3(parameter3) { XBMC_TRACE; }
165 ~CallbackFunction() override { XBMC_TRACE; deallocating(); }
167 void executeCallback() override { XBMC_TRACE; ((*obj).*(meth))(param1,param2,param3); }