From a0be07c370674487baef2a6ee518cc4455e4eed2 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 25 Aug 2019 18:42:00 -0700 Subject: [PATCH] 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. --- hal/src/main/native/include/hal/I2CTypes.h | 13 ++++++- hal/src/main/native/include/hal/SPITypes.h | 14 +++++++- hal/src/main/native/include/hal/Types.h | 35 ++++++++++++++++++- wpilibc/src/main/native/cpp/AnalogGyro.cpp | 16 +-------- wpilibc/src/main/native/cpp/AnalogInput.cpp | 23 +----------- wpilibc/src/main/native/cpp/AnalogOutput.cpp | 19 +--------- wpilibc/src/main/native/cpp/AnalogTrigger.cpp | 8 ++--- .../main/native/cpp/AnalogTriggerOutput.cpp | 19 +++------- wpilibc/src/main/native/cpp/CAN.cpp | 14 +------- wpilibc/src/main/native/cpp/Counter.cpp | 26 +------------- wpilibc/src/main/native/cpp/DigitalInput.cpp | 23 +----------- wpilibc/src/main/native/cpp/DigitalOutput.cpp | 21 +---------- .../src/main/native/cpp/DoubleSolenoid.cpp | 25 +------------ wpilibc/src/main/native/cpp/Encoder.cpp | 27 +------------- wpilibc/src/main/native/cpp/I2C.cpp | 17 +-------- .../native/cpp/InterruptableSensorBase.cpp | 20 ----------- wpilibc/src/main/native/cpp/PWM.cpp | 19 +--------- wpilibc/src/main/native/cpp/Relay.cpp | 23 +----------- wpilibc/src/main/native/cpp/SPI.cpp | 21 ----------- wpilibc/src/main/native/cpp/Solenoid.cpp | 16 +-------- wpilibc/src/main/native/cpp/TimedRobot.cpp | 16 --------- .../src/main/native/include/frc/AnalogGyro.h | 4 +-- .../src/main/native/include/frc/AnalogInput.h | 8 ++--- .../main/native/include/frc/AnalogOutput.h | 8 ++--- .../main/native/include/frc/AnalogTrigger.h | 4 +-- .../native/include/frc/AnalogTriggerOutput.h | 11 ++---- wpilibc/src/main/native/include/frc/CAN.h | 8 ++--- .../src/main/native/include/frc/Compressor.h | 4 +-- wpilibc/src/main/native/include/frc/Counter.h | 8 ++--- .../main/native/include/frc/DigitalInput.h | 8 ++--- .../main/native/include/frc/DigitalOutput.h | 10 +++--- .../main/native/include/frc/DoubleSolenoid.h | 10 +++--- wpilibc/src/main/native/include/frc/Encoder.h | 8 ++--- wpilibc/src/main/native/include/frc/I2C.h | 6 ++-- .../include/frc/InterruptableSensorBase.h | 6 ++-- wpilibc/src/main/native/include/frc/PWM.h | 8 ++--- .../include/frc/PowerDistributionPanel.h | 4 +-- wpilibc/src/main/native/include/frc/Relay.h | 10 +++--- wpilibc/src/main/native/include/frc/SPI.h | 6 ++-- .../src/main/native/include/frc/Solenoid.h | 8 ++--- .../src/main/native/include/frc/TimedRobot.h | 6 ++-- 41 files changed, 151 insertions(+), 409 deletions(-) diff --git a/hal/src/main/native/include/hal/I2CTypes.h b/hal/src/main/native/include/hal/I2CTypes.h index d0b269fd59..b5e8235732 100644 --- a/hal/src/main/native/include/hal/I2CTypes.h +++ b/hal/src/main/native/include/hal/I2CTypes.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2018-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. */ @@ -21,4 +21,15 @@ HAL_ENUM(HAL_I2CPort) { HAL_I2C_kInvalid = -1, HAL_I2C_kOnboard, HAL_I2C_kMXP }; // clang-format on +#ifdef __cplusplus +namespace hal { + +/** + * A move-only C++ wrapper around HAL_I2CPort. + * Does not ensure destruction. + */ +using I2CPort = Handle; + +} // namespace hal +#endif /** @} */ diff --git a/hal/src/main/native/include/hal/SPITypes.h b/hal/src/main/native/include/hal/SPITypes.h index 907623c94a..170bd271ab 100644 --- a/hal/src/main/native/include/hal/SPITypes.h +++ b/hal/src/main/native/include/hal/SPITypes.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2018-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. */ @@ -27,4 +27,16 @@ HAL_ENUM(HAL_SPIPort) { HAL_SPI_kMXP }; // clang-format on + +#ifdef __cplusplus +namespace hal { + +/** + * A move-only C++ wrapper around HAL_SPIPort. + * Does not ensure destruction. + */ +using SPIPort = Handle; + +} // namespace hal +#endif /** @} */ diff --git a/hal/src/main/native/include/hal/Types.h b/hal/src/main/native/include/hal/Types.h index 6180439d98..45bb540964 100644 --- a/hal/src/main/native/include/hal/Types.h +++ b/hal/src/main/native/include/hal/Types.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2016-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. */ @@ -62,4 +62,37 @@ typedef int32_t HAL_Bool; typedef int32_t name; \ enum name #endif + +#ifdef __cplusplus +namespace hal { + +/** + * A move-only C++ wrapper around a HAL handle. + * Does not ensure destruction. + */ +template +class Handle { + public: + Handle() = default; + /*implicit*/ Handle(CType val) : m_handle(val) {} // NOLINT(runtime/explicit) + + Handle(const Handle&) = delete; + Handle& operator=(const Handle&) = delete; + + Handle(Handle&& rhs) : m_handle(rhs.m_handle) { rhs.m_handle = CInvalid; } + + Handle& operator=(Handle&& rhs) { + m_handle = rhs.m_handle; + rhs.m_handle = CInvalid; + return *this; + } + + operator CType() const { return m_handle; } + + private: + CType m_handle = CInvalid; +}; + +} // namespace hal +#endif /** @} */ diff --git a/wpilibc/src/main/native/cpp/AnalogGyro.cpp b/wpilibc/src/main/native/cpp/AnalogGyro.cpp index 5efe7b3d7f..1c356b3cfa 100644 --- a/wpilibc/src/main/native/cpp/AnalogGyro.cpp +++ b/wpilibc/src/main/native/cpp/AnalogGyro.cpp @@ -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. */ @@ -65,20 +65,6 @@ AnalogGyro::AnalogGyro(std::shared_ptr channel, int center, AnalogGyro::~AnalogGyro() { HAL_FreeAnalogGyro(m_gyroHandle); } -AnalogGyro::AnalogGyro(AnalogGyro&& rhs) - : GyroBase(std::move(rhs)), m_analog(std::move(rhs.m_analog)) { - std::swap(m_gyroHandle, rhs.m_gyroHandle); -} - -AnalogGyro& AnalogGyro::operator=(AnalogGyro&& rhs) { - GyroBase::operator=(std::move(rhs)); - - m_analog = std::move(rhs.m_analog); - std::swap(m_gyroHandle, rhs.m_gyroHandle); - - return *this; -} - double AnalogGyro::GetAngle() const { if (StatusIsFatal()) return 0.0; int32_t status = 0; diff --git a/wpilibc/src/main/native/cpp/AnalogInput.cpp b/wpilibc/src/main/native/cpp/AnalogInput.cpp index 52a55d38fa..0945e5fa70 100644 --- a/wpilibc/src/main/native/cpp/AnalogInput.cpp +++ b/wpilibc/src/main/native/cpp/AnalogInput.cpp @@ -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; diff --git a/wpilibc/src/main/native/cpp/AnalogOutput.cpp b/wpilibc/src/main/native/cpp/AnalogOutput.cpp index b18af5b369..5988d2084a 100644 --- a/wpilibc/src/main/native/cpp/AnalogOutput.cpp +++ b/wpilibc/src/main/native/cpp/AnalogOutput.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2014-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,23 +47,6 @@ AnalogOutput::AnalogOutput(int channel) { AnalogOutput::~AnalogOutput() { HAL_FreeAnalogOutputPort(m_port); } -AnalogOutput::AnalogOutput(AnalogOutput&& rhs) - : ErrorBase(std::move(rhs)), - SendableBase(std::move(rhs)), - m_channel(std::move(rhs.m_channel)) { - std::swap(m_port, rhs.m_port); -} - -AnalogOutput& AnalogOutput::operator=(AnalogOutput&& rhs) { - ErrorBase::operator=(std::move(rhs)); - SendableBase::operator=(std::move(rhs)); - - m_channel = std::move(rhs.m_channel); - std::swap(m_port, rhs.m_port); - - return *this; -} - void AnalogOutput::SetVoltage(double voltage) { int32_t status = 0; HAL_SetAnalogOutput(m_port, voltage, &status); diff --git a/wpilibc/src/main/native/cpp/AnalogTrigger.cpp b/wpilibc/src/main/native/cpp/AnalogTrigger.cpp index aeb58dfbee..65a975887a 100644 --- a/wpilibc/src/main/native/cpp/AnalogTrigger.cpp +++ b/wpilibc/src/main/native/cpp/AnalogTrigger.cpp @@ -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. */ @@ -51,8 +51,8 @@ AnalogTrigger::~AnalogTrigger() { AnalogTrigger::AnalogTrigger(AnalogTrigger&& rhs) : ErrorBase(std::move(rhs)), SendableBase(std::move(rhs)), - m_index(std::move(rhs.m_index)) { - std::swap(m_trigger, rhs.m_trigger); + m_index(std::move(rhs.m_index)), + m_trigger(std::move(rhs.m_trigger)) { std::swap(m_analogInput, rhs.m_analogInput); std::swap(m_ownsAnalog, rhs.m_ownsAnalog); } @@ -62,7 +62,7 @@ AnalogTrigger& AnalogTrigger::operator=(AnalogTrigger&& rhs) { SendableBase::operator=(std::move(rhs)); m_index = std::move(rhs.m_index); - std::swap(m_trigger, rhs.m_trigger); + m_trigger = std::move(rhs.m_trigger); std::swap(m_analogInput, rhs.m_analogInput); std::swap(m_ownsAnalog, rhs.m_ownsAnalog); diff --git a/wpilibc/src/main/native/cpp/AnalogTriggerOutput.cpp b/wpilibc/src/main/native/cpp/AnalogTriggerOutput.cpp index b2a8cd5634..c2c7265402 100644 --- a/wpilibc/src/main/native/cpp/AnalogTriggerOutput.cpp +++ b/wpilibc/src/main/native/cpp/AnalogTriggerOutput.cpp @@ -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. */ @@ -14,26 +14,17 @@ using namespace frc; -AnalogTriggerOutput::~AnalogTriggerOutput() { - if (m_interrupt != HAL_kInvalidHandle) { - int32_t status = 0; - HAL_CleanInterrupts(m_interrupt, &status); - // ignore status, as an invalid handle just needs to be ignored. - m_interrupt = HAL_kInvalidHandle; - } -} - bool AnalogTriggerOutput::Get() const { int32_t status = 0; bool result = HAL_GetAnalogTriggerOutput( - m_trigger.m_trigger, static_cast(m_outputType), + m_trigger->m_trigger, static_cast(m_outputType), &status); wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); return result; } HAL_Handle AnalogTriggerOutput::GetPortHandleForRouting() const { - return m_trigger.m_trigger; + return m_trigger->m_trigger; } AnalogTriggerType AnalogTriggerOutput::GetAnalogTriggerTypeForRouting() const { @@ -42,13 +33,13 @@ AnalogTriggerType AnalogTriggerOutput::GetAnalogTriggerTypeForRouting() const { bool AnalogTriggerOutput::IsAnalogTrigger() const { return true; } -int AnalogTriggerOutput::GetChannel() const { return m_trigger.m_index; } +int AnalogTriggerOutput::GetChannel() const { return m_trigger->m_index; } void AnalogTriggerOutput::InitSendable(SendableBuilder&) {} AnalogTriggerOutput::AnalogTriggerOutput(const AnalogTrigger& trigger, AnalogTriggerType outputType) - : m_trigger(trigger), m_outputType(outputType) { + : m_trigger(&trigger), m_outputType(outputType) { HAL_Report(HALUsageReporting::kResourceType_AnalogTriggerOutput, trigger.GetIndex(), static_cast(outputType)); } diff --git a/wpilibc/src/main/native/cpp/CAN.cpp b/wpilibc/src/main/native/cpp/CAN.cpp index f01eb3f687..711645fd6d 100644 --- a/wpilibc/src/main/native/cpp/CAN.cpp +++ b/wpilibc/src/main/native/cpp/CAN.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2018-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,18 +52,6 @@ CAN::~CAN() { } } -CAN::CAN(CAN&& rhs) : ErrorBase(std::move(rhs)) { - std::swap(m_handle, rhs.m_handle); -} - -CAN& CAN::operator=(CAN&& rhs) { - ErrorBase::operator=(std::move(rhs)); - - std::swap(m_handle, rhs.m_handle); - - return *this; -} - void CAN::WritePacket(const uint8_t* data, int length, int apiId) { int32_t status = 0; HAL_WriteCANPacket(m_handle, data, length, apiId, &status); diff --git a/wpilibc/src/main/native/cpp/Counter.cpp b/wpilibc/src/main/native/cpp/Counter.cpp index c97bbc5a05..e7bf035090 100644 --- a/wpilibc/src/main/native/cpp/Counter.cpp +++ b/wpilibc/src/main/native/cpp/Counter.cpp @@ -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. */ @@ -90,30 +90,6 @@ Counter::~Counter() { int32_t status = 0; HAL_FreeCounter(m_counter, &status); wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); - m_counter = HAL_kInvalidHandle; -} - -Counter::Counter(Counter&& rhs) - : ErrorBase(std::move(rhs)), - SendableBase(std::move(rhs)), - CounterBase(std::move(rhs)), - m_upSource(std::move(rhs.m_upSource)), - m_downSource(std::move(rhs.m_downSource)), - m_index(std::move(rhs.m_index)) { - std::swap(m_counter, rhs.m_counter); -} - -Counter& Counter::operator=(Counter&& rhs) { - ErrorBase::operator=(std::move(rhs)); - SendableBase::operator=(std::move(rhs)); - CounterBase::operator=(std::move(rhs)); - - m_upSource = std::move(rhs.m_upSource); - m_downSource = std::move(rhs.m_downSource); - std::swap(m_counter, rhs.m_counter); - m_index = std::move(rhs.m_index); - - return *this; } void Counter::SetUpSource(int channel) { diff --git a/wpilibc/src/main/native/cpp/DigitalInput.cpp b/wpilibc/src/main/native/cpp/DigitalInput.cpp index 273e9b6220..248bdd5232 100644 --- a/wpilibc/src/main/native/cpp/DigitalInput.cpp +++ b/wpilibc/src/main/native/cpp/DigitalInput.cpp @@ -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. */ @@ -45,30 +45,9 @@ DigitalInput::DigitalInput(int channel) { DigitalInput::~DigitalInput() { if (StatusIsFatal()) return; - if (m_interrupt != HAL_kInvalidHandle) { - int32_t status = 0; - HAL_CleanInterrupts(m_interrupt, &status); - // Ignore status, as an invalid handle just needs to be ignored. - m_interrupt = HAL_kInvalidHandle; - } - HAL_FreeDIOPort(m_handle); } -DigitalInput::DigitalInput(DigitalInput&& rhs) - : DigitalSource(std::move(rhs)), m_channel(std::move(rhs.m_channel)) { - std::swap(m_handle, rhs.m_handle); -} - -DigitalInput& DigitalInput::operator=(DigitalInput&& rhs) { - DigitalSource::operator=(std::move(rhs)); - - m_channel = std::move(rhs.m_channel); - std::swap(m_handle, rhs.m_handle); - - return *this; -} - bool DigitalInput::Get() const { if (StatusIsFatal()) return false; int32_t status = 0; diff --git a/wpilibc/src/main/native/cpp/DigitalOutput.cpp b/wpilibc/src/main/native/cpp/DigitalOutput.cpp index b05c6b101e..f2224c7b7f 100644 --- a/wpilibc/src/main/native/cpp/DigitalOutput.cpp +++ b/wpilibc/src/main/native/cpp/DigitalOutput.cpp @@ -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,25 +52,6 @@ DigitalOutput::~DigitalOutput() { HAL_FreeDIOPort(m_handle); } -DigitalOutput::DigitalOutput(DigitalOutput&& rhs) - : ErrorBase(std::move(rhs)), - SendableBase(std::move(rhs)), - m_channel(std::move(rhs.m_channel)), - m_pwmGenerator(std::move(rhs.m_pwmGenerator)) { - std::swap(m_handle, rhs.m_handle); -} - -DigitalOutput& DigitalOutput::operator=(DigitalOutput&& rhs) { - ErrorBase::operator=(std::move(rhs)); - SendableBase::operator=(std::move(rhs)); - - m_channel = std::move(rhs.m_channel); - std::swap(m_handle, rhs.m_handle); - m_pwmGenerator = std::move(rhs.m_pwmGenerator); - - return *this; -} - void DigitalOutput::Set(bool value) { if (StatusIsFatal()) return; diff --git a/wpilibc/src/main/native/cpp/DoubleSolenoid.cpp b/wpilibc/src/main/native/cpp/DoubleSolenoid.cpp index 86678aac59..0f0a6941d2 100644 --- a/wpilibc/src/main/native/cpp/DoubleSolenoid.cpp +++ b/wpilibc/src/main/native/cpp/DoubleSolenoid.cpp @@ -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. */ @@ -83,29 +83,6 @@ DoubleSolenoid::~DoubleSolenoid() { HAL_FreeSolenoidPort(m_reverseHandle); } -DoubleSolenoid::DoubleSolenoid(DoubleSolenoid&& rhs) - : SolenoidBase(std::move(rhs)), - m_forwardChannel(std::move(rhs.m_forwardChannel)), - m_reverseChannel(std::move(rhs.m_reverseChannel)), - m_forwardMask(std::move(rhs.m_forwardMask)), - m_reverseMask(std::move(rhs.m_reverseMask)) { - std::swap(m_forwardHandle, rhs.m_forwardHandle); - std::swap(m_reverseHandle, rhs.m_reverseHandle); -} - -DoubleSolenoid& DoubleSolenoid::operator=(DoubleSolenoid&& rhs) { - SolenoidBase::operator=(std::move(rhs)); - - m_forwardChannel = std::move(rhs.m_forwardChannel); - m_reverseChannel = std::move(rhs.m_reverseChannel); - m_forwardMask = std::move(rhs.m_forwardMask); - m_reverseMask = std::move(rhs.m_reverseMask); - std::swap(m_forwardHandle, rhs.m_forwardHandle); - std::swap(m_reverseHandle, rhs.m_reverseHandle); - - return *this; -} - void DoubleSolenoid::Set(Value value) { if (StatusIsFatal()) return; diff --git a/wpilibc/src/main/native/cpp/Encoder.cpp b/wpilibc/src/main/native/cpp/Encoder.cpp index 77e7a2a99e..1c4d02f530 100644 --- a/wpilibc/src/main/native/cpp/Encoder.cpp +++ b/wpilibc/src/main/native/cpp/Encoder.cpp @@ -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. */ @@ -61,31 +61,6 @@ Encoder::~Encoder() { wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); } -Encoder::Encoder(Encoder&& rhs) - : ErrorBase(std::move(rhs)), - SendableBase(std::move(rhs)), - CounterBase(std::move(rhs)), - PIDSource(std::move(rhs)), - m_aSource(std::move(rhs.m_aSource)), - m_bSource(std::move(rhs.m_bSource)), - m_indexSource(std::move(rhs.m_indexSource)) { - std::swap(m_encoder, rhs.m_encoder); -} - -Encoder& Encoder::operator=(Encoder&& rhs) { - ErrorBase::operator=(std::move(rhs)); - SendableBase::operator=(std::move(rhs)); - CounterBase::operator=(std::move(rhs)); - PIDSource::operator=(std::move(rhs)); - - m_aSource = std::move(rhs.m_aSource); - m_bSource = std::move(rhs.m_bSource); - m_indexSource = std::move(rhs.m_indexSource); - std::swap(m_encoder, rhs.m_encoder); - - return *this; -} - int Encoder::Get() const { if (StatusIsFatal()) return 0; int32_t status = 0; diff --git a/wpilibc/src/main/native/cpp/I2C.cpp b/wpilibc/src/main/native/cpp/I2C.cpp index 4b18f73e71..44b71afc54 100644 --- a/wpilibc/src/main/native/cpp/I2C.cpp +++ b/wpilibc/src/main/native/cpp/I2C.cpp @@ -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. */ @@ -27,21 +27,6 @@ I2C::I2C(Port port, int deviceAddress) I2C::~I2C() { HAL_CloseI2C(m_port); } -I2C::I2C(I2C&& rhs) - : ErrorBase(std::move(rhs)), - m_deviceAddress(std::move(rhs.m_deviceAddress)) { - std::swap(m_port, rhs.m_port); -} - -I2C& I2C::operator=(I2C&& rhs) { - ErrorBase::operator=(std::move(rhs)); - - std::swap(m_port, rhs.m_port); - m_deviceAddress = std::move(rhs.m_deviceAddress); - - return *this; -} - bool I2C::Transaction(uint8_t* dataToSend, int sendSize, uint8_t* dataReceived, int receiveSize) { int32_t status = 0; diff --git a/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp b/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp index 0bc8c33749..36150d47ce 100644 --- a/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp +++ b/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp @@ -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; diff --git a/wpilibc/src/main/native/cpp/PWM.cpp b/wpilibc/src/main/native/cpp/PWM.cpp index 603c94b88b..e0e578e3ef 100644 --- a/wpilibc/src/main/native/cpp/PWM.cpp +++ b/wpilibc/src/main/native/cpp/PWM.cpp @@ -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. */ @@ -61,23 +61,6 @@ PWM::~PWM() { wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); } -PWM::PWM(PWM&& rhs) - : MotorSafety(std::move(rhs)), - SendableBase(std::move(rhs)), - m_channel(std::move(rhs.m_channel)) { - std::swap(m_handle, rhs.m_handle); -} - -PWM& PWM::operator=(PWM&& rhs) { - ErrorBase::operator=(std::move(rhs)); - SendableBase::operator=(std::move(rhs)); - - m_channel = std::move(rhs.m_channel); - std::swap(m_handle, rhs.m_handle); - - return *this; -} - void PWM::StopMotor() { SetDisabled(); } void PWM::GetDescription(wpi::raw_ostream& desc) const { diff --git a/wpilibc/src/main/native/cpp/Relay.cpp b/wpilibc/src/main/native/cpp/Relay.cpp index 9128d20250..970a5e150a 100644 --- a/wpilibc/src/main/native/cpp/Relay.cpp +++ b/wpilibc/src/main/native/cpp/Relay.cpp @@ -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. */ @@ -88,27 +88,6 @@ Relay::~Relay() { if (m_reverseHandle != HAL_kInvalidHandle) HAL_FreeRelayPort(m_reverseHandle); } -Relay::Relay(Relay&& rhs) - : MotorSafety(std::move(rhs)), - SendableBase(std::move(rhs)), - m_channel(std::move(rhs.m_channel)), - m_direction(std::move(rhs.m_direction)) { - std::swap(m_forwardHandle, rhs.m_forwardHandle); - std::swap(m_reverseHandle, rhs.m_reverseHandle); -} - -Relay& Relay::operator=(Relay&& rhs) { - MotorSafety::operator=(std::move(rhs)); - SendableBase::operator=(std::move(rhs)); - - m_channel = std::move(rhs.m_channel); - m_direction = std::move(rhs.m_direction); - std::swap(m_forwardHandle, rhs.m_forwardHandle); - std::swap(m_reverseHandle, rhs.m_reverseHandle); - - return *this; -} - void Relay::Set(Relay::Value value) { if (StatusIsFatal()) return; diff --git a/wpilibc/src/main/native/cpp/SPI.cpp b/wpilibc/src/main/native/cpp/SPI.cpp index 51341b0c67..a884c3b964 100644 --- a/wpilibc/src/main/native/cpp/SPI.cpp +++ b/wpilibc/src/main/native/cpp/SPI.cpp @@ -162,27 +162,6 @@ SPI::SPI(Port port) : m_port(static_cast(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() { diff --git a/wpilibc/src/main/native/cpp/Solenoid.cpp b/wpilibc/src/main/native/cpp/Solenoid.cpp index 3445f5dfa4..7bc2f4e457 100644 --- a/wpilibc/src/main/native/cpp/Solenoid.cpp +++ b/wpilibc/src/main/native/cpp/Solenoid.cpp @@ -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; diff --git a/wpilibc/src/main/native/cpp/TimedRobot.cpp b/wpilibc/src/main/native/cpp/TimedRobot.cpp index fefd1e098b..9d0459c221 100644 --- a/wpilibc/src/main/native/cpp/TimedRobot.cpp +++ b/wpilibc/src/main/native/cpp/TimedRobot.cpp @@ -67,22 +67,6 @@ TimedRobot::~TimedRobot() { HAL_CleanNotifier(m_notifier, &status); } -TimedRobot::TimedRobot(TimedRobot&& rhs) - : IterativeRobotBase(std::move(rhs)), - m_expirationTime(std::move(rhs.m_expirationTime)) { - std::swap(m_notifier, rhs.m_notifier); -} - -TimedRobot& TimedRobot::operator=(TimedRobot&& rhs) { - IterativeRobotBase::operator=(std::move(rhs)); - ErrorBase::operator=(std::move(rhs)); - - std::swap(m_notifier, rhs.m_notifier); - m_expirationTime = std::move(rhs.m_expirationTime); - - return *this; -} - void TimedRobot::UpdateAlarm() { int32_t status = 0; HAL_UpdateNotifierAlarm( diff --git a/wpilibc/src/main/native/include/frc/AnalogGyro.h b/wpilibc/src/main/native/include/frc/AnalogGyro.h index 9e18d89c51..3e7ec7ddd3 100644 --- a/wpilibc/src/main/native/include/frc/AnalogGyro.h +++ b/wpilibc/src/main/native/include/frc/AnalogGyro.h @@ -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. */ @@ -188,7 +188,7 @@ class AnalogGyro : public GyroBase { std::shared_ptr m_analog; private: - HAL_GyroHandle m_gyroHandle = HAL_kInvalidHandle; + hal::Handle m_gyroHandle; }; } // namespace frc diff --git a/wpilibc/src/main/native/include/frc/AnalogInput.h b/wpilibc/src/main/native/include/frc/AnalogInput.h index 97ce2a8b75..fe74b04086 100644 --- a/wpilibc/src/main/native/include/frc/AnalogInput.h +++ b/wpilibc/src/main/native/include/frc/AnalogInput.h @@ -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. */ @@ -48,8 +48,8 @@ class AnalogInput : public ErrorBase, public SendableBase, public PIDSource { ~AnalogInput() override; - AnalogInput(AnalogInput&& rhs); - AnalogInput& operator=(AnalogInput&& rhs); + AnalogInput(AnalogInput&&) = default; + AnalogInput& operator=(AnalogInput&&) = default; /** * Get a sample straight from this channel. @@ -284,7 +284,7 @@ class AnalogInput : public ErrorBase, public SendableBase, public PIDSource { private: int m_channel; - HAL_AnalogInputHandle m_port = HAL_kInvalidHandle; + hal::Handle m_port; int64_t m_accumulatorOffset; }; diff --git a/wpilibc/src/main/native/include/frc/AnalogOutput.h b/wpilibc/src/main/native/include/frc/AnalogOutput.h index 3c7b44e5a9..d42e9461da 100644 --- a/wpilibc/src/main/native/include/frc/AnalogOutput.h +++ b/wpilibc/src/main/native/include/frc/AnalogOutput.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2014-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. */ @@ -30,8 +30,8 @@ class AnalogOutput : public ErrorBase, public SendableBase { ~AnalogOutput() override; - AnalogOutput(AnalogOutput&& rhs); - AnalogOutput& operator=(AnalogOutput&& rhs); + AnalogOutput(AnalogOutput&&) = default; + AnalogOutput& operator=(AnalogOutput&&) = default; /** * Set the value of the analog output. @@ -56,7 +56,7 @@ class AnalogOutput : public ErrorBase, public SendableBase { protected: int m_channel; - HAL_AnalogOutputHandle m_port = HAL_kInvalidHandle; + hal::Handle m_port; }; } // namespace frc diff --git a/wpilibc/src/main/native/include/frc/AnalogTrigger.h b/wpilibc/src/main/native/include/frc/AnalogTrigger.h index beb48fc296..618d3c2730 100644 --- a/wpilibc/src/main/native/include/frc/AnalogTrigger.h +++ b/wpilibc/src/main/native/include/frc/AnalogTrigger.h @@ -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. */ @@ -136,7 +136,7 @@ class AnalogTrigger : public ErrorBase, public SendableBase { private: int m_index; - HAL_AnalogTriggerHandle m_trigger = HAL_kInvalidHandle; + hal::Handle m_trigger; AnalogInput* m_analogInput = nullptr; bool m_ownsAnalog = false; }; diff --git a/wpilibc/src/main/native/include/frc/AnalogTriggerOutput.h b/wpilibc/src/main/native/include/frc/AnalogTriggerOutput.h index fc3d8f252d..931b3449fe 100644 --- a/wpilibc/src/main/native/include/frc/AnalogTriggerOutput.h +++ b/wpilibc/src/main/native/include/frc/AnalogTriggerOutput.h @@ -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. */ @@ -48,11 +48,6 @@ class AnalogTriggerOutput : public DigitalSource { friend class AnalogTrigger; public: - ~AnalogTriggerOutput() override; - - AnalogTriggerOutput(AnalogTriggerOutput&&) = default; - AnalogTriggerOutput& operator=(AnalogTriggerOutput&&) = default; - /** * Get the state of the analog trigger output. * @@ -99,10 +94,10 @@ class AnalogTriggerOutput : public DigitalSource { AnalogTriggerType outputType); private: - // Uses reference rather than smart pointer because a user can not construct + // Uses pointer rather than smart pointer because a user can not construct // an AnalogTriggerOutput themselves and because the AnalogTriggerOutput // should always be in scope at the same time as an AnalogTrigger. - const AnalogTrigger& m_trigger; + const AnalogTrigger* m_trigger; AnalogTriggerType m_outputType; }; diff --git a/wpilibc/src/main/native/include/frc/CAN.h b/wpilibc/src/main/native/include/frc/CAN.h index 4cd06e9d7f..5ef4e21147 100644 --- a/wpilibc/src/main/native/include/frc/CAN.h +++ b/wpilibc/src/main/native/include/frc/CAN.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2018-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. */ @@ -58,8 +58,8 @@ class CAN : public ErrorBase { */ ~CAN() override; - CAN(CAN&& rhs); - CAN& operator=(CAN&& rhs); + CAN(CAN&&) = default; + CAN& operator=(CAN&&) = default; /** * Write a packet to the CAN device with a specific ID. This ID is 10 bits. @@ -144,6 +144,6 @@ class CAN : public ErrorBase { HAL_CAN_Dev_kMiscellaneous; private: - HAL_CANHandle m_handle = HAL_kInvalidHandle; + hal::Handle m_handle; }; } // namespace frc diff --git a/wpilibc/src/main/native/include/frc/Compressor.h b/wpilibc/src/main/native/include/frc/Compressor.h index 97f64d1e46..f16f698158 100644 --- a/wpilibc/src/main/native/include/frc/Compressor.h +++ b/wpilibc/src/main/native/include/frc/Compressor.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2014-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. */ @@ -169,7 +169,7 @@ class Compressor : public ErrorBase, public SendableBase { void InitSendable(SendableBuilder& builder) override; protected: - HAL_CompressorHandle m_compressorHandle = HAL_kInvalidHandle; + hal::Handle m_compressorHandle; private: void SetCompressor(bool on); diff --git a/wpilibc/src/main/native/include/frc/Counter.h b/wpilibc/src/main/native/include/frc/Counter.h index 2705a39413..fdfb8c5771 100644 --- a/wpilibc/src/main/native/include/frc/Counter.h +++ b/wpilibc/src/main/native/include/frc/Counter.h @@ -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. */ @@ -139,8 +139,8 @@ class Counter : public ErrorBase, public SendableBase, public CounterBase { ~Counter() override; - Counter(Counter&& rhs); - Counter& operator=(Counter&& rhs); + Counter(Counter&&) = default; + Counter& operator=(Counter&&) = default; /** * Set the upsource for the counter as a digital input channel. @@ -425,7 +425,7 @@ class Counter : public ErrorBase, public SendableBase, public CounterBase { std::shared_ptr m_downSource; // The FPGA counter object - HAL_CounterHandle m_counter = HAL_kInvalidHandle; + hal::Handle m_counter; private: int m_index = 0; // The index of this counter. diff --git a/wpilibc/src/main/native/include/frc/DigitalInput.h b/wpilibc/src/main/native/include/frc/DigitalInput.h index af191aaf54..790e1ab8d7 100644 --- a/wpilibc/src/main/native/include/frc/DigitalInput.h +++ b/wpilibc/src/main/native/include/frc/DigitalInput.h @@ -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. */ @@ -35,8 +35,8 @@ class DigitalInput : public DigitalSource { ~DigitalInput() override; - DigitalInput(DigitalInput&& rhs); - DigitalInput& operator=(DigitalInput&& rhs); + DigitalInput(DigitalInput&&) = default; + DigitalInput& operator=(DigitalInput&&) = default; /** * Get the value from a digital input channel. @@ -70,7 +70,7 @@ class DigitalInput : public DigitalSource { private: int m_channel; - HAL_DigitalHandle m_handle = HAL_kInvalidHandle; + hal::Handle m_handle; friend class DigitalGlitchFilter; }; diff --git a/wpilibc/src/main/native/include/frc/DigitalOutput.h b/wpilibc/src/main/native/include/frc/DigitalOutput.h index 49cb67dbcb..76c2a04a1f 100644 --- a/wpilibc/src/main/native/include/frc/DigitalOutput.h +++ b/wpilibc/src/main/native/include/frc/DigitalOutput.h @@ -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. */ @@ -35,8 +35,8 @@ class DigitalOutput : public ErrorBase, public SendableBase { ~DigitalOutput() override; - DigitalOutput(DigitalOutput&& rhs); - DigitalOutput& operator=(DigitalOutput&& rhs); + DigitalOutput(DigitalOutput&&) = default; + DigitalOutput& operator=(DigitalOutput&&) = default; /** * Set the value of a digital output. @@ -124,8 +124,8 @@ class DigitalOutput : public ErrorBase, public SendableBase { private: int m_channel; - HAL_DigitalHandle m_handle = HAL_kInvalidHandle; - HAL_DigitalPWMHandle m_pwmGenerator = HAL_kInvalidHandle; + hal::Handle m_handle; + hal::Handle m_pwmGenerator; }; } // namespace frc diff --git a/wpilibc/src/main/native/include/frc/DoubleSolenoid.h b/wpilibc/src/main/native/include/frc/DoubleSolenoid.h index 87c0c855bc..4edf9276de 100644 --- a/wpilibc/src/main/native/include/frc/DoubleSolenoid.h +++ b/wpilibc/src/main/native/include/frc/DoubleSolenoid.h @@ -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. */ @@ -45,8 +45,8 @@ class DoubleSolenoid : public SolenoidBase { ~DoubleSolenoid() override; - DoubleSolenoid(DoubleSolenoid&& rhs); - DoubleSolenoid& operator=(DoubleSolenoid&& rhs); + DoubleSolenoid(DoubleSolenoid&&) = default; + DoubleSolenoid& operator=(DoubleSolenoid&&) = default; /** * Set the value of a solenoid. @@ -91,8 +91,8 @@ class DoubleSolenoid : public SolenoidBase { int m_reverseChannel; // The reverse channel on the module to control. int m_forwardMask; // The mask for the forward channel. int m_reverseMask; // The mask for the reverse channel. - HAL_SolenoidHandle m_forwardHandle = HAL_kInvalidHandle; - HAL_SolenoidHandle m_reverseHandle = HAL_kInvalidHandle; + hal::Handle m_forwardHandle; + hal::Handle m_reverseHandle; }; } // namespace frc diff --git a/wpilibc/src/main/native/include/frc/Encoder.h b/wpilibc/src/main/native/include/frc/Encoder.h index 7096eeb061..03efbdb187 100644 --- a/wpilibc/src/main/native/include/frc/Encoder.h +++ b/wpilibc/src/main/native/include/frc/Encoder.h @@ -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. */ @@ -133,8 +133,8 @@ class Encoder : public ErrorBase, ~Encoder() override; - Encoder(Encoder&& rhs); - Encoder& operator=(Encoder&& rhs); + Encoder(Encoder&&) = default; + Encoder& operator=(Encoder&&) = default; // CounterBase interface /** @@ -362,7 +362,7 @@ class Encoder : public ErrorBase, std::shared_ptr m_aSource; // The A phase of the quad encoder std::shared_ptr m_bSource; // The B phase of the quad encoder std::shared_ptr m_indexSource = nullptr; - HAL_EncoderHandle m_encoder = HAL_kInvalidHandle; + hal::Handle m_encoder; friend class DigitalGlitchFilter; }; diff --git a/wpilibc/src/main/native/include/frc/I2C.h b/wpilibc/src/main/native/include/frc/I2C.h index a0860e0552..2f12615c02 100644 --- a/wpilibc/src/main/native/include/frc/I2C.h +++ b/wpilibc/src/main/native/include/frc/I2C.h @@ -35,8 +35,8 @@ class I2C : public ErrorBase { ~I2C() override; - I2C(I2C&& rhs); - I2C& operator=(I2C&& rhs); + I2C(I2C&&) = default; + I2C& operator=(I2C&&) = default; /** * Generic transaction. @@ -137,7 +137,7 @@ class I2C : public ErrorBase { bool VerifySensor(int registerAddress, int count, const uint8_t* expected); private: - HAL_I2CPort m_port = HAL_I2C_kInvalid; + hal::I2CPort m_port; int m_deviceAddress; }; diff --git a/wpilibc/src/main/native/include/frc/InterruptableSensorBase.h b/wpilibc/src/main/native/include/frc/InterruptableSensorBase.h index f650b85548..527702f7e6 100644 --- a/wpilibc/src/main/native/include/frc/InterruptableSensorBase.h +++ b/wpilibc/src/main/native/include/frc/InterruptableSensorBase.h @@ -41,8 +41,8 @@ class InterruptableSensorBase : public ErrorBase, public SendableBase { */ virtual ~InterruptableSensorBase(); - InterruptableSensorBase(InterruptableSensorBase&&); - InterruptableSensorBase& operator=(InterruptableSensorBase&&); + InterruptableSensorBase(InterruptableSensorBase&&) = default; + InterruptableSensorBase& operator=(InterruptableSensorBase&&) = default; virtual HAL_Handle GetPortHandleForRouting() const = 0; virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0; @@ -144,7 +144,7 @@ class InterruptableSensorBase : public ErrorBase, public SendableBase { virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge); protected: - HAL_InterruptHandle m_interrupt{HAL_kInvalidHandle}; + hal::Handle m_interrupt; std::unique_ptr m_interruptHandler{nullptr}; void AllocateInterrupts(bool watcher); diff --git a/wpilibc/src/main/native/include/frc/PWM.h b/wpilibc/src/main/native/include/frc/PWM.h index 99f213ed25..08cbd4f175 100644 --- a/wpilibc/src/main/native/include/frc/PWM.h +++ b/wpilibc/src/main/native/include/frc/PWM.h @@ -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. */ @@ -73,8 +73,8 @@ class PWM : public MotorSafety, public SendableBase { */ ~PWM() override; - PWM(PWM&& rhs); - PWM& operator=(PWM&& rhs); + PWM(PWM&&) = default; + PWM& operator=(PWM&&) = default; // MotorSafety interface void StopMotor() override; @@ -231,7 +231,7 @@ class PWM : public MotorSafety, public SendableBase { private: int m_channel; - HAL_DigitalHandle m_handle = HAL_kInvalidHandle; + hal::Handle m_handle; }; } // namespace frc diff --git a/wpilibc/src/main/native/include/frc/PowerDistributionPanel.h b/wpilibc/src/main/native/include/frc/PowerDistributionPanel.h index 2d7f65cda6..d0ddf33ef3 100644 --- a/wpilibc/src/main/native/include/frc/PowerDistributionPanel.h +++ b/wpilibc/src/main/native/include/frc/PowerDistributionPanel.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2014-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. */ @@ -83,7 +83,7 @@ class PowerDistributionPanel : public ErrorBase, public SendableBase { void InitSendable(SendableBuilder& builder) override; private: - HAL_PDPHandle m_handle = HAL_kInvalidHandle; + hal::Handle m_handle; }; } // namespace frc diff --git a/wpilibc/src/main/native/include/frc/Relay.h b/wpilibc/src/main/native/include/frc/Relay.h index 6fb21b56c4..3de58d29f9 100644 --- a/wpilibc/src/main/native/include/frc/Relay.h +++ b/wpilibc/src/main/native/include/frc/Relay.h @@ -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. */ @@ -53,8 +53,8 @@ class Relay : public MotorSafety, public SendableBase { */ ~Relay() override; - Relay(Relay&& rhs); - Relay& operator=(Relay&& rhs); + Relay(Relay&&) = default; + Relay& operator=(Relay&&) = default; /** * Set the relay state. @@ -98,8 +98,8 @@ class Relay : public MotorSafety, public SendableBase { int m_channel; Direction m_direction; - HAL_RelayHandle m_forwardHandle = HAL_kInvalidHandle; - HAL_RelayHandle m_reverseHandle = HAL_kInvalidHandle; + hal::Handle m_forwardHandle; + hal::Handle m_reverseHandle; }; } // namespace frc diff --git a/wpilibc/src/main/native/include/frc/SPI.h b/wpilibc/src/main/native/include/frc/SPI.h index 44efd9af30..a5e6a44c9c 100644 --- a/wpilibc/src/main/native/include/frc/SPI.h +++ b/wpilibc/src/main/native/include/frc/SPI.h @@ -41,8 +41,8 @@ class SPI : public ErrorBase { ~SPI() override; - SPI(SPI&& rhs); - SPI& operator=(SPI&& rhs); + SPI(SPI&&) = default; + SPI& operator=(SPI&&) = default; /** * Configure the rate of the generated clock signal. @@ -345,7 +345,7 @@ class SPI : public ErrorBase { double GetAccumulatorIntegratedAverage() const; protected: - HAL_SPIPort m_port = HAL_SPI_kInvalid; + hal::SPIPort m_port; bool m_msbFirst = false; // Default little-endian bool m_sampleOnTrailing = false; // Default data updated on falling edge bool m_clockIdleHigh = false; // Default clock active high diff --git a/wpilibc/src/main/native/include/frc/Solenoid.h b/wpilibc/src/main/native/include/frc/Solenoid.h index 8a90b2603d..e6f012d59f 100644 --- a/wpilibc/src/main/native/include/frc/Solenoid.h +++ b/wpilibc/src/main/native/include/frc/Solenoid.h @@ -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. */ @@ -38,8 +38,8 @@ class Solenoid : public SolenoidBase { ~Solenoid() override; - Solenoid(Solenoid&& rhs); - Solenoid& operator=(Solenoid&& rhs); + Solenoid(Solenoid&&) = default; + Solenoid& operator=(Solenoid&&) = default; /** * Set the value of a solenoid. @@ -90,7 +90,7 @@ class Solenoid : public SolenoidBase { void InitSendable(SendableBuilder& builder) override; private: - HAL_SolenoidHandle m_solenoidHandle = HAL_kInvalidHandle; + hal::Handle m_solenoidHandle; int m_channel; // The channel on the module to control }; diff --git a/wpilibc/src/main/native/include/frc/TimedRobot.h b/wpilibc/src/main/native/include/frc/TimedRobot.h index 323878fb37..fcc498e0c5 100644 --- a/wpilibc/src/main/native/include/frc/TimedRobot.h +++ b/wpilibc/src/main/native/include/frc/TimedRobot.h @@ -56,11 +56,11 @@ class TimedRobot : public IterativeRobotBase, public ErrorBase { ~TimedRobot() override; - TimedRobot(TimedRobot&& rhs); - TimedRobot& operator=(TimedRobot&& rhs); + TimedRobot(TimedRobot&&) = default; + TimedRobot& operator=(TimedRobot&&) = default; private: - HAL_NotifierHandle m_notifier{0}; + hal::Handle m_notifier; // The absolute expiration time double m_expirationTime = 0;