mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-12-29 15:41:18 +01:00
Allowed concatenation with other RegisterValue, made them all constexpr
This commit is contained in:
@@ -47,11 +47,14 @@ void init_bit(py::module &m) {
|
||||
.def("value", &RegisterValue::value)
|
||||
.def(py::self == py::self)
|
||||
.def(py::self != py::self)
|
||||
.def("__or__", [](const RegisterValue& v, uint32_t rhs) {
|
||||
return v | rhs;
|
||||
.def("__or__", [](const RegisterValue &lhs, const RegisterValue &rhs) {
|
||||
return lhs | rhs;
|
||||
})
|
||||
.def("__ior__", [](RegisterValue &v, uint32_t rhs) -> RegisterValue& {
|
||||
v |= rhs;
|
||||
return v;
|
||||
.def("__or__", [](const RegisterValue& lhs, uint32_t rhs) {
|
||||
return lhs | rhs;
|
||||
})
|
||||
.def("__ior__", [](RegisterValue &lhs, uint32_t rhs) -> RegisterValue& {
|
||||
lhs |= rhs;
|
||||
return lhs;
|
||||
}, py::return_value_policy::reference_internal);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class RegisterAddress {
|
||||
constexpr explicit RegisterAddress(uint32_t value) : value_(value) {}
|
||||
explicit RegisterAddress(const std::string &value);
|
||||
std::string str() const;
|
||||
uint32_t value() const noexcept { return value_; }
|
||||
constexpr uint32_t value() const noexcept { return value_; }
|
||||
|
||||
constexpr bool operator==(const RegisterAddress &other) const {
|
||||
return (value_ == other.value_);
|
||||
@@ -49,8 +49,8 @@ class BitAddress {
|
||||
BitAddress(RegisterAddress address, uint32_t bitPosition);
|
||||
BitAddress(const std::string &address, const std::string &bitPosition);
|
||||
std::string str() const;
|
||||
RegisterAddress address() const noexcept { return addr_; }
|
||||
uint32_t bitPosition() const noexcept { return bitPos_; }
|
||||
constexpr RegisterAddress address() const noexcept { return addr_; }
|
||||
constexpr uint32_t bitPosition() const noexcept { return bitPos_; }
|
||||
|
||||
constexpr bool operator==(const BitAddress &other) const {
|
||||
return (addr_ == other.addr_ && bitPos_ == other.bitPos_);
|
||||
@@ -70,14 +70,25 @@ class RegisterValue {
|
||||
explicit RegisterValue(const std::string &value);
|
||||
|
||||
std::string str() const;
|
||||
uint32_t value() const noexcept { return value_; }
|
||||
constexpr uint32_t value() const noexcept { return value_; }
|
||||
|
||||
RegisterValue &operator|=(uint32_t rhs) noexcept {
|
||||
constexpr RegisterValue &operator|=(const RegisterValue &rhs) noexcept {
|
||||
value_ |= rhs.value();
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr RegisterValue operator|(const RegisterValue &rhs) const noexcept {
|
||||
RegisterValue tmp(*this);
|
||||
tmp |= rhs;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
constexpr RegisterValue &operator|=(uint32_t rhs) noexcept {
|
||||
value_ |= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
RegisterValue operator|(uint32_t rhs) const noexcept {
|
||||
constexpr RegisterValue operator|(uint32_t rhs) const noexcept {
|
||||
RegisterValue tmp(*this);
|
||||
tmp |= rhs;
|
||||
return tmp;
|
||||
|
||||
@@ -84,6 +84,7 @@ TEST_CASE("Convert RegisterValue using classes ", "[support][.bit_utils]") {
|
||||
CHECK(reg1.str() == vec_ans[i]);
|
||||
CHECK((reg0 | 0xffffffffu) == RegisterValue(0xffffffffu));
|
||||
CHECK((reg0 | 0x0) == reg0);
|
||||
CHECK((reg0 | reg1) == reg0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user