2018-07-09 22:15:37 +08:00
|
|
|
# Utilities reference
|
|
|
|
|
2019-03-31 11:22:36 +08:00
|
|
|
## Header
|
2018-07-09 22:15:37 +08:00
|
|
|
|
2021-01-20 20:59:29 +08:00
|
|
|
eventpp/utilities/eventutil.h
|
|
|
|
|
|
|
|
## API reference
|
2018-07-09 22:15:37 +08:00
|
|
|
|
|
|
|
```c++
|
|
|
|
template <typename DispatcherType>
|
|
|
|
bool removeListener(
|
2022-02-04 09:00:50 +08:00
|
|
|
DispatcherType & dispatcher,
|
|
|
|
const typename DispatcherType::Event & event,
|
|
|
|
const typename DispatcherType::Callback & listener
|
2018-07-09 22:15:37 +08:00
|
|
|
);
|
|
|
|
```
|
|
|
|
The function finds `listener` of `event` in `dispatcher`, if it finds one, removes the listener and returns true, otherwise returns false.
|
|
|
|
Note: the function only removes the first found listener. To remove more than one listeners, repeat calling this function until it returns false.
|
|
|
|
This function requires the listener be able to be compared with equal operator (==).
|
|
|
|
|
|
|
|
```c++
|
|
|
|
template <typename CallbackListType>
|
|
|
|
bool removeListener(
|
2022-02-04 09:00:50 +08:00
|
|
|
CallbackListType & callbackList,
|
|
|
|
const typename CallbackListType::Callback & callback
|
2018-07-09 22:15:37 +08:00
|
|
|
);
|
|
|
|
```
|
|
|
|
The function finds `callback` in `callbackList`, if it finds one, removes the callback and returns true, otherwise returns false.
|
|
|
|
Note: the function only removes the first found callback. To remove more than one callbacks, repeat calling this function until it returns false.
|
|
|
|
This function requires the callback be able to be compared with equal operator (==).
|
|
|
|
|
2018-12-23 09:48:13 +08:00
|
|
|
```c++
|
|
|
|
template <typename DispatcherType>
|
2018-12-23 10:20:48 +08:00
|
|
|
bool hasListener(
|
2022-02-04 09:00:50 +08:00
|
|
|
DispatcherType & dispatcher,
|
|
|
|
const typename DispatcherType::Event & event,
|
|
|
|
const typename DispatcherType::Callback & listener
|
2018-12-23 09:48:13 +08:00
|
|
|
);
|
|
|
|
```
|
2018-12-23 10:20:48 +08:00
|
|
|
The function finds `listener` of `event` in `dispatcher`, returns true if it finds any one, otherwise returns false.
|
|
|
|
This function requires the listener be able to be compared with equal operator (==).
|
2018-12-23 09:48:13 +08:00
|
|
|
|
|
|
|
```c++
|
|
|
|
template <typename DispatcherType>
|
2018-12-23 10:20:48 +08:00
|
|
|
bool hasAnyListener(
|
2022-02-04 09:00:50 +08:00
|
|
|
DispatcherType & dispatcher,
|
|
|
|
const typename DispatcherType::Event & event
|
2018-12-23 09:48:13 +08:00
|
|
|
);
|
|
|
|
```
|
2018-12-23 10:20:48 +08:00
|
|
|
The function finds any listener of `event` in `dispatcher`, returns true if it finds any one, otherwise returns false.
|
2018-12-23 09:48:13 +08:00
|
|
|
|
|
|
|
```c++
|
|
|
|
template <typename CallbackListType>
|
|
|
|
bool hasListener(
|
2022-02-04 09:00:50 +08:00
|
|
|
CallbackListType & callbackList,
|
|
|
|
const typename CallbackListType::Callback & callback
|
2018-12-23 09:48:13 +08:00
|
|
|
);
|
|
|
|
```
|
|
|
|
The function finds `callback` in `callbackList`, returns true if it finds one, otherwise returns false.
|
|
|
|
This function requires the callback be able to be compared with equal operator (==).
|
2018-12-23 10:20:48 +08:00
|
|
|
|
|
|
|
```c++
|
|
|
|
template <typename CallbackListType>
|
|
|
|
bool hasAnyListener(
|
2022-02-04 09:00:50 +08:00
|
|
|
CallbackListType & callbackList
|
2018-12-23 10:20:48 +08:00
|
|
|
);
|
|
|
|
```
|
|
|
|
The function finds any callback in `callbackList`, returns true if it finds any one, otherwise returns false.
|