diff options
author | Chris Robinson <[email protected]> | 2022-02-14 00:20:45 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2022-02-14 00:20:45 -0800 |
commit | c156e30a484eeaa341b42520904cef7b0eefc7c9 (patch) | |
tree | fdab94bf76578f23ef4af48151b8eb9945d45dac /al/eax_fx_slot_index.cpp | |
parent | f915b86dbb8a3d75e37a2813df093694aae0dcbb (diff) |
Derive EaxFxSlotIndex from an optional
Diffstat (limited to 'al/eax_fx_slot_index.cpp')
-rw-r--r-- | al/eax_fx_slot_index.cpp | 104 |
1 files changed, 14 insertions, 90 deletions
diff --git a/al/eax_fx_slot_index.cpp b/al/eax_fx_slot_index.cpp index 484c3499..fe74097d 100644 --- a/al/eax_fx_slot_index.cpp +++ b/al/eax_fx_slot_index.cpp @@ -25,100 +25,38 @@ public: } // namespace -EaxFxSlotIndex::EaxFxSlotIndex( - EaxFxSlotIndexValue index) +void EaxFxSlotIndex::set(EaxFxSlotIndexValue index) { - set(index); -} - -EaxFxSlotIndex::EaxFxSlotIndex( - const EaxFxSlotIndex& rhs) noexcept - : - has_value_{rhs.has_value_}, - value_{rhs.value_} -{ -} - -void EaxFxSlotIndex::operator=( - EaxFxSlotIndexValue index) -{ - set(index); -} - -void EaxFxSlotIndex::operator=( - const GUID& guid) -{ - set(guid); -} - -void EaxFxSlotIndex::operator=( - const EaxFxSlotIndex& rhs) noexcept -{ - has_value_ = rhs.has_value_; - value_ = rhs.value_; -} - -bool EaxFxSlotIndex::has_value() const noexcept -{ - return has_value_; -} - -EaxFxSlotIndexValue EaxFxSlotIndex::get() const -{ - if (!has_value_) - { - throw EaxFxSlotIndexException{"No value."}; - } - - return value_; -} - -void EaxFxSlotIndex::reset() noexcept -{ - has_value_ = false; -} - -void EaxFxSlotIndex::set( - EaxFxSlotIndexValue index) -{ - if (index >= static_cast<EaxFxSlotIndexValue>(EAX_MAX_FXSLOTS)) - { + if(index >= EaxFxSlotIndexValue{EAX_MAX_FXSLOTS}) fail("Index out of range."); - } - has_value_ = true; - value_ = index; + emplace(index); } -void EaxFxSlotIndex::set( - const GUID& guid) +void EaxFxSlotIndex::set(const GUID &guid) { if (false) { } else if (guid == EAX_NULL_GUID) { - has_value_ = false; + reset(); } else if (guid == EAXPROPERTYID_EAX40_FXSlot0 || guid == EAXPROPERTYID_EAX50_FXSlot0) { - has_value_ = true; - value_ = 0; + emplace(0u); } else if (guid == EAXPROPERTYID_EAX40_FXSlot1 || guid == EAXPROPERTYID_EAX50_FXSlot1) { - has_value_ = true; - value_ = 1; + emplace(1u); } else if (guid == EAXPROPERTYID_EAX40_FXSlot2 || guid == EAXPROPERTYID_EAX50_FXSlot2) { - has_value_ = true; - value_ = 2; + emplace(2u); } else if (guid == EAXPROPERTYID_EAX40_FXSlot3 || guid == EAXPROPERTYID_EAX50_FXSlot3) { - has_value_ = true; - value_ = 3; + emplace(3u); } else { @@ -126,14 +64,8 @@ void EaxFxSlotIndex::set( } } -EaxFxSlotIndex::operator EaxFxSlotIndexValue() const -{ - return get(); -} - [[noreturn]] -void EaxFxSlotIndex::fail( - const char* message) +void EaxFxSlotIndex::fail(const char* message) { throw EaxFxSlotIndexException{message}; } @@ -143,19 +75,11 @@ bool operator==( const EaxFxSlotIndex& lhs, const EaxFxSlotIndex& rhs) noexcept { - if (lhs.has_value() != rhs.has_value()) - { + if(lhs.has_value() != rhs.has_value()) return false; - } - - if (lhs.has_value()) - { - return lhs.get() == rhs.get(); - } - else - { - return true; - } + if(lhs.has_value()) + return *lhs == *rhs; + return true; } bool operator!=( |