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

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -52,20 +52,6 @@ Solenoid::Solenoid(int moduleNumber, int channel)
Solenoid::~Solenoid() { HAL_FreeSolenoidPort(m_solenoidHandle); }
Solenoid::Solenoid(Solenoid&& rhs)
: SolenoidBase(std::move(rhs)), m_channel(std::move(rhs.m_channel)) {
std::swap(m_solenoidHandle, rhs.m_solenoidHandle);
}
Solenoid& Solenoid::operator=(Solenoid&& rhs) {
SolenoidBase::operator=(std::move(rhs));
std::swap(m_solenoidHandle, rhs.m_solenoidHandle);
m_channel = std::move(rhs.m_channel);
return *this;
}
void Solenoid::Set(bool on) {
if (StatusIsFatal()) return;
int32_t status = 0;