mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[wpilibc] Remove Utility.h (#3376)
Change last 2 uses of wpi_assert to throw error instead.
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
#include "frc/Encoder.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/Utility.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "frc/InterruptableSensorBase.h"
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/Utility.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/Timer.h"
|
||||
#include "frc/Utility.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/Utility.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -119,7 +118,7 @@ void PWM::SetPeriodMultiplier(PeriodMultiplier mult) {
|
||||
HAL_SetPWMPeriodScale(m_handle, 0, &status); // Don't squelch any outputs
|
||||
break;
|
||||
default:
|
||||
wpi_assert(false);
|
||||
throw FRC_MakeError(err::InvalidParameter, "PeriodMultiplier value");
|
||||
}
|
||||
|
||||
FRC_CheckErrorStatus(status, "SetPeriodMultiplier");
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/Timer.h"
|
||||
#include "frc/Utility.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include "frc/DigitalOutput.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/Timer.h"
|
||||
#include "frc/Utility.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -83,7 +82,10 @@ Ultrasonic::~Ultrasonic() {
|
||||
}
|
||||
|
||||
void Ultrasonic::Ping() {
|
||||
wpi_assert(!m_automaticEnabled);
|
||||
if (m_automaticEnabled) {
|
||||
throw FRC_MakeError(err::IncompatibleMode,
|
||||
"cannot call Ping() in automatic mode");
|
||||
}
|
||||
|
||||
// Reset the counter to zero (invalid data now)
|
||||
m_counter.Reset();
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/Utility.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <cxxabi.h>
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
|
||||
#include <frc/Base.h>
|
||||
#include <hal/DriverStation.h>
|
||||
#include <wpi/Path.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/StackTrace.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
bool wpi_assert_impl(bool conditionValue, const wpi::Twine& conditionText,
|
||||
const wpi::Twine& message, wpi::StringRef fileName,
|
||||
int lineNumber, wpi::StringRef funcName) {
|
||||
if (!conditionValue) {
|
||||
wpi::SmallString<128> locBuf;
|
||||
wpi::raw_svector_ostream locStream(locBuf);
|
||||
locStream << funcName << " [" << wpi::sys::path::filename(fileName) << ":"
|
||||
<< lineNumber << "]";
|
||||
|
||||
wpi::SmallString<128> errorBuf;
|
||||
wpi::raw_svector_ostream errorStream(errorBuf);
|
||||
|
||||
errorStream << "Assertion \"" << conditionText << "\" ";
|
||||
|
||||
if (message.isTriviallyEmpty() ||
|
||||
(message.isSingleStringRef() && message.getSingleStringRef().empty())) {
|
||||
errorStream << "failed.\n";
|
||||
} else {
|
||||
errorStream << "failed: " << message << "\n";
|
||||
}
|
||||
|
||||
std::string stack = wpi::GetStackTrace(2);
|
||||
|
||||
// Print the error and send it to the DriverStation
|
||||
HAL_SendError(1, 1, 0, errorBuf.c_str(), locBuf.c_str(), stack.c_str(), 1);
|
||||
}
|
||||
|
||||
return conditionValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Common error routines for wpi_assertEqual_impl and wpi_assertNotEqual_impl.
|
||||
*
|
||||
* This should not be called directly; it should only be used by
|
||||
* wpi_assertEqual_impl and wpi_assertNotEqual_impl.
|
||||
*/
|
||||
void wpi_assertEqual_common_impl(const wpi::Twine& valueA,
|
||||
const wpi::Twine& valueB,
|
||||
const wpi::Twine& equalityType,
|
||||
const wpi::Twine& message,
|
||||
wpi::StringRef fileName, int lineNumber,
|
||||
wpi::StringRef funcName) {
|
||||
wpi::SmallString<128> locBuf;
|
||||
wpi::raw_svector_ostream locStream(locBuf);
|
||||
locStream << funcName << " [" << wpi::sys::path::filename(fileName) << ":"
|
||||
<< lineNumber << "]";
|
||||
|
||||
wpi::SmallString<128> errorBuf;
|
||||
wpi::raw_svector_ostream errorStream(errorBuf);
|
||||
|
||||
errorStream << "Assertion \"" << valueA << " " << equalityType << " "
|
||||
<< valueB << "\" ";
|
||||
|
||||
if (message.isTriviallyEmpty() ||
|
||||
(message.isSingleStringRef() && message.getSingleStringRef().empty())) {
|
||||
errorStream << "failed.\n";
|
||||
} else {
|
||||
errorStream << "failed: " << message << "\n";
|
||||
}
|
||||
|
||||
std::string trace = wpi::GetStackTrace(3);
|
||||
|
||||
// Print the error and send it to the DriverStation
|
||||
HAL_SendError(1, 1, 0, errorBuf.c_str(), locBuf.c_str(), trace.c_str(), 1);
|
||||
}
|
||||
|
||||
bool wpi_assertEqual_impl(int valueA, int valueB,
|
||||
const wpi::Twine& valueAString,
|
||||
const wpi::Twine& valueBString,
|
||||
const wpi::Twine& message, wpi::StringRef fileName,
|
||||
int lineNumber, wpi::StringRef funcName) {
|
||||
if (!(valueA == valueB)) {
|
||||
wpi_assertEqual_common_impl(valueAString, valueBString, "==", message,
|
||||
fileName, lineNumber, funcName);
|
||||
}
|
||||
return valueA == valueB;
|
||||
}
|
||||
|
||||
bool wpi_assertNotEqual_impl(int valueA, int valueB,
|
||||
const wpi::Twine& valueAString,
|
||||
const wpi::Twine& valueBString,
|
||||
const wpi::Twine& message, wpi::StringRef fileName,
|
||||
int lineNumber, wpi::StringRef funcName) {
|
||||
if (!(valueA != valueB)) {
|
||||
wpi_assertEqual_common_impl(valueAString, valueBString, "!=", message,
|
||||
fileName, lineNumber, funcName);
|
||||
}
|
||||
return valueA != valueB;
|
||||
}
|
||||
Reference in New Issue
Block a user