From 54326311ad37ccda50edb6acc31f0f86e3d37a7e Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 1 Dec 2017 21:50:24 -0800 Subject: [PATCH] Use Twine in error checks. --- wpilibc/src/main/native/cpp/AnalogInput.cpp | 9 ++------- wpilibc/src/main/native/cpp/AnalogOutput.cpp | 9 ++------- wpilibc/src/main/native/cpp/DigitalInput.cpp | 9 ++------- wpilibc/src/main/native/cpp/DigitalOutput.cpp | 9 ++------- .../src/main/native/cpp/DoubleSolenoid.cpp | 19 +++++++++---------- wpilibc/src/main/native/cpp/Error.cpp | 2 -- wpilibc/src/main/native/cpp/PWM.cpp | 9 ++------- wpilibc/src/main/native/cpp/Relay.cpp | 8 +++----- wpilibc/src/main/native/cpp/Solenoid.cpp | 13 +++++-------- 9 files changed, 27 insertions(+), 60 deletions(-) diff --git a/wpilibc/src/main/native/cpp/AnalogInput.cpp b/wpilibc/src/main/native/cpp/AnalogInput.cpp index 20f8499e09..570f33145d 100644 --- a/wpilibc/src/main/native/cpp/AnalogInput.cpp +++ b/wpilibc/src/main/native/cpp/AnalogInput.cpp @@ -11,8 +11,6 @@ #include #include #include -#include -#include #include "SmartDashboard/SendableBuilder.h" #include "Timer.h" @@ -27,12 +25,9 @@ using namespace frc; * on-board 4-7 are on the MXP port. */ AnalogInput::AnalogInput(int channel) { - llvm::SmallString<32> str; - llvm::raw_svector_ostream buf(str); - buf << "Analog Input " << channel; - if (!SensorBase::CheckAnalogInputChannel(channel)) { - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str()); + wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, + "Analog Input " + llvm::Twine(channel)); return; } diff --git a/wpilibc/src/main/native/cpp/AnalogOutput.cpp b/wpilibc/src/main/native/cpp/AnalogOutput.cpp index b2b05acc96..8535485c71 100644 --- a/wpilibc/src/main/native/cpp/AnalogOutput.cpp +++ b/wpilibc/src/main/native/cpp/AnalogOutput.cpp @@ -11,8 +11,6 @@ #include #include -#include -#include #include "SensorBase.h" #include "SmartDashboard/SendableBuilder.h" @@ -28,12 +26,9 @@ using namespace frc; * @param channel The channel number on the roboRIO to represent. */ AnalogOutput::AnalogOutput(int channel) { - llvm::SmallString<32> str; - llvm::raw_svector_ostream buf(str); - buf << "analog output " << channel; - if (!SensorBase::CheckAnalogOutputChannel(channel)) { - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str()); + wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, + "analog output " + llvm::Twine(channel)); m_channel = std::numeric_limits::max(); m_port = HAL_kInvalidHandle; return; diff --git a/wpilibc/src/main/native/cpp/DigitalInput.cpp b/wpilibc/src/main/native/cpp/DigitalInput.cpp index 407fa8ee46..9d0055d162 100644 --- a/wpilibc/src/main/native/cpp/DigitalInput.cpp +++ b/wpilibc/src/main/native/cpp/DigitalInput.cpp @@ -12,8 +12,6 @@ #include #include #include -#include -#include #include "SmartDashboard/SendableBuilder.h" #include "WPIErrors.h" @@ -28,12 +26,9 @@ using namespace frc; * @param channel The DIO channel 0-9 are on-board, 10-25 are on the MXP port */ DigitalInput::DigitalInput(int channel) { - llvm::SmallString<32> str; - llvm::raw_svector_ostream buf(str); - if (!CheckDigitalChannel(channel)) { - buf << "Digital Channel " << channel; - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str()); + wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, + "Digital Channel " + llvm::Twine(channel)); m_channel = std::numeric_limits::max(); return; } diff --git a/wpilibc/src/main/native/cpp/DigitalOutput.cpp b/wpilibc/src/main/native/cpp/DigitalOutput.cpp index 99f25f0001..0e9399c257 100644 --- a/wpilibc/src/main/native/cpp/DigitalOutput.cpp +++ b/wpilibc/src/main/native/cpp/DigitalOutput.cpp @@ -12,8 +12,6 @@ #include #include #include -#include -#include #include "SensorBase.h" #include "SmartDashboard/SendableBuilder.h" @@ -30,13 +28,10 @@ using namespace frc; * port */ DigitalOutput::DigitalOutput(int channel) { - llvm::SmallString<32> str; - llvm::raw_svector_ostream buf(str); - m_pwmGenerator = HAL_kInvalidHandle; if (!SensorBase::CheckDigitalChannel(channel)) { - buf << "Digital Channel " << channel; - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str()); + wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, + "Digital Channel " + llvm::Twine(channel)); m_channel = std::numeric_limits::max(); return; } diff --git a/wpilibc/src/main/native/cpp/DoubleSolenoid.cpp b/wpilibc/src/main/native/cpp/DoubleSolenoid.cpp index 452d09702e..a487d676d7 100644 --- a/wpilibc/src/main/native/cpp/DoubleSolenoid.cpp +++ b/wpilibc/src/main/native/cpp/DoubleSolenoid.cpp @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include "SensorBase.h" #include "SmartDashboard/SendableBuilder.h" @@ -43,21 +41,22 @@ DoubleSolenoid::DoubleSolenoid(int moduleNumber, int forwardChannel, : SolenoidBase(moduleNumber), m_forwardChannel(forwardChannel), m_reverseChannel(reverseChannel) { - llvm::SmallString<32> str; - llvm::raw_svector_ostream buf(str); if (!SensorBase::CheckSolenoidModule(m_moduleNumber)) { - buf << "Solenoid Module " << m_moduleNumber; - wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf.str()); + wpi_setWPIErrorWithContext( + ModuleIndexOutOfRange, + "Solenoid Module " + llvm::Twine(m_moduleNumber)); return; } if (!SensorBase::CheckSolenoidChannel(m_forwardChannel)) { - buf << "Solenoid Module " << m_forwardChannel; - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str()); + wpi_setWPIErrorWithContext( + ChannelIndexOutOfRange, + "Solenoid Channel " + llvm::Twine(m_forwardChannel)); return; } if (!SensorBase::CheckSolenoidChannel(m_reverseChannel)) { - buf << "Solenoid Module " << m_reverseChannel; - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str()); + wpi_setWPIErrorWithContext( + ChannelIndexOutOfRange, + "Solenoid Channel " + llvm::Twine(m_reverseChannel)); return; } int32_t status = 0; diff --git a/wpilibc/src/main/native/cpp/Error.cpp b/wpilibc/src/main/native/cpp/Error.cpp index 8654c06ed4..48f87cef27 100644 --- a/wpilibc/src/main/native/cpp/Error.cpp +++ b/wpilibc/src/main/native/cpp/Error.cpp @@ -8,8 +8,6 @@ #include "Error.h" #include -#include -#include #include "DriverStation.h" #include "Timer.h" diff --git a/wpilibc/src/main/native/cpp/PWM.cpp b/wpilibc/src/main/native/cpp/PWM.cpp index c4abe363e3..d42f78c3c1 100644 --- a/wpilibc/src/main/native/cpp/PWM.cpp +++ b/wpilibc/src/main/native/cpp/PWM.cpp @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include "SensorBase.h" #include "SmartDashboard/SendableBuilder.h" @@ -31,12 +29,9 @@ using namespace frc; * MXP port */ PWM::PWM(int channel) { - llvm::SmallString<32> str; - llvm::raw_svector_ostream buf(str); - if (!SensorBase::CheckPWMChannel(channel)) { - buf << "PWM Channel " << channel; - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str()); + wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, + "PWM Channel " + llvm::Twine(channel)); return; } diff --git a/wpilibc/src/main/native/cpp/Relay.cpp b/wpilibc/src/main/native/cpp/Relay.cpp index 5338144f91..2dd2cc71e4 100644 --- a/wpilibc/src/main/native/cpp/Relay.cpp +++ b/wpilibc/src/main/native/cpp/Relay.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include "MotorSafetyHelper.h" #include "SensorBase.h" @@ -30,11 +30,9 @@ using namespace frc; */ Relay::Relay(int channel, Relay::Direction direction) : m_channel(channel), m_direction(direction) { - llvm::SmallString<128> str; - llvm::raw_svector_ostream buf(str); if (!SensorBase::CheckRelayChannel(m_channel)) { - buf << "Relay Channel " << m_channel; - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str()); + wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, + "Relay Channel " + llvm::Twine(m_channel)); return; } diff --git a/wpilibc/src/main/native/cpp/Solenoid.cpp b/wpilibc/src/main/native/cpp/Solenoid.cpp index 18b09ebccf..182addb726 100644 --- a/wpilibc/src/main/native/cpp/Solenoid.cpp +++ b/wpilibc/src/main/native/cpp/Solenoid.cpp @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include "SensorBase.h" #include "SmartDashboard/SendableBuilder.h" @@ -35,16 +33,15 @@ Solenoid::Solenoid(int channel) */ Solenoid::Solenoid(int moduleNumber, int channel) : SolenoidBase(moduleNumber), m_channel(channel) { - llvm::SmallString<32> str; - llvm::raw_svector_ostream buf(str); if (!SensorBase::CheckSolenoidModule(m_moduleNumber)) { - buf << "Solenoid Module " << m_moduleNumber; - wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf.str()); + wpi_setWPIErrorWithContext( + ModuleIndexOutOfRange, + "Solenoid Module " + llvm::Twine(m_moduleNumber)); return; } if (!SensorBase::CheckSolenoidChannel(m_channel)) { - buf << "Solenoid Module " << m_channel; - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str()); + wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, + "Solenoid Channel " + llvm::Twine(m_channel)); return; }