Skip to content

feragon/nano-signal-slot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nano-signal-slot

Pure C++11 Signals and Slots

Include

// #include "nano_function.hpp" // Nano::Function, Nano::DelegateKey
// #include "nano_observer.hpp" // Nano::Observer
#include "nano_signal_slot.hpp" // Nano::Signal / All the above

Declare

// Declare Nano::Signals using function signature syntax
Nano::Signal<bool(const char*)> signal_one;
Nano::Signal<bool(const char*, std::size_t)> signal_two;

Connect

// Connect member functions to Nano::signals;
signal_one.connect<Foo, &Foo::handler_a>(&foo);
signal_two.connect<Foo, &Foo::handler_b>(&foo);

// Connect a static member function
signal_one.connect<Foo::handler_c>();

// Connect a free function
signal_two.connect<handler_d>();

Emit / Emit Accumulate

// Emit Signals
signal_one.emit("we get signal");
signal_two.emit("main screen turn on", __LINE__);

std::vector<bool> status;

// Emit Signals and accumulate SRVs (signal return values)
signal_one.emit_accumulate([&](bool srv)
{
    status.push_back(srv);
}
,"how are you gentlemen");

Disconnect

Additionally test convenience overloads for references.

// Disconnect member functions from Nano::Signals
signal_one.disconnect<Foo, &Foo::handler_a>(foo);
signal_two.disconnect<Foo, &Foo::handler_b>(foo);

// Disconnect a static member function
signal_one.disconnect<Foo::handler_c>();

// Disconnect a free function
signal_two.disconnect<handler_d>();

Connection Management

To utilize automatic connection management you must inherit from Nano::Observer.

struct Foo : public Nano::Observer
{
    bool handler_a(const char* sl) const
    {
        std::cout << sl << std::endl;
        return true;
    }
	...

Function Objects

Must guarantee that object lifetimes are compatible.

// Test using function objects
auto fo = [&](const char* sl)
{
    std::cout << sl << std::endl;
    return true;
};

...

// Connecting function objects (or any object defining a suitable operator())
signal_one.connect(&fo);

...

// Disconnecting function objects (convenience overload is used here)
signal_one.disconnect(fo);

Links

Performance Metrics Benchmark Algorithms

About

Pure C++11 Signals and Slots

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 100.0%