libhatchet
Loading...
Searching...
No Matches
hxtask.hpp
Go to the documentation of this file.
1#pragma once
2// SPDX-FileCopyrightText: © 2017-2026 Adrian Johnston.
3// SPDX-License-Identifier: MIT
4// This file is licensed under the MIT license found in the LICENSE.md file.
5
9
10#include "libhatchet.h"
11
12// HX_USE_MACROS_WITH_MODULE allows including macros alongside the module.
13#if HX_USE_MACROS_WITH_MODULE
14#error Header does not provide macros alone.
15#endif
16
17HX_NS_BEGIN_
18
19class hxtask_queue;
20
23class hxtask {
24public:
29 virtual bool execute(hxtask_queue*) = 0;
30
35 virtual void on_completion(hxtask_queue*) { }
36
41 virtual void on_failure(hxtask_queue*) { }
42
46 virtual void on_cancel(hxtask_queue*) { }
47
49 virtual const char* get_label(void) const { return "task"; }
50
51private:
52 friend class hxtask_queue;
53
54 // Reduce confusion by separating these out.
55 void process(hxtask_queue* q_) {
56 if(execute(q_)) {
57 on_completion(q_);
58 }
59 else {
60 on_failure(q_);
61 }
62 }
63};
64
65HX_NS_END_
hxtask_queue - Provides a priority queue of tasks and a worker thread pool.
Definition hxtask_queue.hpp:25
hxtask - Pure virtual base class for operations to be performed on a different thread or at a later t...
Definition hxtask.hpp:23
virtual void on_completion(hxtask_queue *)
Indicates successful execution.
Definition hxtask.hpp:35
friend class hxtask_queue
Definition hxtask.hpp:52
virtual const char * get_label(void) const
Returns the label of the task, or "task" by default.
Definition hxtask.hpp:49
virtual bool execute(hxtask_queue *)=0
Executes the task.
virtual void on_cancel(hxtask_queue *)
Indicates cancelled execution.
Definition hxtask.hpp:46
virtual void on_failure(hxtask_queue *)
Indicates failed execution.
Definition hxtask.hpp:41
Provides core macros, memory management and feature detection.