mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
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:
@@ -162,27 +162,6 @@ SPI::SPI(Port port) : m_port(static_cast<HAL_SPIPort>(port)) {
|
||||
|
||||
SPI::~SPI() { HAL_CloseSPI(m_port); }
|
||||
|
||||
SPI::SPI(SPI&& rhs)
|
||||
: ErrorBase(std::move(rhs)),
|
||||
m_msbFirst(std::move(rhs.m_msbFirst)),
|
||||
m_sampleOnTrailing(std::move(rhs.m_sampleOnTrailing)),
|
||||
m_clockIdleHigh(std::move(rhs.m_clockIdleHigh)),
|
||||
m_accum(std::move(rhs.m_accum)) {
|
||||
std::swap(m_port, rhs.m_port);
|
||||
}
|
||||
|
||||
SPI& SPI::operator=(SPI&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
|
||||
std::swap(m_port, rhs.m_port);
|
||||
m_msbFirst = std::move(rhs.m_msbFirst);
|
||||
m_sampleOnTrailing = std::move(rhs.m_sampleOnTrailing);
|
||||
m_clockIdleHigh = std::move(rhs.m_clockIdleHigh);
|
||||
m_accum = std::move(rhs.m_accum);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void SPI::SetClockRate(int hz) { HAL_SetSPISpeed(m_port, hz); }
|
||||
|
||||
void SPI::SetMSBFirst() {
|
||||
|
||||
Reference in New Issue
Block a user