From 05d6e1341a7138941e39964cee39c119a049bef2 Mon Sep 17 00:00:00 2001 From: Aleksandar Fabijanic Date: Tue, 14 Oct 2025 22:04:01 +0200 Subject: [PATCH] Add DataNotification #5047 --- Foundation/include/Poco/Notification.h | 53 ++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/Foundation/include/Poco/Notification.h b/Foundation/include/Poco/Notification.h index 9d04db9c6..59cb1c2b9 100644 --- a/Foundation/include/Poco/Notification.h +++ b/Foundation/include/Poco/Notification.h @@ -57,6 +57,59 @@ protected: }; +template +class DataNotification: public Notification + /// DataNotification carries a topic and an associated payload of type T. +{ +public: + using Ptr = AutoPtr>; + + template + DataNotification(std::string topic, U&& data) + /// Creates the DataNotification with a topic and payload. + : Notification(std::move(topic)), + _payload(std::forward(data)) + { + } + + explicit DataNotification(std::string topic) + /// Creates the DataNotification with a topic and a default-constructed payload. + : Notification(std::move(topic)), + _payload() + { + } + + ~DataNotification() override = default; + + std::string topic() const + /// Returns the notification topic. + { + return name(); + } + + const T& payload() const + /// Returns the payload. + { + return _payload; + } + + T& payload() + /// Returns a modifiable reference to the payload. + { + return _payload; + } + + void setPayload(T data) + /// Sets the payload. + { + _payload = std::move(data); + } + +private: + T _payload; +}; + + } // namespace Poco