{"id":16602793,"url":"https://github.com/jamesboer/nfy","last_synced_at":"2025-08-27T11:07:44.817Z","repository":{"id":117473720,"uuid":"273494896","full_name":"JamesBoer/Nfy","owner":"JamesBoer","description":"A Lightweight Template-Based Notification Library","archived":false,"fork":false,"pushed_at":"2022-08-27T18:18:09.000Z","size":245,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T08:11:12.430Z","etag":null,"topics":["c-plus-plus","c-plus-plus-14","cmake","game-development","nfy","nfy-library","notification","notification-library","observer-pattern","registered-observers","weak-pointers"],"latest_commit_sha":null,"homepage":null,"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/JamesBoer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"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}},"created_at":"2020-06-19T13:00:36.000Z","updated_at":"2025-01-15T07:31:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"32ecb5f3-39bb-4222-a3f5-c38bebfe2dd3","html_url":"https://github.com/JamesBoer/Nfy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JamesBoer/Nfy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesBoer%2FNfy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesBoer%2FNfy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesBoer%2FNfy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesBoer%2FNfy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JamesBoer","download_url":"https://codeload.github.com/JamesBoer/Nfy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesBoer%2FNfy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272324301,"owners_count":24914387,"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","status":"online","status_checked_at":"2025-08-27T02:00:09.397Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["c-plus-plus","c-plus-plus-14","cmake","game-development","nfy","nfy-library","notification","notification-library","observer-pattern","registered-observers","weak-pointers"],"created_at":"2024-10-12T00:23:55.329Z","updated_at":"2025-08-27T11:07:44.808Z","avatar_url":"https://github.com/JamesBoer.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nfy ![CI](https://github.com/JamesBoer/Nfy/workflows/CI/badge.svg)\nNfy is a template-based notification library designed to simplify the implementation of an interface-based observer pattern in C++.  \n\n## What is Nfy Used For?\nThe Nfy library allows you to send messages from one class to another through the use of an interface.  Observer classes are derived from this interface, register themselves with the notification system, and can then receive messages.  The notification class retains a list of weak pointers to these observers, allowing a the notification system to send messages to an arbitrary number of observers.\n\n## Building Nfy\nThe Nfy library is distributed as a single header file, Nfy.hpp, so you can include the library header and start using it immediately.  Nfy requires a C++ 14 compliant compiler.\n\n## How to Use Nfy\nThe Nfy library consists of a single class, called ```Notify```, which is in the namespace Nfy.  For brevity and clarity, all subsequent examples are assuming ```using namespace Nfy``` has been added earlier in the source file.  Let's examine how we might use this class.  \n\n### Simple Events\nFirst, let's presume we want to create an interface from which we can derive other classes, so as to receive notification events.  Let's call this class ```INotify```, and assume we have a single notification event we want to track, for which we'll create a handler function called ```void OnEventX(int arg)```.  This function does not return any value, and takes a single integer argument.\n\n``` c++\nclass INotify\n{\npublic:\n    virtual ~INotify() {}\n    virtual void OnEventX(int arg) = 0;\n};\n```    \n    \nNow let's derive a concrete implementation from this interface, which we'll call ```Observer```.  \n\n``` c++\nclass Observer : public INotify\n{\npublic:\n    virtual void OnEventX(int arg) override \n    {\n        // EventX called!\n    }\n};\n```   \nAll instances of this ```Observer``` class, once registered with an approprate notifier object, will have it's OnEventX() member function called when involved from the notifier object.  Let's examine how this is done.\n\n``` c++\n// Create notify bus object\nNotifier\u003cINotify\u003e notifier;\n\n// Create observer object and register with notify bus\nauto observer = std::make_shared\u003cObserver\u003e();\nnotifier.Register(observer);\n\n// Call OnEventX() with parameter for all registered observers\nnotifier.Notify(\u0026INotify::OnEventX, 42);\n``` \n\nWe see here a single observer registered with a single notify bus.  The ```OnEventX``` function call is invoked on all registered observers with the ```Notify``` call, where we passed both the function signature and any subsequent parameters.\n\nYou'll note that we've created the observer object with a ```std::shared_ptr```.  This is necessary for the ```Notifier``` class to hold onto the observers as weak pointers.  Using weak pointers means you don't have to remember to explicitly unregister the observer.  ```Notifier``` will check internal pointers as it iterates through them, and erase any weak pointers that have expired.\n\n### Events with Boolean Return Values\n\nNotifications using function signatures with a Boolean return value have a special meaning for Nfy.  The ```Notifier``` class will call all registered observers until a function returns a true value, which signifies \"I've handled this event, so you can stop processing the requests now.\"  There may be cases where it only makes sense for one observer to handle an event, after which all other observers should not be notified.\n\nLet's assume our ```INotify``` interface looked like this, with a Boolean return value on the ```OnEventX()``` function:\n\n``` c++\nclass INotify\n{\npublic:\n    virtual ~INotify() {}\n    virtual bool OnEventX(int arg) = 0;\n};\n```   \n\nWe can now check to see if at least one observer returned true, signaling that the event was \"handled\". \n\n``` c++\n// Call OnEventX() with parameter for all registered observers\nif (notifier.Notify(\u0026INotify::OnEventX, 42))\n    // Event has been handled\n``` \n\n### Notifier Options\n\nBy default, all operations in the ```Notifier``` class are thread safe, protected by a ```std::mutex```, and the internal ```std::vector``` uses the default allocator.  Both of these defaults can be overridden.\n\nTo disable thread safety in situations where you wish to make this performance-safety trade-off, you can create a single-threaded ```Notifier``` bus object which uses a custom allocator as follows:\n\n``` c++\n// Create notify bus object\nNotifier\u003cINotify, SingleThreaded, MyAllocator\u003cstd::weak_ptr\u003cINotify\u003e\u003e\u003e notifier;\n\n``` ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesboer%2Fnfy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamesboer%2Fnfy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesboer%2Fnfy/lists"}