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:
@@ -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. */
|
||||
@@ -47,27 +47,6 @@ AnalogInput::AnalogInput(int channel) {
|
||||
|
||||
AnalogInput::~AnalogInput() { HAL_FreeAnalogInputPort(m_port); }
|
||||
|
||||
AnalogInput::AnalogInput(AnalogInput&& rhs)
|
||||
: ErrorBase(std::move(rhs)),
|
||||
SendableBase(std::move(rhs)),
|
||||
PIDSource(std::move(rhs)),
|
||||
m_channel(std::move(rhs.m_channel)),
|
||||
m_accumulatorOffset(std::move(rhs.m_accumulatorOffset)) {
|
||||
std::swap(m_port, rhs.m_port);
|
||||
}
|
||||
|
||||
AnalogInput& AnalogInput::operator=(AnalogInput&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
SendableBase::operator=(std::move(rhs));
|
||||
PIDSource::operator=(std::move(rhs));
|
||||
|
||||
m_channel = std::move(rhs.m_channel);
|
||||
std::swap(m_port, rhs.m_port);
|
||||
m_accumulatorOffset = std::move(rhs.m_accumulatorOffset);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
int AnalogInput::GetValue() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
|
||||
Reference in New Issue
Block a user