samedi 22 octobre 2016

Copying signal connections when copying a connected object

I'm implementing a C++11(14?) observer pattern syntax-sugared with signals.

I have the basic connect/disconnect stuff working. I'm currently tackling copy/move semantics of the connected object (i.e. not the signal, but an object of which a member function is connected to it). For this, I have a trackable class which enables lifetime management so that signals get notified of connected object destruction (and this works).

I'm running into difficulties when I want to enable copy semantics on trackable, which is one of the chief omissions in the Qt API I am trying to replicate/improve. I currently store the connections as std::function, with a signature matching void(ArgTypes...) for a given signal<ArgTypes...>. Member functions are bound to an object at connect time, so I lose the information of which member functions I have connected (because these cannot be stored in any way in a homogeneous container (so really, these can't be stored at all).

I'd like a copy of a trackable to be connected in the same way as the original. How can I achieve this?

Aucun commentaire:

Enregistrer un commentaire