all repos — fluxbox @ 54230c9a4474baf4f1c56773992212093e222349

custom fork of the fluxbox windowmanager

Simplify FbTk::Signal template classes a bit

basically, i just got rid of Signal[0-3] classes and moved their contents to the appropriate
specialization of FbTk::Signal

also, this fixes the
no matching function for call to 'MemFunIgnoreArgs(FbTk::Signal<void, FbTk::SigImpl::EmptyArg,
FbTk::SigImpl::EmptyArg, FbTk::SigImpl::EmptyArg>&, void (FbTk::SigImpl::Signal0<void>::*)())'
error i had in the following commit.
Pavel Labath pavelo@centrum.sk
commit

54230c9a4474baf4f1c56773992212093e222349

parent

d5bd23e41a05cc66676d9c4bf480e59b8566b7ac

1 files changed, 30 insertions(+), 64 deletions(-)

jump to
M src/FbTk/Signal.hhsrc/FbTk/Signal.hh

@@ -101,52 +101,34 @@ SlotList m_slots; ///< all slots connected to a signal

Trackers m_trackers; ///< all instances that tracks this signal. }; -/// Signal with no argument -template <typename ReturnType> -class Signal0: public SignalHolder { -public: - typedef Slot0<ReturnType> SlotType; - - ~Signal0() { } +struct EmptyArg {}; - void emit() { - for ( Iterator it = begin(); it != end(); ++it ) { - static_cast<SlotType&>(*it)(); - } - } +} // namespace SigImpl - SlotID connect(const SlotType& slot) { - return SignalHolder::connect(slot); - } -}; -/// Signal with one argument -template <typename ReturnType, typename Arg1> -class Signal1: public SignalHolder { +/// Specialization for three arguments. +template <typename ReturnType, + typename Arg1 = SigImpl::EmptyArg, typename Arg2 = SigImpl::EmptyArg, typename Arg3 = SigImpl::EmptyArg > +class Signal: public SigImpl::SignalHolder { public: - typedef Slot1<ReturnType, Arg1> SlotType; - - ~Signal1() { } + typedef SigImpl::Slot3<ReturnType, Arg1, Arg2, Arg3> SlotType; - void emit(Arg1 arg) { + void emit(Arg1 arg1, Arg2 arg2, Arg3 arg3) { for ( Iterator it = begin(); it != end(); ++it ) { - static_cast<SlotType&>(*it)(arg); + static_cast<SlotType&>(*it)(arg1, arg2, arg3); } } SlotID connect(const SlotType& slot) { return SignalHolder::connect(slot); } - }; -/// Signal with two arguments +/// Specialization for two arguments. template <typename ReturnType, typename Arg1, typename Arg2> -class Signal2: public SignalHolder { +class Signal<ReturnType, Arg1, Arg2, SigImpl::EmptyArg>: public SigImpl::SignalHolder { public: - typedef Slot2<ReturnType, Arg1, Arg2> SlotType; - - ~Signal2() { } + typedef SigImpl::Slot2<ReturnType, Arg1, Arg2> SlotType; void emit(Arg1 arg1, Arg2 arg2) { for ( Iterator it = begin(); it != end(); ++it ) {

@@ -159,54 +141,38 @@ return SignalHolder::connect(slot);

} }; -/// Signal with three arguments -template <typename ReturnType, typename Arg1, typename Arg2, typename Arg3> -class Signal3: public SignalHolder { +/// Specialization for one argument. +template <typename ReturnType, typename Arg1> +class Signal<ReturnType, Arg1, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::SignalHolder { public: - typedef Slot3<ReturnType, Arg1, Arg2, Arg3> SlotType; - - ~Signal3() { } + typedef SigImpl::Slot1<ReturnType, Arg1> SlotType; - void emit(Arg1 arg1, Arg2 arg2, Arg3 arg3) { + void emit(Arg1 arg) { for ( Iterator it = begin(); it != end(); ++it ) { - static_cast<SlotType&>(*it)(arg1, arg2, arg3); + static_cast<SlotType&>(*it)(arg); } } SlotID connect(const SlotType& slot) { return SignalHolder::connect(slot); } - }; -struct EmptyArg {}; - -} // namespace SigImpl - - -/// Specialization for three arguments. -template <typename ReturnType, - typename Arg1 = SigImpl::EmptyArg, typename Arg2 = SigImpl::EmptyArg, typename Arg3 = SigImpl::EmptyArg > -class Signal: public SigImpl::Signal3< ReturnType, Arg1, Arg2, Arg3 > { +/// Specialization for no arguments. +template <typename ReturnType> +class Signal<ReturnType, SigImpl::EmptyArg, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::SignalHolder { public: -}; + typedef SigImpl::Slot0<ReturnType> SlotType; -/// Specialization for two arguments. -template <typename ReturnType, typename Arg1, typename Arg2> -class Signal<ReturnType, Arg1, Arg2, SigImpl::EmptyArg>: public SigImpl::Signal2< ReturnType, Arg1, Arg2 > { -public: -}; + void emit() { + for ( Iterator it = begin(); it != end(); ++it ) { + static_cast<SlotType&>(*it)(); + } + } -/// Specialization for one argument. -template <typename ReturnType, typename Arg1> -class Signal<ReturnType, Arg1, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::Signal1< ReturnType, Arg1 > { -public: -}; - -/// Specialization for no argument. -template <typename ReturnType> -class Signal<ReturnType, SigImpl::EmptyArg, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::Signal0< ReturnType > { -public: + SlotID connect(const SlotType& slot) { + return SignalHolder::connect(slot); + } }; /**