A lightweight synchronous event framework for C++11
Overview
Like many other event frameworks, this project allows you to reduce inter-class dependencies and decouple your C++11 code by leveraging synchronous events and event handlers.
Unlike managed languages such as C# and Java, C++ is statically typed and doesn't support reflection or anonymous delegates making event systems slightly more difficult. This project attempts to create a simple and lightweight event framework that can easily be adapted to any C++11 project. The only requirements are a compiler that supports C++11 and access to the standard C++ libraries. It was inspired by the design of several public event APIs such as in Google's Web Toolkit and those found in popular game modding frameworks.
The files can be dropped into any existing project as is without any modification or can be easily modified to fit an existing design. One example of a common tweak would be to replace the included Object base class with another base class that is common to the project. The EventBus requires that all events be fired from an Object type which could be replaced by an already existing class in your project.
The EventBus does perform a few 'unsafe' operations by statically casting to and from void *. This was originally done using the boost::any library to avoid static casting but was changed to void * in the interest of making runtime speed faster and the code more portable. There are many projects that don't include Boost, and the casts are protected through the use of templates which remove the possibility of an incorrect cast.
Source Files
Core Files
- /src/event/Event.hpp
- /src/event/EventBus.cpp
- /src/event/EventBus.hpp
- /src/event/EventHandler.hpp

本文介绍了一个轻量级的C++11同步事件框架,旨在减少代码间的依赖并实现解耦。框架不需要反射或匿名委托,适用于任何C++11项目。它包括事件的创建、触发、注册和注销处理器的详细步骤,并提供了示例代码。
最低0.47元/天 解锁文章
2607

被折叠的 条评论
为什么被折叠?



