Refactor HAL handle move construction/assignment (#1845)

A templated hal::Handle class is used to wrap handles to make them move-only.
This eliminates a lot of boilerplate move constructor/assignment code
in the main WPILib classes.  HAL_SPIPort and HAL_I2CPort are also wrapped.

The wrapper class does not implement destruction.  This would require the
wrapper class to be handle-specific (rather than generic) and would result
in more code added than it removed, plus would add header dependencies on
more HAL headers.  In addition, some HAL handle release functions are more
complex (e.g. have return values) and can't be easily mapped to a destructor.
This commit is contained in:
Peter Johnson
2019-08-25 18:42:00 -07:00
committed by GitHub
parent 558c383088
commit a0be07c370
41 changed files with 151 additions and 409 deletions

View File

@@ -21,26 +21,6 @@ InterruptableSensorBase::~InterruptableSensorBase() {
// Ignore status, as an invalid handle just needs to be ignored.
}
InterruptableSensorBase::InterruptableSensorBase(InterruptableSensorBase&& rhs)
: ErrorBase(std::move(rhs)),
m_interrupt(rhs.m_interrupt),
m_interruptHandler{std::move(rhs.m_interruptHandler)} {
rhs.m_interrupt = HAL_kInvalidHandle;
rhs.m_interruptHandler = nullptr;
}
InterruptableSensorBase& InterruptableSensorBase::operator=(
InterruptableSensorBase&& rhs) {
ErrorBase::operator=(std::move(rhs));
m_interrupt = rhs.m_interrupt;
m_interruptHandler = std::move(rhs.m_interruptHandler);
rhs.m_interrupt = HAL_kInvalidHandle;
rhs.m_interruptHandler = nullptr;
return *this;
}
void InterruptableSensorBase::RequestInterrupts(
HAL_InterruptHandlerFunction handler, void* param) {
if (StatusIsFatal()) return;