{"id":22509186,"url":"https://github.com/adrg/sling","last_synced_at":"2025-08-03T13:31:16.188Z","repository":{"id":72534269,"uuid":"209814455","full_name":"adrg/sling","owner":"adrg","description":"Lightweight C++ Signals and Slots implementation","archived":false,"fork":false,"pushed_at":"2024-05-30T16:30:43.000Z","size":11,"stargazers_count":20,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-05-30T19:40:58.043Z","etag":null,"topics":["callback","callbacks","cpp","cpp11","cpp14","cpp17","events","header-only","library","lightweight","signals","signalslot","slots"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adrg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"adrgb"}},"created_at":"2019-09-20T14:47:58.000Z","updated_at":"2024-05-30T16:30:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b72f26a-466b-44b9-98a0-c8c4def50b21","html_url":"https://github.com/adrg/sling","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrg%2Fsling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrg%2Fsling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrg%2Fsling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrg%2Fsling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adrg","download_url":"https://codeload.github.com/adrg/sling/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228547949,"owners_count":17935151,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["callback","callbacks","cpp","cpp11","cpp14","cpp17","events","header-only","library","lightweight","signals","signalslot","slots"],"created_at":"2024-12-07T01:28:02.767Z","updated_at":"2024-12-07T01:28:03.432Z","avatar_url":"https://github.com/adrg.png","language":"C++","readme":"\u003ch1 align=\"center\"\u003esling\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\n        \u003cimg alt=\"MIT license\" src=\"https://img.shields.io/github/license/adrg/sling\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/adrg/sling/issues\"\u003e\n        \u003cimg alt=\"GitHub issues\" src=\"https://img.shields.io/github/issues/adrg/sling\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://ko-fi.com/T6T72WATK\"\u003e\n        \u003cimg alt=\"Buy me a coffee\" src=\"https://img.shields.io/static/v1.svg?label=%20\u0026message=Buy%20me%20a%20coffee\u0026color=579fbf\u0026logo=buy%20me%20a%20coffee\u0026logoColor=white\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\nsling is a lightweight C++ implementation of signals and slots. A slot is\nessentially a callback wrapper which can be created from different kinds of\ncallable entities. Slots can be connected to a signal, and they get notified\nwhen the signal is emitted.\n\n## Installation\n\nBeing a header-only library, you can just include it in your project. Requires\ncompiler support for C++11 or later.\n\n## Usage\n\n#### Creating signals\n```cpp\nsl::Signal\u003c\u003e sig0;            // signal without parameters.\nsl::Signal\u003cstd::string\u003e sig1; // signal with one parameter (std::string).\nsl::Signal\u003cdouble, int\u003e sig2; // signal with two parameters (double and int).\n```\n\n#### Connecting slots\n```cpp\nsl::Signal\u003cint\u003e sig;\n```\n\nConnect slots created from lambda expressions.\n```cpp\nsig.connect(sl::Slot\u003cint\u003e([](int x) {}));\n```\n\nConnect slots created from regular functions.\n```cpp\nvoid foo(int x) {}\nsig.connect(sl::Slot\u003cint\u003e(foo));\n```\n\nConnect slots created from object member functions.\n```cpp\nclass Foo\n{\npublic:\n    void bar(int x) {}\n    void baz(int x) const {}\n    virtual void qux(int x) {}\n    static void corge(int x) {}\n};\n\nFoo foo;\nsig.connect(sl::Slot\u003cint\u003e(\u0026foo, \u0026Foo::bar));\nsig.connect(sl::Slot\u003cint\u003e(\u0026foo, \u0026Foo::baz));\nsig.connect(sl::Slot\u003cint\u003e(\u0026foo, \u0026Foo::qux));\nsig.connect(sl::Slot\u003cint\u003e(Foo::corge));\n```\n\nConnect slots created from object instances implementing operator ().\n```cpp\nstruct Bar\n{\n    void operator () (int x) const {}\n};\n\nsig.connect(sl::Slot\u003cint\u003e(Bar()));\n```\n\n#### Disconnecting slots\n```cpp\nvoid foo(int x) {}\nsl::Signal\u003cint\u003e sig;\n```\n\nDisconnect using the slot interface.\n```cpp\nsl::Slot\u003cint\u003e slot(foo);\nsig.connect(slot);\nslot.disconnect();\n```\n\nDisconnect by passing a reference or a pointer to the slot.\n```cpp\nsl::Slot\u003cint\u003e slot(foo);\nsig.connect(slot);\nsig.disconnect(slot); // or sig.disconnect(\u0026slot);\n```\n\nDisconnect by passing the slot ID returned on signal connection.\n```cpp\nsl::SlotID slotID = sig.connect(sl::Slot\u003cint\u003e(foo));\nsig.disconnect(slotID);\n```\n\nDisconnect all slots.\n```cpp\nsig.clear();\n```\n\nAll slots are automatically disconnected when the signal they are connected to\ngoes out of scope. Similarly, slots are automatically disconnected from signals\nwhen they go out of scope.\n\nSlots are suitable as public class members, as they are automatically disconnected\nwhen the class instance they belong to goes out of scope. In addition, this\nallows private member functions to be specified as slot callbacks.\n```cpp\nclass Baz\n{\nprivate:\n    void bar(int x) {}\npublic:\n    sl::Slot\u003cint\u003e onBar{this, \u0026Baz::bar};\n};\n\nBaz b;\nsig.connect(b.onBar);\n```\n\n#### Emitting signals\n```cpp\nsl::Signal\u003cint\u003e sig;\nsig(1); // or sig.emit(1);\n```\n\n#### Copying and moving\n\nSignal copying is disabled as I have not found an intuitive behaviour for\nthis operation. Moving signals is allowed and it transfers all connected slots\nto the new signal. The moved signal is left in a valid state, as if newly constructed.\n\nSlot copying is permitted and the result of the operation is a slot having a\ncopy of the source slot callback. However, the new slot is not connected to the\nsignal the original slot is connected to, if any. When moving slots, the new\nslot basically replaces the old one. If the moved slot is connected to a signal,\nit is disconnected first, and the new one is connected to that signal.\nThe moved slot is left in a valid state, having no callback. A new callback\ncan be assigned using the `setCallback` method.\n\n#### Thread safety\n\nThe library does not guarantee thread safety in its current state. I am\nconsidering making it thread safe in the future.\n\n## Contributing\n\nContributions in the form of pull requests, issues or just general feedback,\nare always welcome.  \nSee [CONTRIBUTING.MD](CONTRIBUTING.md).\n\n## License\nCopyright (c) 2019 Adrian-George Bostan.\n\nThis project is licensed under the [MIT license](http://opensource.org/licenses/MIT).\nSee [LICENSE](LICENSE) for more details.\n","funding_links":["https://ko-fi.com/adrgb","https://ko-fi.com/T6T72WATK"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrg%2Fsling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadrg%2Fsling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrg%2Fsling/lists"}