Notification Center in C ++

After programming at some point with iOS and C objects, I fell in love with the general notification template implemented by the NSNotificationCenter and NSNotification classes. Returning to C ++, which has always been my language of choice for most things, I am trying to replicate this pattern and believe that there really needs to be a common implementation of similar C ++ classes supporting it there.

It seems that the template is more difficult to implement in C ++ than Objective-C, due to the more dynamic nature of the later one, but it seems far from impossible. I looked at acceleration libraries because they are usually awesome, and it was sad not to find my luck there. Although the boost :: bind, boost :: lamda, boost :: function seems like they do most of the work. Am I missing something obvious? Is there something already existing that would allow me to easily reproduce the behavior of NSNotification / NSNotificationCenter?

+5
source share
3 answers

@anno, boot:: signal, , , , , C. boost:: signal tutorial, , .


:

, , . :

class NewsItem { /* ... */ };
boost::signal<void (const NewsItem&)> deliverNews;

deliverNews - , a NewsItem .


( boost:: bind):

, , , deliverNews. , , :

struct NewsMessageArea : public MessageArea
{
public:
  // ...

  void displayNews(const NewsItem& news) const
  {
    messageText = news.text();
    update();
  }
};

// ...
NewsMessageArea newsMessageArea = new NewsMessageArea(/* ... */);
// ...
deliverNews.connect(boost::bind(&NewsMessageArea::displayNews, newsMessageArea, _1));

, , boost:: signal

, , , newsMessageArea, deliverNews? , . , Boost.Signals NewsMessageArea, , newsMessageArea , newsMessageArea . NewsMessageArea boost:: signals:: trackable, :

struct NewsMessageArea : public MessageArea, public boost::signals::trackable
{
  // ...
};

: , Boost.Bind , , boost:: bind, .

+1

, - , ,

+2

boost, , poco::NotificationCenter.

Cocoa, Poco :

NotificationCenter - ++ NSNotificationCenter Apple Cocoa ( OpenStep).

+2
source

All Articles