Reputation: 3174
I found this C++ code that uses boost signals and I'm trying to understand it.
// A boost::signal wrapper structure
template <typename Signature>
struct SignalBase : public boost::noncopyable
{
typedef boost::function_traits< Signature > SignatureTraits;
typedef boost::signal<Signature> SignalType;
typedef typename SignalType::slot_function_type SlotFunctionType;
typedef typename SignalType::result_type ResultType;
typedef boost::signals::connection ConnectionType;
SignalBase() : m_signal() {};
virtual ~SignalBase() {};
protected:
SignalType m_signal;
};
// I use a specialization of this template for an arity of 1.
// The template generates the correct function call operator for the arity of the signal.
template<int Arity, typename Signature>
struct SelArity : public SignalBase<Signature> {};
// Specialization
template<typename Signature>
struct SelArity< 1, Signature> : public SignalBase<Signature>
{
typedef SignalBase<Signature> BaseType;
inline typename BaseType::ResultType operator()(typename BaseType::SignatureTraits::arg1_type arg )
{
return BaseType::m_signal( arg );
}
};
I can't figure out what SelArity
functors will return. As far as I understand m_signal
is a type which can declare signals that will be able to connect to functions with Signature
signature. How is it possible to have types as parameters?( see return BaseType::m_signal( arg );
) What is the type represented by ResultType
? And how will I be able to use the object returned by SelArity
functor?
Upvotes: 1
Views: 482
Reputation: 15075
No, m_signal
is not a type, it's an instance of class SignalType
, which is boost::signal<Signature>
.
SelArity
functor actually invokes m_signal
with 1 argument and returns its return value.
(What all these wrappers are needed for I don't know.)
Upvotes: 1