AIStatefulTask ‐ Asynchronous, Stateful Task Scheduler library.

Threads-like task objects evolving through user-defined states.

BrokerKey.h
1#pragma once
2
3#include <boost/intrusive_ptr.hpp>
4#include <iosfwd>
5#include <cstdint>
6
8
9namespace statefultask {
10
11// BrokerKey
12//
13// Base class for objects that are used to initialize brokered tasks
14// and to initialize them.
15//
17{
18 public:
19 struct Deleter { Deleter(bool owner = true) : owner(owner) { } void operator()(BrokerKey const* ptr) const { if (owner) delete ptr; } bool owner; };
20 using unique_ptr = std::unique_ptr<BrokerKey, Deleter>;
21 using const_unique_ptr = std::unique_ptr<BrokerKey const, Deleter>;
22
23 virtual ~BrokerKey() = default;
24
25 virtual uint64_t hash() const = 0;
26 virtual void initialize(boost::intrusive_ptr<AIStatefulTask> task) const = 0;
27 virtual unique_ptr copy() const = 0;
28#ifdef CWDEBUG
29 virtual void print_on(std::ostream& os) const = 0;
30 friend std::ostream& operator<<(std::ostream& os, BrokerKey const& data) { data.print_on(os); return os; }
31#endif
32
33 public:
34 bool equal_to(BrokerKey const& other) const { return typeid(*this) == typeid(other) && equal_to_impl(other); }
35 unique_ptr non_owning_ptr() { return unique_ptr(this, false); }
36 const_unique_ptr non_owning_ptr() const { return const_unique_ptr(this, false); }
37
38 protected:
39 virtual bool equal_to_impl(BrokerKey const&) const = 0;
40};
41
43{
44 uint64_t operator()(BrokerKey::unique_ptr const& ptr) const { return ptr->hash(); }
45};
46
48{
49 bool operator()(BrokerKey::unique_ptr const& left, BrokerKey::unique_ptr const& right) const { return left->equal_to(*right); }
50};
51
52} // namespace statefultask
std::ostream & operator<<(std::ostream &os, AIStatefulTask::Handler const &handler)
Write a Handler to an ostream.
Definition: AIStatefulTask.cxx:1118
Definition: AIStatefulTask.h:96
Definition: BrokerKey.h:17
Tasks defined by the library project are put into this namespace.
Definition: AIStatefulTask.h:857
Definition: BrokerKey.h:48
Definition: BrokerKey.h:43
Definition: BrokerKey.h:19