Giter Site home page Giter Site logo

lsignal's Introduction

lsignal: C++ signal/slot system.

lsignal (or lightweight signal) is a very little and fast C++ thread-safe implementation of signal and slot system which is based on modern C++11 code.

Requirements

C++ compiler with support C++11.

How to use

Include lsignal.h in your project.

Essential classes

signal

This is a template class which holds callbacks and can emit signals with certain arguments. See examples of declarations:

Declaration Description
lsignal::signal<void()> s; Signal without parameters, return type - void
lsignal::signal<int(int,int)> t; Signal with two parameters, return type - int
lsignal::signal<std::string()> u; Signal without parameters, return type - std::string

You can connect to signal any callback which looks like callable object but be aware than signature of callback must be equal signature of corresponding signal:

Callback Description
s.connect(foo); foo is a common function
s.connect(bar); bar is a lambda function
s.connect(baz); baz is a class with operator()
s.connect(&qx, &qux::func); qx is a instance of class qux

Result of this function is a instance of class connection.

When signal is emitted return value will be the result of executing last connected callback. If you want to receive all results of callbacks you should pass aggregate function as last parameter:

lsignal::signal<int(int,int)> s;
...
auto agg = [](const std::vector<int>& v) -> int { ... };
s(2, 3, agg);
connection

connection contains link between signal and callback. Available next operations:

Method Description
is_locked Check if connection is locked
set_lock If connection is locked then callback won't be called
disconnect Remove callback from signal

Also you can pass connection directly to signal::disconnect for disconnecting this connection.

slot

This class similar to connection but is used for owhership policy. Look example:

class foo : public lsignal::slot
{
    ...
};
...
foo f;

// disconnect when f was destroyed
s.connect([](){ ... }, &f);

Performance

Synthetic test (one or more empty callbacks) showed that calling lsignal from two to five times faster than calling boost::signal2 which was created with dummy (empty) mutex.

lsignal's People

Contributors

cpp11nullptr avatar dknof avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.