-
Notifications
You must be signed in to change notification settings - Fork 11
quick_guide
Freeman Zhang edited this page Apr 28, 2015
·
20 revisions
Here is a straight-forward guide to show you how to use the code.
You can just drag the source code into your project.
Or use cmake to build a dynamic or static library, just
$ cd <folder where you checkout the source>
$ mkdir build
$ cd build
$ cmake ../
$ make && sudo make install
An event object for invocation is used by sender object to perform notifications, usually it's a member variable of template class CppEvent::Event<>.
For example, suppose you are developing a GUI project, you may need a clicked event in a button class:
class Button: public Widget
{
public:
Button(Widget* parent);
private:
CppEvent::Event<> clicked_;
};
Use template arguments to declare an event which will send 1 or more parameters.
For example:
class ToggleButton: public Widget
{
public:
ToggleButton(Widget* parent);
private:
CppEvent::Event<bool> toggled_;
};
Add EventRef<> in putlic area:
class Button: public Widget
{
public:
Button(Widget* parent);
CppEvent::EventRef<> clicked ()
{return clicked_};
private:
CppEvent::Event<> clicked_;
};
Event consumer must be a subclass of CppEvent::Trackable.
class Consumer: public CppEvent
{
public:
Consumer ();
void OnDoSth ();
};
The following snippet shows connect a button's click event to a Consumer.
Button btn;
Consumer rec;
btn.clicked().connect(&rec, &rec::OnDoSth);
Table of contents
- Quick Guide
- Delegate Implementation