Thread collector. Collects threads during a set timeframe and returns them in a list via the completed() method.
More...
#include <dpp.h>
|
| thread_collector (cluster *cl, uint64_t duration) |
| Construct a new thread collector object. More...
|
|
virtual void | completed (const std::vector< dpp::thread > &list)=0 |
| Return the completed collection. More...
|
|
virtual const dpp::thread * | filter (const dpp::thread_create_t &element) |
| Select and filter the items which are to appear in the list This is called every time a new event is fired, to filter the event and determine which of the items is sent to the list. Returning nullptr excludes the item from the list. More...
|
|
virtual | ~thread_collector ()=default |
| Destroy the thread collector object. More...
|
|
virtual void | completed (const std::vector< C > &list)=0 |
| You must implement this function to receive the completed list of captured objects. More...
|
|
virtual const C * | filter (const T &element)=0 |
| Filter the list of elements. More...
|
|
virtual void | cancel () |
| Immediately cancels the collector. More...
|
|
Thread collector. Collects threads during a set timeframe and returns them in a list via the completed() method.
◆ thread_collector()
dpp::thread_collector::thread_collector |
( |
cluster * |
cl, |
|
|
uint64_t |
duration |
|
) |
| |
|
inline |
Construct a new thread collector object.
- Parameters
-
cl | cluster to associate the collector with |
duration | Duration of time to run the collector for in seconds |
◆ ~thread_collector()
virtual dpp::thread_collector::~thread_collector |
( |
| ) |
|
|
virtualdefault |
Destroy the thread collector object.
◆ cancel()
template<class T , class C >
Immediately cancels the collector.
Use this if you have met the conditions for which you are collecting objects early, e.g. you were watching for a message containing 'yes' or 'no' and have received it before the time is up.
- Note
- Causes calling of the completed() method if it has not yet been called.
◆ completed() [1/2]
template<class T , class C >
virtual void dpp::collector< T, C >::completed |
( |
const std::vector< C > & |
list | ) |
|
|
pure virtualinherited |
You must implement this function to receive the completed list of captured objects.
- Parameters
-
list | The list of captured objects in captured order |
◆ completed() [2/2]
virtual void dpp::thread_collector::completed |
( |
const std::vector< dpp::thread > & |
list | ) |
|
|
pure virtual |
Return the completed collection.
- Parameters
-
list | items collected during the timeframe specified |
◆ filter() [1/2]
Select and filter the items which are to appear in the list This is called every time a new event is fired, to filter the event and determine which of the items is sent to the list. Returning nullptr excludes the item from the list.
- Parameters
-
- Returns
- Returned item to add to the list, or nullptr to skip adding this element
◆ filter() [2/2]
template<class T , class C >
Filter the list of elements.
Every time an event is fired on the collector, this method wil be called to determine if we should add an object to the list or not. This function can then process the element
value, extract the parts which are to be saved to a list (e.g. a dpp::message out of a dpp::message_create_t) and return it as the return value. Returning a value of nullptr causes no object to be stored.
Here is an example of how to filter messages which have specific text in them. This should be used with the specialised type dpp::message_collector
if (m.
msg.
content.find(
"something i want") != std::string::npos) {
} else {
return nullptr;
}
}
virtual const dpp::thread * filter(const dpp::thread_create_t &element)
Select and filter the items which are to appear in the list This is called every time a new event is ...
Definition: dpp.h:276
Create message.
Definition: dispatcher.h:1172
message msg
message that was created (sent).
Definition: dispatcher.h:1181
Represents messages sent and received on Discord.
Definition: message.h:1036
std::string content
Definition: message.h:1046
- Parameters
-
element | The event data to filter |
- Returns
- const C* Returned object or nullptr
◆ owner
template<class T , class C >