Re: [sigc] dynamic signals?



Hi!

Your scenario seems to be possible to implement. You are aware, of course, that you loose any kind of type safety! Wrong connect/emit function calls would not be detected at compile time and cause the program to segfault at run time.

Note that

sc.connect("second-signal", sigc::ptr_fun(foo));

cannot be implemented like this. Normally, the argument to signal.connect() is converted to a slot object implicitly according to the type the parameter to signal.connect(). This type depends on the template signature of the signal. Since in the code above the information from the signal's template signature is not available, the exact type of the slot has to specified manually like in:

sc.connect("second-signal", sigc::slot<void,int>(sigc::ptr_fun(foo)));

Problems can also arise in your emit() function if the parameter types don't match the signal's template signature exactly. E.g. if you exchange:

sc.emit("second-signal",2);

with

  sc.emit("second-signal",2.1);

your emit() template function will be instantiated for type "float" and you will cast the signal "second-signal" to signal<void,float> where the real type is signal<void,int>!

Regards,

  Martin

Am 01.04.2005 20:02:57 schrieb(en) Aaron Griffin:
Hello everyone,
I've been looking into libsigc++ briefly, and I like it alot.  I have
one implementation question for you all.  I would like to product the
following behavior:

/***************************************************/
void foo(int i)
{
   std::cout << "called with i="
             << i << std::endl;
}

signal_creator sc;
sc.create("first-signal",sigc::signal<void>());
sc.create("second-signal",sigc::signal<void,int>());

sc.connect("first-signal", sigc::bind(foo,1));
sc.connect("second-signal", sigc::ptr_fun(foo));

sc.emit("first-signal");
sc.emit("second-signal",2);
/***************************************************/

is this possible? my idea was to create a private
std::map<std::string,sigc::signal_base> and insert upon creation.  I
think I may have difficulty when creating both the connect and emit
signatures...

I would assume the "connect" method would be typed with a
"sigc::slot_base" - but I'm curious as to what would happen if a slot
expecting 3 parameters is attached to a signal emitting 1
parameter...

as for the emit signature, I was planning on just overloading it to
take 0 to 7 parameters, and up-cast the signal accordingly before
calling emit

would this work? is there a better way to do it?

Thanks for your time,
Aaron Griffin
_______________________________________________
libsigc-list mailing list
libsigc-list gnome org
http://mail.gnome.org/mailman/listinfo/libsigc-list





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]