当前位置: 首页>>代码示例>>C++>>正文


C++ NotificationCenter::postNotification方法代码示例

本文整理汇总了C++中NotificationCenter::postNotification方法的典型用法代码示例。如果您正苦于以下问题:C++ NotificationCenter::postNotification方法的具体用法?C++ NotificationCenter::postNotification怎么用?C++ NotificationCenter::postNotification使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NotificationCenter的用法示例。


在下文中一共展示了NotificationCenter::postNotification方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void NotificationCenterTest::test4()
{
	NotificationCenter nc;
	Observer<NotificationCenterTest, Notification> o1(*this, &NotificationCenterTest::handle1);
	Observer<NotificationCenterTest, Notification> o2(*this, &NotificationCenterTest::handle2);
	nc.addObserver(o1);
	assert (nc.hasObserver(o1));
	nc.addObserver(o2);
	assert (nc.hasObserver(o2));
	nc.postNotification(new Notification);
	assert (_set.size() == 2);
	assert (_set.find("handle1") != _set.end());
	assert (_set.find("handle2") != _set.end());
	nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
	assert (!nc.hasObserver(o1));
	nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle2));
	assert (!nc.hasObserver(o2));
	_set.clear();
	nc.postNotification(new Notification);
	assert (_set.empty());
	Observer<NotificationCenterTest, Notification> o3(*this, &NotificationCenterTest::handle3);
	nc.addObserver(o3);
	assert (nc.hasObserver(o3));
	nc.postNotification(new Notification);
	assert (_set.size() == 1);
	assert (_set.find("handle3") != _set.end());
	nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle3));
	assert (!nc.hasObserver(o3));
}
开发者ID:Chingliu,项目名称:poco,代码行数:29,代码来源:NotificationCenterTest.cpp

示例2: main_1

int main_1(int argc, char** argv) {

    NotificationCenter nc;
    Target target;

    // Observer works with plain pointers to Notification objects.
    nc.addObserver(
        Observer<Target, BaseNotification>(target, &Target::handleBase));
    // NObserver works with AutoPtr<Notification>.
    // handleBase and handleSub both got this
    nc.addObserver(
        NObserver<Target, SubNotification>(target, &Target::handleSub));

    std::cout << "* postNotification: BaseNotification" << std::endl;
    nc.postNotification(new BaseNotification("Base Class Notification"));

    // Targets subscribed for a particular notification class also receive
    // notifications that are subclasses of that class.
    std::cout << "* postNotification: SubNotification" << std::endl;
    nc.postNotification(new SubNotification("Sub Class Notification"));

    nc.removeObserver(
        Observer<Target, BaseNotification>(target, &Target::handleBase));
    nc.removeObserver(
        NObserver<Target, SubNotification>(target, &Target::handleSub));

    return 0;
}
开发者ID:ricleal,项目名称:CppPocoTests,代码行数:28,代码来源:poco.cpp

示例3:

void NotificationCenterTest::test5()
{
	NotificationCenter nc;
	nc.addObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
	nc.addObserver(Observer<NotificationCenterTest, TestNotification>(*this, &NotificationCenterTest::handleTest));
	nc.postNotification(new Notification);
	assert (_set.size() == 1);
	assert (_set.find("handle1") != _set.end());
	_set.clear();
	nc.postNotification(new TestNotification);
	assert (_set.size() == 2);
	assert (_set.find("handle1") != _set.end());
	assert (_set.find("handleTest") != _set.end());
	nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
	nc.removeObserver(Observer<NotificationCenterTest, TestNotification>(*this, &NotificationCenterTest::handleTest));
}
开发者ID:RangelReale,项目名称:sandbox,代码行数:16,代码来源:NotificationCenterTest.cpp

示例4: testAuto

void NotificationCenterTest::testAuto()
{
	NotificationCenter nc;
	nc.addObserver(NObserver<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handleAuto));
	nc.postNotification(new Notification);
	assert (_set.size() == 1);
	assert (_set.find("handleAuto") != _set.end());
	nc.removeObserver(NObserver<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handleAuto));
}
开发者ID:RangelReale,项目名称:sandbox,代码行数:9,代码来源:NotificationCenterTest.cpp

示例5: dispatch

void PriorityNotificationQueue::dispatch(NotificationCenter& notificationCenter)
{
    FastMutex::ScopedLock lock(_mutex);
    Notification::Ptr pNf = dequeueOne();
    while (pNf)
    {
        notificationCenter.postNotification(pNf);
        pNf = dequeueOne();
    }
}
开发者ID:as2120,项目名称:ZPoco,代码行数:10,代码来源:PriorityNotificationQueue.cpp

示例6:

void NotificationCenterTest::test2()
{
	NotificationCenter nc;
	nc.addObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
	assert (nc.hasObservers());
	assert (nc.countObservers() == 1);
	nc.postNotification(new Notification);
	assert (_set.size() == 1);
	assert (_set.find("handle1") != _set.end());
	nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
	assert (!nc.hasObservers());
	assert (nc.countObservers() == 0);
}
开发者ID:Victorcasas,项目名称:georest,代码行数:13,代码来源:NotificationCenterTest.cpp

示例7: dispatch

	void MessageQueue::dispatch(NotificationCenter& center, unsigned int maxNumberToDispatch)
	{
		MessagesIterator iter;
		unsigned int dispatchCount;

		Poco::ScopedRWLock lock(dispatchQueueRWLock, true);

		dispatchCount = 0;

		// First copy the messages from the queuedMessages queue to the dispatchQueue
		queuedMessagesRWLock.writeLock();
		iter = queuedMessages.begin();
		while ((iter != queuedMessages.end()) && ((maxNumberToDispatch == 0) || (dispatchCount < maxNumberToDispatch)))
		{
			// Insert message into dispatch queue
			dispatchQueue.push_back(*iter);

			// Remove message from queued messages queue
			iter = queuedMessages.erase(iter);

			dispatchCount++;
		}
		queuedMessages.clear();
		queuedMessagesRWLock.unlock();

		// Dispatch the messages
		for (iter = dispatchQueue.begin(); iter != dispatchQueue.end(); )
		{

			// Call duplicate on the Message instance, since Poco doesn't expect the object to be shared
			(*iter)->duplicate();

			// Send the message
			center.postNotification(*iter);

			// Remove the message from the list
			iter = dispatchQueue.erase(iter);
		}
		dispatchQueue.clear();
	}
开发者ID:mchamberlain,项目名称:asd-ve-platform,代码行数:40,代码来源:MessageQueue.cpp


注:本文中的NotificationCenter::postNotification方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。