Make IOPort constexpr

This commit is contained in:
Jaby 2023-03-18 15:02:21 +01:00
parent 1e8997dbca
commit 5a39a9a896
1 changed files with 14 additions and 7 deletions

View File

@ -60,25 +60,31 @@ namespace JabyEngine {
#define __declare_io_type(name, type, ...) \ #define __declare_io_type(name, type, ...) \
template<template<typename> typename T> \ template<template<typename> typename T> \
struct name##_io_base { \ struct name##_io_base { \
T<type>::Value raw_value; \ T<type>::Value raw_value = 0; \
\ \
name##_io_base(type value) : raw_value(value) {} \ constexpr name##_io_base() = default; \
\
constexpr name##_io_base(type value) : raw_value(value) {} \
__VA_ARGS__ \ __VA_ARGS__ \
\ \
void set(IOBitSet bit) { \ constexpr name##_io_base& set(IOBitSet bit) { \
this->raw_value = bit::set(this->raw_value, bit.pos); \ this->raw_value = bit::set(this->raw_value, bit.pos); \
return *this; \
} \ } \
\ \
void set(IOBitUnset bit) { \ constexpr name##_io_base& set(IOBitUnset bit) { \
this->raw_value = bit::clear(this->raw_value, bit.pos); \ this->raw_value = bit::clear(this->raw_value, bit.pos); \
return *this; \
} \ } \
\ \
void set(IOValueSet bits, type value) { \ constexpr name##_io_base& set(IOValueSet bits, type value) { \
this->raw_value = bit::value::set_normalized(this->raw_value, value, bits.pos, bits.length); \ this->raw_value = bit::value::set_normalized(this->raw_value, value, bits.pos, bits.length); \
return *this; \
} \ } \
\ \
void set(const IOValueSet::IOValueSetPair<type>& value) { \ constexpr name##_io_base& set(const IOValueSet::IOValueSetPair<type>& value) { \
this->set(value.first, value.second); \ this->set(value.first, value.second); \
return *this; \
} \ } \
\ \
type get(IOValueSet bits) const { \ type get(IOValueSet bits) const { \
@ -86,8 +92,9 @@ namespace JabyEngine {
} \ } \
\ \
\ \
void clear(IOBitSet bit) { \ constexpr name##_io_base& clear(IOBitSet bit) { \
this->raw_value = bit::clear(this->raw_value, bit.pos); \ this->raw_value = bit::clear(this->raw_value, bit.pos); \
return *this; \
} \ } \
\ \
\ \