Support a form of setting bits easily
This commit is contained in:
parent
275d6c0ce2
commit
f6ac2adb4d
|
@ -3,6 +3,24 @@
|
||||||
#include "../../Auxiliary/complex_bitmap.hpp"
|
#include "../../Auxiliary/complex_bitmap.hpp"
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
|
struct IOBitUnset {
|
||||||
|
size_t pos;
|
||||||
|
|
||||||
|
constexpr IOBitUnset(size_t bit_pos) : pos(bit_pos) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct IOBitSet {
|
||||||
|
size_t pos;
|
||||||
|
|
||||||
|
constexpr IOBitSet(size_t bit_pos) : pos(bit_pos) {
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr IOBitUnset operator!() const {
|
||||||
|
return IOBitUnset(this->pos);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct NormalValue {
|
struct NormalValue {
|
||||||
typedef T Value;
|
typedef T Value;
|
||||||
|
@ -26,6 +44,24 @@ namespace JabyEngine {
|
||||||
name##_io_base(type value) : raw_value(value) {} \
|
name##_io_base(type value) : raw_value(value) {} \
|
||||||
__VA_ARGS__ \
|
__VA_ARGS__ \
|
||||||
\
|
\
|
||||||
|
void set(IOBitSet bit) { \
|
||||||
|
this->raw_value = bit::set(this->raw_value, bit.pos); \
|
||||||
|
} \
|
||||||
|
void set(IOBitUnset bit) { \
|
||||||
|
this->raw_value = bit::clear(this->raw_value, bit.pos); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
\
|
||||||
|
void clear(IOBitSet bit) { \
|
||||||
|
this->raw_value = bit::clear(this->raw_value, bit.pos); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
\
|
||||||
|
bool is_set(IOBitSet bit) const { \
|
||||||
|
return bit::is_set(this->raw_value, bit.pos);\
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
\
|
||||||
void operator=(type value) { \
|
void operator=(type value) { \
|
||||||
this->raw_value = value; \
|
this->raw_value = value; \
|
||||||
} \
|
} \
|
||||||
|
|
Loading…
Reference in New Issue