Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

Class template slotN

boost::signals2::slotN — Pass slots as function arguments, and associate tracked objects with a slot.

Synopsis

// In header: <boost/signals2/slot.hpp>

template<typename R, typename T1, typename T2, ..., typename TN, 
         typename SlotFunction = functionN<R, T1, T2, ..., TN> > 
class slotN : public slot_base {
public:
  // types
  typedef R            result_type;         
  typedef T1           argument_type;         // If N == 1
  typedef T1           first_argument_type;   // If N == 2
  typedef T2           second_argument_type;  // If N == 2
  typedef T1           arg1_type;           
  typedef T2           arg2_type;           
     .
     .
     .
  typedef TN           argN_type;           
  typedef SlotFunction slot_function_type;  

  // static constants
  static const int arity = N;

  // construct/copy/destruct
  template<typename Slot> slotN(const Slot &);
  template<typename OtherR, typename OtherT1, typename OtherT2, ..., 
           typename OtherTN, typename OtherSlotFunction> 
    slotN(const slotN<OtherR, OtherT1, OtherT2, ..., OtherTN, OtherSlotFunction> &);
  template<typename OtherSignature, typename OtherSlotFunction> 
    slotN(const slot<OtherSignature, OtherSlotFunction> &);
  template<typename Func, typename Arg1, typename Arg2, ..., typename ArgN> 
    slotN(const Func &, const Arg1 &, const Arg2 &, ..., const ArgN &);

  // invocation
  result_type operator()(arg1_type, arg2_type, ..., argN_type);
  result_type operator()(arg1_type, arg2_type, ..., argN_type) const;

  // tracking
  slotN & track(const weak_ptr<void> &);
  slotN & track(const signal_base &);
  slotN & track(const slot_base &);

  // slot function access
  slot_function_type & slot_function();
  const slot_function_type & slot_function() const;
};

Description

The class template slotN covers several related classes slot0, slot1, slot2, etc., where the number suffix describes the number of function parameters the slot will take. Instead of enumerating all classes, a single pattern slotN will be described, where N represents the number of function parameters.

slotN public construct/copy/destruct

  1. template<typename Slot> slotN(const Slot & target);

    Effects:

    Initializes the SlotFunction object in this with target, which may be any function object with which a SlotFunction can be constructed.

    In this special case where the template type parameter Slot is a compatible signal or signalN type, the signal will automatically be added to the slot's tracked object list. Otherwise, the slot's tracked object list is initially empty.

  2. template<typename OtherR, typename OtherT1, typename OtherT2, ..., 
             typename OtherTN, typename OtherSlotFunction> 
      slotN(const slotN<OtherR, OtherT1, OtherT2, ..., OtherTN, OtherSlotFunction> & other_slot);

    Effects:

    Initializes this with a copy of other_slot's SlotFunction object and tracked object list.

  3. template<typename OtherSignature, typename OtherSlotFunction> 
      slotN(const slot<OtherSignature, OtherSlotFunction> & other_slot);

    Effects:

    Initializes this with a copy of other_slot's OtherSlotFunction object and tracked object list.

  4. template<typename Func, typename Arg1, typename Arg2, ..., typename ArgN> 
      slotN(const Func & f, const Arg1 & a1, const Arg2 & a2, ..., 
            const ArgN & aN);

    Effects:

    Syntactic sugar for bind() when the constructor is passed more than one argument. As if: slotN(boost::bind(f, a1, a2, ..., aN))

slotN invocation

  1. result_type operator()(arg1_type a1, arg2_type a2, ..., argN_type aN);
    result_type operator()(arg1_type a1, arg2_type a2, ..., argN_type aN) const;

    Effects:

    Calls the slot's SlotFunction object.

    Returns:

    The result returned by the slot's SlotFunction object.

    Throws:

    Any exceptions thrown by the slot's SlotFunction object. boost::signals2::expired_slot if any object in the tracked object list has expired.

    Notes:

    If you have already used lock to insure the tracked objects are valid, it is slightly more efficient to use the slot_function() method and call the slot's SlotFunction directly.

slotN tracking

  1. slotN & track(const weak_ptr<void> & tracked_object);
    slotN & track(const signal_base & tracked_signal);
    slotN & track(const slot_base & tracked_slot);

    Effects:

    Adds object(s) to the slot's tracked object list. Should any of the tracked objects expire, then subsequent attempts to call the slot's operator() or lock() methods will throw an expired_slot exception.

    When tracking a signal, a shared_ptr internal to the signal class is used for tracking. The signal does not need to be owned by an external shared_ptr.

    In the case of passing another slot as the argument to track(), only the objects currently in the other slot's tracked object list are added to the tracked object list of this. The other slot object itself is not tracked.

    Returns:

    *this

slotN slot function access

  1. slot_function_type & slot_function();
    const slot_function_type & slot_function() const;

    Returns:

    A reference to the slot's underlying SlotFunction object.


PrevUpHomeNext