Here is some signal/slot stuff that I've recently put together:
template
{
public:
virtual R call(const A1& arg1 = A1(), const A2& arg2 = A2(), const A3& arg3 = A3(), const A4& arg4 = A4())
{ return (R)(arg1, arg2, arg3, arg4); }
};
template
{
public:
virtual R call() { return R(); }
};
template
{
public:
virtual R call(const A1& arg1 = A1()) { return R(); }
};
template
{
public:
virtual R call(const A1& arg1 = A1(), const A2& arg2 = A2()) { return R(); }
};
template
{
public:
virtual R call(const A1& arg1 = A1(), const A2& arg2 = A2(), const A3& arg3 = A3()) { return R(); }
};
template
class stub : public base
{
public:
stub(T& obj, R (T::*ptr)(A1, A2, A3, A4)) : _obj(obj), _ptr(ptr) { }
R call(const A1& arg1 = A1(), const A2& arg2 = A2(), const A3& arg3 = A3(), const A4& arg4 = A4())
{
return (_obj.*_ptr)(arg1, arg2, arg3, arg4);
}
private:
T& _obj;
R (T::*_ptr)(A1, A2, A3, A4);
};
template
{
public:
stub(T& obj, R (T::*ptr)()) : _obj(obj), _ptr(ptr) { }
R call()
{
return (_obj.*_ptr)();
}
private:
T& _obj;
R (T::*_ptr)();
};
template
{
public:
stub(T& obj, R (T::*ptr)(A1)) : _obj(obj), _ptr(ptr) { }
R call(const A1& arg1 = A1())
{
return (_obj.*_ptr)(arg1);
}
private:
T& _obj;
R (T::*_ptr)(A1);
};
template
{
public:
stub(T& obj, R (T::*ptr)(A1, A2)) : _obj(obj), _ptr(ptr) { }
R call(const A1& arg1 = A1(), const A2& arg2 = A2())
{
return (_obj.*_ptr)(arg1, arg2);
}
private:
T& _obj;
R (T::*_ptr)(A1, A2);
};
template
{
public:
stub(T& obj, R (T::*ptr)(A1, A2, A3)) : _obj(obj), _ptr(ptr) { }
R call(const A1& arg1 = A1(), const A2& arg2 = A2(), const A3& arg3 = A3())
{
return (_obj.*_ptr)(arg1, arg2, arg3);
}
private:
T& _obj;
R (T::*_ptr)(A1, A2, A3);
};
template
{
public:
signal_t() : _ptr(0), _stub(0) { }
template
{
_stub = new stub
}
template
{
_stub = new stub
}
void connect(R (*function)(A1, A2, A3, A4)) { _ptr = function; }
R operator()(const A1& arg1 = A1(), const A2& arg2 = A2(), const A3& arg3 = A3(), const A4& arg4 = A4())
{
if(_ptr)
return _ptr(arg1, arg2, arg3, arg4);
else if(_stub)
return _stub->call(arg1, arg2, arg3, arg4);
else
return R();
}
private:
R (*_ptr)(A1, A2, A3, A4);
base
};
template
{
public:
signal_t() : _ptr(0), _stub(0) { }
template
{
_stub = new stub
}
template
{
_stub = new stub
}
void connect(R (*function)()) { _ptr = function; }
R operator()()
{
if(_ptr)
return _ptr();
else if(_stub)
return _stub->call();
else
return R();
}
private:
R (*_ptr)();
base
};
template
{
public:
signal_t() : _ptr(0), _stub(0) { }
template
{
_stub = new stub
}
template
{
_stub = new stub
}
void connect(R (*function)(A1)) { _ptr = function; }
R operator()(const A1& arg1 = A1())
{
if(_ptr)
return _ptr(arg1);
else if(_stub)
return _stub->call(arg1);
else
return R();
}
private:
R (*_ptr)(A1);
base
};
template
{
public:
signal_t() : _ptr(0), _stub(0) { }
template
{
_stub = new stub
}
template
{
_stub = new stub
}
void connect(R (*function)(A1, A2)) { _ptr = function; }
R operator()(const A1& arg1 = A1(), const A2& arg2 = A2())
{
if(_ptr)
return _ptr(arg1, arg2);
else if(_stub)
return _stub->call(arg1, arg2);
else
return R();
}
private:
R (*_ptr)(A1, A2);
base
};
template
{
public:
signal_t() : _ptr(0), _stub(0) { }
template
{
_stub = new stub
}
template
{
_stub = new stub
}
void connect(R (*function)(A1, A2, A3)) { _ptr = function; }
R operator()(const A1& arg1 = A1(), const A2& arg2 = A2(), const A3& arg3 = A3())
{
if(_ptr)
return _ptr(arg1, arg2, arg3);
else if(_stub)
return _stub->call(arg1, arg2, arg3);
else
return R();
}
private:
R (*_ptr)(A1, A2, A3);
base
};
Not sure exactly why it works but it seems to.

0 Comments:
Post a Comment
<< Home