`
chenqi210
  • 浏览: 76696 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

event

    博客分类:
  • c++
 
阅读更多
#ifndef ODBCLIB_CORE_EVENT_EVENT_H
#define ODBCLIB_CORE_EVENT_EVENT_H

#include "Event.template"
#include "Event.implement"

#endif

 

#ifndef ODBCLIB_CORE_EVENT_EVENT_TEMPLATE
#define ODBCLIB_CORE_EVENT_EVENT_TEMPLATE

#include <vector>

namespace odbclib
{
	namespace core
	{
		namespace event
		{
			template <typename EventArgType> class EventListener;

			template<typename EventArgType>
			class Event
			{
			public:
				typedef std::vector< EventListener<EventArgType>* > ListenerList;

			public:
				virtual ~Event();
				virtual Event & addListener		(EventListener<EventArgType> &);
				virtual Event & removeListener	(EventListener<EventArgType> &);
				virtual Event & removeListeners	();

				virtual void notifyListeners(EventArgType const&);
			private:
				ListenerList m_listeners;
			};
		}
	}
}

#endif

 

#include "EventListener.template"
#include <algorithm>

namespace odbclib
{
	namespace core
	{
		namespace event
		{
			template<typename T>
			Event<T>::~Event()
			{
				removeListeners();
			}

			template<typename T>
			Event<T> & Event<T>::addListener(EventListener<T> &listener)
			{ 
				m_listeners.push_back(&listener);
				listener.m_events.push_back(this);
				return *this;
			}

			template<typename T>
			Event<T> & Event<T>::removeListener(EventListener<T> &listener)
			{
				m_listeners.erase(
					std::remove(
						m_listeners.begin(),
						m_listeners.end(),
						&listener),
					m_listeners.end());
				listener.m_events.erase(
					std::remove(
						listener.m_events.begin(),
						listener.m_events.end(),
						this),
					listener.m_events.end());
				return *this;
			}

			template<typename T>
			Event<T> & Event<T>::removeListeners()
			{
				ListenerList listeners(m_listeners);
				for(typename ListenerList::iterator iter = listeners.begin();
					iter != listeners.end(); ++iter)
					(*iter)->m_events.erase(
						std::remove(
							(*iter)->m_events.begin(),
							(*iter)->m_events.end(),
							this),
						(*iter)->m_events.end());	
				m_listeners.clear();
				return *this;
			}

			template<typename T>
			void Event<T>::notifyListeners(T const& e)
			{
				ListenerList listeners(m_listeners);
				for(typename ListenerList::iterator iter = listeners.begin();
					iter != listeners.end(); ++iter)
					(*iter)->onEvent(e);
			}
		}
	}
}

 

#ifndef ODBCLIB_CORE_EVENT_EVENTLISTENER_H
#define ODBCLIB_CORE_EVENT_EVENTLISTENER_H

#include "EventListener.template"
#include "EventListener.implement"

#endif

 

#ifndef ODBCILB_CORE_EVENT_EVENTLISTENER_TEMPLATE
#define ODBCILB_CORE_EVENT_EVENTLISTENER_TEMPLATE

#include <vector>

namespace odbclib
{
	namespace core
	{
		namespace event
		{
			template<typename EventArgType> class Event;

			template<typename EventArgType>
			class EventListener
			{
			public:
				typedef std::vector< Event<EventArgType>* > EventList;

				virtual ~EventListener();
				virtual void onEvent(EventArgType const&);

			private:
				EventList m_events;

				friend class Event<EventArgType>;
			};
		}
	}
}

#endif

 

#include "Event.template"

#include <algorithm>

namespace odbclib
{
	namespace core
	{
		namespace event
		{
			template<typename T>
			EventListener<T>::~EventListener()
			{
				EventList events(m_events);
				for(typename EventList::iterator iter = events.begin();
					iter != events.end(); ++iter)
					(*iter)->removeListener(*this);
			}

			template<typename T>
			void EventListener<T>::onEvent(T const& e)
			{
	
			}
		}
	}
}
 
分享到:
评论

相关推荐

    Event_Log_Explorer_4.3.8.zi

    + Added Custom columns - you can extract information from description and display it in event list. + Added alerts by event type. * NewAPI: Event description could be missing for some events. Fixed. *...

    EventLog_Analyzer.zip

    Eventlog Analyzer日志管理系统、日志分析工具、日志服务器的功能及作用  Eventlog Analyzer是用来分析和审计系统及事件日志的管理软件,能够对全网范围内的主机、服务器、网络设备、数据库以及各种应用服务系统等...

    EVENT TAG EVENT TAG EVENT TAG

    Activity Details独木舟水球同乐日 及 独木舟水球邀请赛 @ 迪欣湖 [2010年7月3,4日...独木舟水球邀请赛将 迪欣湖活动中心举行ㄛ欢迎光临观赛〔详情请 览 http://www.facebook.com/event.php?eid=115015881876447 ...

    EVENT

    EVENT

    Video-based event recognition

    single-thread action is represented by a stochastic finite automaton of event states, which are recognized from the characteristics of the trajectory and shape of moving blob of the actor using ...

    shiro-event-1.4.0-API文档-中英对照版.zip

    赠送jar包:shiro-event-1.4.0.jar; 赠送原API文档:shiro-event-1.4.0-javadoc.jar; 赠送源代码:shiro-event-1.4.0-sources.jar; 赠送Maven依赖信息文件:shiro-event-1.4.0.pom; 包含翻译后的API文档:shiro-...

    Event Streams in Action: Real-time event systems with Kafka and Kinesis

    Event Streams in Action: Real-time event systems with Kafka and Kinesis。 Writing real-world applications in a data-rich environment can feel like being caught in the cross fire of a paintball battle....

    shiro-event-1.4.0-API文档-中文版.zip

    赠送jar包:shiro-event-1.4.0.jar; 赠送原API文档:shiro-event-1.4.0-javadoc.jar; 赠送源代码:shiro-event-1.4.0-sources.jar; 赠送Maven依赖信息文件:shiro-event-1.4.0.pom; 包含翻译后的API文档:shiro-...

    配置Event_alert

    配置Event_alert 其中“活动”、“活动级”配置可以参考下面的例子,不用配置“预警详细资料”,但必须是“定期”alert,不能是“事件”alert,“频率”选择“根据需要”,保存后,进入:“预警系统管理器”&gt;“请求...

    Windows2016 EventLog Analyzer安装部署.pptx

    Windows2016 EventLog Analyzer安装部署 1.产品概览 2.功能介绍 3.版本对比 4.硬件要求 5.操作系统要求 6.安装Windows Server 2016 7.EventLog Analyzer使用的端口 8.部署EventLog Analyzer 9.应用EventLog Analyzer

    onvif之event详解(汉语)

    非常好的onvif Event汉语资料,文档中详细阐述了onvif 事件处理模块的交互过程,对于做onvif开发有很大的帮助!

    EventLog Analyzer 12.2.1

    ManageEngine EventLog Analyzer 12.2.1

    Visual Event.rar

    用Chrome插件Visual Event查看Dom绑定的事件 Visual Event简介 Visual Event是一个开源Javascript 书签,能提供绑定在DOM元素上的事件调试信息。Visual Event能显示如下信息: 1、哪一个元素有事件绑定 ...

    eventsource-polyfill.js

    为IE浏览器添加EventSource兼容性支持。为IE浏览器添加EventSource兼容性支持。

    关于Unhandled event loop exception No more handles的两种解决方案

    在使用eclipse的时候,有时候会弹出一个方框,里面的内容是Unhandled event loop exception No more handles,当你点击OK的时候,又会出来一个方框,里面第一句话是 An SWT error has occurred,并且诱导你关闭...

    Windows Event Log 日志管理工具

    Windows Event Log 日志管理工具,功能包括添加Event Source,添加Event Log,删除Event Source,删除EventLog. 可用于Web项目发布中对自定义日志的管理。 因需要一定系统访问权限,请使用管理员权限登录使用。

    Designing Event-Driven Systems

    Designing Event-Driven Systems_Concepts and Patterns for Streaming Services with Apache Kakfa, published by OReilly

    Event Processing in Action PDF

    Event Processing in Action introduces the major concepts of event-driven architectures and shows how to use, design, and build event processing systems and applications. Written for working software ...

    Eventsource-masterPHP事件源库.zip

    在做的时候主要的一个问题是如何更好的把本来在Terminal上输出的结果实时的输出到web界面上,最后发现了EventSource这个东西,除了IE浏览器不支持,其他浏览器都内置这个对象,可以很好得完成我的这个需求。...

    [示例][PHP]Eventsource-masterPHP事件源库.zip

    在做的时候主要的一个问题是如何更好的把本来在Terminal上输出的结果实时的输出到web界面上,最后发现了EventSource这个东西,除了IE浏览器不支持,其他浏览器都内置这个对象,可以很好得完成我的这个需求。...

Global site tag (gtag.js) - Google Analytics