Boost logo

Boost Users :

From: Juho Mäkinen (juho.makinen_at_[hidden])
Date: 2005-06-07 01:56:04


Hello.

I'm having problems with boost::signal. I have a simple callback
system:

typedef boost::signal<void (const String &)> StringCallbacks;
TSharedPtr<StringCallbacks> stringCallbacks;

stringCallbacks contains void (Const String &) -callback functions.
New callback functions are registered into the callback system with
registerCallback -function:

template<class VarType> class SettingUpdater {
  private:
    VarType & reference;

    SettingUpdater(VarType & var) : reference(var) { }
 
  public:
    void operator()(const String & setting)
    {
       // do someting irrelevant for the question here
       // with the reference -variable
    }
};

boost::signals::connection registerCallback(StringCallbacks::slot_type callback)
{
  // PROBLEM: I'd like to call the callback once without calling every callback
  // which are possibly registered already into the signal before this.

  // Register the new callback into the signal.
  return stringCallbacks.get()->connect(callback);
}

The actual usage of registerCallback:
int localVariable;
registerCallback(SettingUpdater<int>(localVariable));

Question:
As you might already see above, I'd like to call the callback function
once in the registerCallback function without calling every callback
already registered in the stringCallbacks signal.
I first tried something like
String param = "foo";
callback(param);
but that won't compile.

I also tried callback.get_slot_function()(param);
That compiles, but it won't execute the operator() -function in SettingUpdater.

Calling the signal will execute all callbacks registered, so the SettingUpdater
function seems working. How I can execute the operator() function
in SettingUpdater<> inside registerCallback function by the
callback parameter passed to registerCallback function?

Thanks in advance =)

 - Juho Mäkinen


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net