1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/*
* functorimpl.h:
*
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
* $Id: functorimpl.h,v 1.1 2006/08/24 23:25:07 phintuka Exp $
*
*/
#ifndef __XINELIB_FUNCTORIMPL_H
#ifndef __XINELIB_FUNCTOR_H
# error functorimpl.h should not be included, use functor.h instead
#endif
#if 1 /* gcc 3.3.x (?) does not accept class TRESULT=void */
template <class TCLASS>
class cFunctor0 : public cFunctor {
public:
protected:
typedef void (TCLASS::*TFUNC)(void);
cFunctor0(TCLASS *obj, TFUNC f) : m_obj(obj), m_f(f) {}
virtual ~cFunctor0() {};
virtual void Execute(void)
{
(*m_obj.*m_f)();
}
private:
TCLASS *m_obj;
TFUNC m_f;
friend cFunctor *CreateFunctor<TCLASS>(TCLASS*,TFUNC);
};
template <class TCLASS, class TARG1>
class cFunctor1 : public cFunctor {
public:
protected:
typedef void (TCLASS::*TFUNC)(TARG1);
cFunctor1(TCLASS *obj, TFUNC f, TARG1 arg1) :
m_obj(obj), m_f(f), m_arg1(arg1) {}
virtual ~cFunctor1() {};
virtual void Execute(void)
{
(*m_obj.*m_f)(m_arg1);
}
private:
TCLASS *m_obj;
TFUNC m_f;
TARG1 m_arg1;
friend cFunctor *CreateFunctor<TCLASS,TARG1>(TCLASS*,TFUNC,TARG1);
};
#endif
template <class TCLASS, class TRESULT>
class cFunctorR0 : public cFunctor {
public:
protected:
typedef TRESULT (TCLASS::*TFUNC)(void);
cFunctorR0(TCLASS *obj, TFUNC f) : m_obj(obj), m_f(f) {}
virtual ~cFunctorR0() {};
virtual void Execute(void)
{
// TODO: use future to pass back value
(void) (*m_obj.*m_f)();
}
private:
TCLASS *m_obj;
TFUNC m_f;
friend cFunctor *CreateFunctor<TCLASS,TRESULT>(TCLASS*,TFUNC);
};
template <class TCLASS, class TRESULT, class TARG1>
class cFunctorR1 : public cFunctor {
public:
protected:
typedef TRESULT (TCLASS::*TFUNC)(TARG1);
cFunctorR1(TCLASS *obj, TFUNC f, TARG1 arg1) :
m_obj(obj), m_f(f), m_arg1(arg1) {}
virtual ~cFunctorR1() {};
virtual void Execute(void)
{
// TODO: use future to pass back value
(void) (*m_obj.*m_f)(m_arg1);
}
private:
TCLASS *m_obj;
TFUNC m_f;
TARG1 m_arg1;
friend cFunctor *CreateFunctor<TCLASS,TRESULT>(TCLASS*,TFUNC,TARG1);
};
#if 1 /* gcc 3.3.x (?) does not accept class TRESULT=void */
template<class TCLASS>
cFunctor *CreateFunctor(TCLASS *c,
void (TCLASS::*fp)(void))
{
return new cFunctor0<TCLASS>(c, fp);
}
template<class TCLASS, class TARG1>
cFunctor *CreateFunctor(TCLASS *c,
void (TCLASS::*fp)(TARG1),
TARG1 arg1)
{
return new cFunctor1<TCLASS,TARG1>(c, fp, arg1);
}
#endif
template<class TCLASS, class TRESULT>
cFunctor *CreateFunctor(TCLASS *c,
TRESULT (TCLASS::*fp)(void))
{
return new cFunctorR0<TCLASS,TRESULT>(c, fp);
}
template<class TCLASS, class TRESULT, class TARG1>
cFunctor *CreateFunctor(TCLASS *c,
TRESULT (TCLASS::*fp)(TARG1),
TARG1 arg1)
{
return new cFunctorR1<TCLASS,TRESULT,TARG1>(c, fp, arg1);
}
#endif
|