the_drow
the_drow

Reputation: 19181

How to prevent removal of slots from a certain signal?

Is it possible to block the removal of certain slots from a signal in the boost.signals library?
If so how should a code that does such a thing will look like? Do I need to create a derived class just for that specific signal to do so?

Upvotes: 1

Views: 76

Answers (1)

Edward Strange
Edward Strange

Reputation: 40859

Supply your own slot connection function that fails to return the connection. Without the connection the client can't break it.

Edit: code example:

struct my_class
{
  boost::signals::connection listen_event1(boost::function<void (my_class const&)> const& f)
  {
    return signal1.connect(f);
  }
  void listen_event2(boost::function<void my_class const&)> const& f)
  {
    signal2.connect(f);
  }

private:
  typedef boost::signals::signal<void(my_class const&)> sig_t;
  sig_t signal1;
  sig_t signal2;
};

signal2 connections cannot be disconnected.

Upvotes: 1

Related Questions