Easy3D 2.5.3
Signal< Args > Class Template Reference

A light-weight implementation of the simple signal-slot mechanism. More...

#include <easy3d/core/signal.h>

Public Member Functions

 Signal (Signal const &)
 Copy constructor and assignment create a new signal.
 
 Signal (Signal &&other) noexcept
 Move constructor.
 
Signaloperator= (Signal &&other) noexcept
 The assignment operator.
 
Signaloperator= (Signal const &other)
 The assignment operator.
 
int connect (std::function< void(Args...)> const &slot)
 Connects a function to this signal. More...
 
template<typename Class >
int connect (Class *inst, void(Class::*func)(Args...))
 Connects a member function of an object to this signal. More...
 
template<typename Class >
int connect (Class *inst, void(Class::*func)(Args...) const)
 Connects a const member function of an object to this signal. More...
 
int connect (Signal< Args... > *receiver)
 Connects this signal to another signal receiver. More...
 
void disconnect (int id)
 Disconnects a previously connected function.
 
void disconnect_all ()
 Disconnects all previously connected functions.
 
void send (Args... p)
 Calls all connected functions.
 
void send_for_all_but_one (int excludedConnectionID, Args... p)
 Calls all connected functions except for one.
 
void emit_for (int connectionID, Args... p)
 Calls only one connected function.
 

Detailed Description

template<typename... Args>
class easy3d::Signal< Args >

A light-weight implementation of the simple signal-slot mechanism.

Signal supports any types of functions (functions, lambda functions, and member functions) with any number of arguments. Connected functions will be called when the send() method of the signal object is invoked. Any argument passed to send() will be passed to the given functions. Multiple slots can be connected to the same signal object. A signal (i.e., the sender) can be connected to another signal (e.g., the receiver). A typical usage of Signal in Easy3D is camera manipulation. When the camera has been manipulated, the viewer should be notified (e.g., a repaint event should be triggered). This is done by calling to the viewer's update() function. So in Easy3D, the viewer's update function is connected to the camera's corresponding signal.

See also
A more powerful implementation sigslot based on C++14.
Examples
Test_Signal.

Member Function Documentation

◆ connect() [1/4]

int connect ( Class *  inst,
void(Class::*)(Args...) const  func 
)
inline

Connects a const member function of an object to this signal.

The returned value can be used to disconnect the function from this signal, e.g.,

signal.connect(viewer, &Viewer::update);
void update() const
Update the display (i.e., repaint).
Definition: viewer.cpp:631
Note
When a member function has overloads, explicitly cast the function to the right function type, e.g.,
static_cast<void (Viewer::*)(const std::string&, int)>(&Viewer::print)
Or use the helper function overload for a lighter syntax.

◆ connect() [2/4]

int connect ( Class *  inst,
void(Class::*)(Args...)  func 
)
inline

Connects a member function of an object to this signal.

The returned value can be used to disconnect the function from this signal, e.g.,

signal.connect(viewer, &Viewer::update);
Note
When a member function has overloads, explicitly cast the function to the right function type, e.g.,
static_cast<void (Viewer::*)(const std::string&, int)>(&Viewer::print)
Or use the helper function overload for a lighter syntax.

◆ connect() [3/4]

int connect ( Signal< Args... > *  receiver)
inline

Connects this signal to another signal receiver.

Upon return, the emission of this signal will trigger receiver to emit. The returned value can be used to disconnect the connected signal.

◆ connect() [4/4]

int connect ( std::function< void(Args...)> const &  slot)
inline

Connects a function to this signal.

The returned value can be used to disconnect the function from this signal.

Note
When a function has overloads, explicitly cast the function to the right function type, e.g.,
static_cast<void (*)(const std::string&, int)>(&print)
Or use the helper function overload for a lighter syntax.
Examples
Test_Signal, and Tutorial_405_ObjectManipulation.

The documentation for this class was generated from the following file: