summaryrefslogtreecommitdiffstats
path: root/engine/include/core
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-01-23 00:30:10 +0100
committerNao Pross <naopross@thearcway.org>2019-01-23 00:30:10 +0100
commitfd9ecd4e9c7cbe76bc60197a7183ac3ca4e8d0f8 (patch)
tree68f5d42aa3aee7ec2519a8766b8619bb73223d6e /engine/include/core
parentceh (diff)
downloadflatland-fd9ecd4e9c7cbe76bc60197a7183ac3ca4e8d0f8.tar.gz
flatland-fd9ecd4e9c7cbe76bc60197a7183ac3ca4e8d0f8.zip
Integrate prioritized into task, rename prior_t to priority_t
There was a bunch of code in core/priority.hpp that has been reduced. It works the same as before, just with less stuff. task.cpp is buildable without errors with: $ ninja build/engine/task.o
Diffstat (limited to 'engine/include/core')
-rw-r--r--engine/include/core/priority.hpp60
-rw-r--r--engine/include/core/signal.hpp6
-rw-r--r--engine/include/core/task.hpp19
3 files changed, 25 insertions, 60 deletions
diff --git a/engine/include/core/priority.hpp b/engine/include/core/priority.hpp
index 5f03bc9..0f00006 100644
--- a/engine/include/core/priority.hpp
+++ b/engine/include/core/priority.hpp
@@ -2,12 +2,10 @@
#include <set>
-namespace flat
-{
- namespace core
- {
- enum class prior_t : unsigned
- {
+namespace flat {
+ namespace core {
+
+ enum class priority_t : unsigned {
max = 0,
higher = 1,
high = 2,
@@ -17,47 +15,23 @@ namespace flat
min = 6,
};
- class prioritized
- {
- const prior_t m_priority;
+ class prioritized {
+ private:
+ const priority_t m_priority;
public:
+ prioritized(priority_t priority = priority_t::none)
+ : m_priority(priority) {}
- prioritized(prior_t m_priority = prior_t::none) : m_priority(m_priority) {}
-
- const prior priority() const
- {
+ const priority_t priority() const {
return m_priority;
}
- };
-
- struct prior_criteria
- {
- bool operator()(const prioritized& a, const prioritized& b) const
- {
- return a.priority() < b.priority();
- }
- };
-
- /* Compiler will complain if don't pass a non prioritized object */
-
- template <class T>
- using prior_set = std::multiset<T, prior_criteria>;
-
-
- /* Equivalent but with pointers */
-
- struct prior_ptr_criteria
- {
- bool operator()(const prioritized* a, const prioritized* b) const
- {
- return a->priority() < b->priority();
- }
- };
+ };
+
+ bool operator<(const prioritized& lhs, const prioritized& rhs) {
+ return lhs.priority() < rhs.priority();
+ }
+ }
+}
- /* Compiler will complain if don't pass a non prioritized object */
- template <class T>
- using prior_ptr_set = std::multiset<T*, prior_criteria>;
- }
-};
diff --git a/engine/include/core/signal.hpp b/engine/include/core/signal.hpp
index 1057f3f..755f3ed 100644
--- a/engine/include/core/signal.hpp
+++ b/engine/include/core/signal.hpp
@@ -22,12 +22,12 @@ namespace flat
object * sender;
void * data; // TODO, avoid this void pointer
- priority prior;
+ priority_t prior;
signal( object * sender,
const std::string& id = "",
void * data,
- prior_t prior = prior_t::none);
+ priority_t prior = priority_t::none);
/* Alias to flat::core::channel::emit() */
bool emit(const std::string& channel) const;
@@ -51,7 +51,7 @@ namespace flat
public:
- channel(const std::string& id = "", prior_t priority = prior_t::none);
+ channel(const std::string& id = "", priority_t priority = priority_t::none);
~channel();
void emit(const signal&);
diff --git a/engine/include/core/task.hpp b/engine/include/core/task.hpp
index 9422a23..b6ddad1 100644
--- a/engine/include/core/task.hpp
+++ b/engine/include/core/task.hpp
@@ -1,34 +1,25 @@
#pragma once
+#include "priority.hpp"
+
#include <functional>
#include <set>
namespace flat {
namespace core {
- class task {
+ class task : public prioritized {
public:
- enum class priority : unsigned {
- max = 0,
- high = 1,
- none = 2,
- low = 3,
- min = 4,
- };
-
- // to pass a member function (method) use std::bind(f, obj)
- task(std::function<void()> callback, priority p = priority::none);
task() = delete;
+ task(std::function<void()> callback, priority_t p = priority_t::none);
inline void operator()() const { m_callback(); }
- friend bool operator<(const task& lhs, const task& rhs);
private:
- const priority m_priority;
std::function<void()> m_callback;
};
struct job : public std::multiset<task> {
- inline void add_task(task t) {
+ inline auto add_task(task t) {
this->insert(t);
}