Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
Listener & Emitter Class Example

Emitter Class

Create an emitting class having a listener_type from template sf::TListener.
Instantiate the type

class MyEmitter
{
public:
typedef sf::TListener<std::string&> listener_type;
listener_type::emitter_type emitter;
std::string callThem()
{
std::string s(1, '$');
emitter.callListeners(s);
return s;
}
};
Template class used to bind listeners to a handler_type instance.
Definition TListener.h:79

Listener Class

Derive the class from sf::ListenerList to link/register any type of listener.

class MyListener :sf::ListenerList
{
public:
explicit MyListener(std::string ofs)
:offset(std::move(ofs)) {}
auto unlinkIt()
{
return delete_null(link_ptr);
}
void linkIt(MyEmitter* emitter)
{
MyEmitter::listener_type::func_type lambda = [&](std::string& s)
{
s += offset;
};
link_ptr = emitter->emitter.linkListener(this, lambda);
}
private:
MyEmitter::listener_type* link_ptr{nullptr};
std::string offset;
};
Base class used as container for classes having listeners created by sf::TListener template.
Definition TListener.h:13
void delete_null(T &p)
Deletes object and clears pointer.
Definition pointer.h:14