summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-05-04 11:51:47 +0200
committerStanislaw Halik <sthalik@misaki.pl>2018-05-05 12:34:52 +0200
commita6f095c01e93090e185afd0d9f26bf4565a552ed (patch)
treef20a632b256bfa95b4470654a61f829d5a117f3b
parent7f8043b8287e187a7c1d4f0175ed9c527d6bdcc6 (diff)
compat, logic/pipeline: add bitwise enum operators
-rw-r--r--compat/enum-operators.hpp28
-rw-r--r--logic/pipeline.cpp2
-rw-r--r--logic/pipeline.hpp11
3 files changed, 36 insertions, 5 deletions
diff --git a/compat/enum-operators.hpp b/compat/enum-operators.hpp
new file mode 100644
index 00000000..e956c461
--- /dev/null
+++ b/compat/enum-operators.hpp
@@ -0,0 +1,28 @@
+#pragma once
+
+#include <type_traits>
+
+#define OTR_FLAGS_OP2(type, op) \
+ inline type operator op (type a, type b) \
+ { \
+ using t__ = std::underlying_type_t<type>; \
+ return static_cast<type>(t__((a)) op t__((b))); \
+ } // end
+
+#define OTR_FLAGS_SHIFT(type, op) \
+ type operator op (type, unsigned) = delete;
+
+#define OTR_FLAGS_OP1(type, op) \
+ inline type operator op (type x) \
+ { \
+ using t__ = std::underlying_type_t<type>; \
+ return static_cast<type>(t__((x))); \
+ } // end
+
+#define DEFINE_ENUM_OPERATORS(type) \
+ OTR_FLAGS_OP2(type, |) \
+ OTR_FLAGS_OP2(type, &) \
+ OTR_FLAGS_OP2(type, ^) \
+ OTR_FLAGS_OP1(type, ~) \
+ OTR_FLAGS_SHIFT(type, <<); \
+ OTR_FLAGS_SHIFT(type, >>); // end
diff --git a/logic/pipeline.cpp b/logic/pipeline.cpp
index 5f17f2b1..e562ef7f 100644
--- a/logic/pipeline.cpp
+++ b/logic/pipeline.cpp
@@ -667,7 +667,7 @@ void bits::negate(flags flag_)
}
}
-bool bits::get(unsigned flag)
+bool bits::get(flags flag)
{
return !!(b & flag);
}
diff --git a/logic/pipeline.hpp b/logic/pipeline.hpp
index 7c18f7fc..2fe0f64b 100644
--- a/logic/pipeline.hpp
+++ b/logic/pipeline.hpp
@@ -6,6 +6,7 @@
#include "api/plugin-support.hpp"
#include "mappings.hpp"
#include "compat/euler.hpp"
+#include "compat/enum-operators.hpp"
#include "runtime-libraries.hpp"
#include "extensions.hpp"
@@ -62,7 +63,7 @@ public:
using namespace time_units;
struct OTR_LOGIC_EXPORT bits
-{
+{
enum flags : unsigned {
f_center = 1 << 0,
f_held_center = 1 << 1,
@@ -73,12 +74,14 @@ struct OTR_LOGIC_EXPORT bits
std::atomic<unsigned> b;
- void set(flags flag_, bool val_);
+ void set(flags flag_, bool val);
void negate(flags flag_);
- bool get(unsigned flag);
+ bool get(flags flag);
bits();
};
+DEFINE_ENUM_OPERATORS(bits::flags);
+
class OTR_LOGIC_EXPORT pipeline : private QThread, private bits
{
Q_OBJECT
@@ -144,6 +147,6 @@ public:
void set_zero(bool value);
};
-} // ns pipeine_impl
+} // ns pipeline_impl
using pipeline_impl::pipeline;