mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Use std::string_view and fmtlib across all libraries (#3402)
- Twine, StringRef, Format, and NativeFormatting have been removed - Logging now uses fmtlib style formatting - Nearly all uses of wpi::outs/errs have been replaced with fmt::print() or std::puts()/std::fputs() (for unformatted strings). - A wpi/fmt/raw_ostream.h header has been added to enable fmt::print() with wpi::raw_ostream
This commit is contained in:
@@ -121,7 +121,7 @@ void DoubleSolenoid::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSafeState([=]() { Set(kOff); });
|
||||
builder.AddSmallStringProperty(
|
||||
"Value",
|
||||
[=](wpi::SmallVectorImpl<char>& buf) -> wpi::StringRef {
|
||||
[=](wpi::SmallVectorImpl<char>& buf) -> std::string_view {
|
||||
switch (Get()) {
|
||||
case kForward:
|
||||
return "Forward";
|
||||
@@ -131,7 +131,7 @@ void DoubleSolenoid::InitSendable(SendableBuilder& builder) {
|
||||
return "Off";
|
||||
}
|
||||
},
|
||||
[=](wpi::StringRef value) {
|
||||
[=](std::string_view value) {
|
||||
Value lvalue = kOff;
|
||||
if (value == "Forward") {
|
||||
lvalue = kForward;
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
#include "frc/IterativeRobotBase.h"
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <hal/DriverStation.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/livewindow/LiveWindow.h"
|
||||
@@ -23,33 +23,33 @@ IterativeRobotBase::IterativeRobotBase(units::second_t period)
|
||||
m_watchdog(period, [this] { PrintLoopOverrunMessage(); }) {}
|
||||
|
||||
void IterativeRobotBase::RobotInit() {
|
||||
wpi::outs() << "Default " << __FUNCTION__ << "() method... Override me!\n";
|
||||
fmt::print("Default {}() method... Override me!\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
void IterativeRobotBase::SimulationInit() {
|
||||
wpi::outs() << "Default " << __FUNCTION__ << "() method... Override me!\n";
|
||||
fmt::print("Default {}() method... Override me!\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
void IterativeRobotBase::DisabledInit() {
|
||||
wpi::outs() << "Default " << __FUNCTION__ << "() method... Override me!\n";
|
||||
fmt::print("Default {}() method... Override me!\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
void IterativeRobotBase::AutonomousInit() {
|
||||
wpi::outs() << "Default " << __FUNCTION__ << "() method... Override me!\n";
|
||||
fmt::print("Default {}() method... Override me!\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
void IterativeRobotBase::TeleopInit() {
|
||||
wpi::outs() << "Default " << __FUNCTION__ << "() method... Override me!\n";
|
||||
fmt::print("Default {}() method... Override me!\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
void IterativeRobotBase::TestInit() {
|
||||
wpi::outs() << "Default " << __FUNCTION__ << "() method... Override me!\n";
|
||||
fmt::print("Default {}() method... Override me!\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
void IterativeRobotBase::RobotPeriodic() {
|
||||
static bool firstRun = true;
|
||||
if (firstRun) {
|
||||
wpi::outs() << "Default " << __FUNCTION__ << "() method... Override me!\n";
|
||||
fmt::print("Default {}() method... Override me!\n", __FUNCTION__);
|
||||
firstRun = false;
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ void IterativeRobotBase::RobotPeriodic() {
|
||||
void IterativeRobotBase::SimulationPeriodic() {
|
||||
static bool firstRun = true;
|
||||
if (firstRun) {
|
||||
wpi::outs() << "Default " << __FUNCTION__ << "() method... Override me!\n";
|
||||
fmt::print("Default {}() method... Override me!\n", __FUNCTION__);
|
||||
firstRun = false;
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ void IterativeRobotBase::SimulationPeriodic() {
|
||||
void IterativeRobotBase::DisabledPeriodic() {
|
||||
static bool firstRun = true;
|
||||
if (firstRun) {
|
||||
wpi::outs() << "Default " << __FUNCTION__ << "() method... Override me!\n";
|
||||
fmt::print("Default {}() method... Override me!\n", __FUNCTION__);
|
||||
firstRun = false;
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ void IterativeRobotBase::DisabledPeriodic() {
|
||||
void IterativeRobotBase::AutonomousPeriodic() {
|
||||
static bool firstRun = true;
|
||||
if (firstRun) {
|
||||
wpi::outs() << "Default " << __FUNCTION__ << "() method... Override me!\n";
|
||||
fmt::print("Default {}() method... Override me!\n", __FUNCTION__);
|
||||
firstRun = false;
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ void IterativeRobotBase::AutonomousPeriodic() {
|
||||
void IterativeRobotBase::TeleopPeriodic() {
|
||||
static bool firstRun = true;
|
||||
if (firstRun) {
|
||||
wpi::outs() << "Default " << __FUNCTION__ << "() method... Override me!\n";
|
||||
fmt::print("Default {}() method... Override me!\n", __FUNCTION__);
|
||||
firstRun = false;
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,7 @@ void IterativeRobotBase::TeleopPeriodic() {
|
||||
void IterativeRobotBase::TestPeriodic() {
|
||||
static bool firstRun = true;
|
||||
if (firstRun) {
|
||||
wpi::outs() << "Default " << __FUNCTION__ << "() method... Override me!\n";
|
||||
fmt::print("Default {}() method... Override me!\n", __FUNCTION__);
|
||||
firstRun = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,11 @@
|
||||
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
// The Preferences table name
|
||||
static wpi::StringRef kTableName{"Preferences"};
|
||||
static constexpr std::string_view kTableName{"Preferences"};
|
||||
|
||||
Preferences* Preferences::GetInstance() {
|
||||
static Preferences instance;
|
||||
@@ -24,126 +23,126 @@ std::vector<std::string> Preferences::GetKeys() {
|
||||
return m_table->GetKeys();
|
||||
}
|
||||
|
||||
std::string Preferences::GetString(wpi::StringRef key,
|
||||
wpi::StringRef defaultValue) {
|
||||
std::string Preferences::GetString(std::string_view key,
|
||||
std::string_view defaultValue) {
|
||||
return m_table->GetString(key, defaultValue);
|
||||
}
|
||||
|
||||
int Preferences::GetInt(wpi::StringRef key, int defaultValue) {
|
||||
int Preferences::GetInt(std::string_view key, int defaultValue) {
|
||||
return static_cast<int>(m_table->GetNumber(key, defaultValue));
|
||||
}
|
||||
|
||||
double Preferences::GetDouble(wpi::StringRef key, double defaultValue) {
|
||||
double Preferences::GetDouble(std::string_view key, double defaultValue) {
|
||||
return m_table->GetNumber(key, defaultValue);
|
||||
}
|
||||
|
||||
float Preferences::GetFloat(wpi::StringRef key, float defaultValue) {
|
||||
float Preferences::GetFloat(std::string_view key, float defaultValue) {
|
||||
return m_table->GetNumber(key, defaultValue);
|
||||
}
|
||||
|
||||
bool Preferences::GetBoolean(wpi::StringRef key, bool defaultValue) {
|
||||
bool Preferences::GetBoolean(std::string_view key, bool defaultValue) {
|
||||
return m_table->GetBoolean(key, defaultValue);
|
||||
}
|
||||
|
||||
int64_t Preferences::GetLong(wpi::StringRef key, int64_t defaultValue) {
|
||||
int64_t Preferences::GetLong(std::string_view key, int64_t defaultValue) {
|
||||
return static_cast<int64_t>(m_table->GetNumber(key, defaultValue));
|
||||
}
|
||||
|
||||
void Preferences::SetString(wpi::StringRef key, wpi::StringRef value) {
|
||||
void Preferences::SetString(std::string_view key, std::string_view value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetString(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
|
||||
void Preferences::PutString(wpi::StringRef key, wpi::StringRef value) {
|
||||
void Preferences::PutString(std::string_view key, std::string_view value) {
|
||||
SetString(key, value);
|
||||
}
|
||||
|
||||
void Preferences::InitString(wpi::StringRef key, wpi::StringRef value) {
|
||||
void Preferences::InitString(std::string_view key, std::string_view value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDefaultString(value);
|
||||
}
|
||||
|
||||
void Preferences::SetInt(wpi::StringRef key, int value) {
|
||||
void Preferences::SetInt(std::string_view key, int value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDouble(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
|
||||
void Preferences::PutInt(wpi::StringRef key, int value) {
|
||||
void Preferences::PutInt(std::string_view key, int value) {
|
||||
SetInt(key, value);
|
||||
}
|
||||
|
||||
void Preferences::InitInt(wpi::StringRef key, int value) {
|
||||
void Preferences::InitInt(std::string_view key, int value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDefaultDouble(value);
|
||||
}
|
||||
|
||||
void Preferences::SetDouble(wpi::StringRef key, double value) {
|
||||
void Preferences::SetDouble(std::string_view key, double value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDouble(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
|
||||
void Preferences::PutDouble(wpi::StringRef key, double value) {
|
||||
void Preferences::PutDouble(std::string_view key, double value) {
|
||||
SetDouble(key, value);
|
||||
}
|
||||
|
||||
void Preferences::InitDouble(wpi::StringRef key, double value) {
|
||||
void Preferences::InitDouble(std::string_view key, double value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDefaultDouble(value);
|
||||
}
|
||||
|
||||
void Preferences::SetFloat(wpi::StringRef key, float value) {
|
||||
void Preferences::SetFloat(std::string_view key, float value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDouble(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
|
||||
void Preferences::PutFloat(wpi::StringRef key, float value) {
|
||||
void Preferences::PutFloat(std::string_view key, float value) {
|
||||
SetFloat(key, value);
|
||||
}
|
||||
|
||||
void Preferences::InitFloat(wpi::StringRef key, float value) {
|
||||
void Preferences::InitFloat(std::string_view key, float value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDefaultDouble(value);
|
||||
}
|
||||
|
||||
void Preferences::SetBoolean(wpi::StringRef key, bool value) {
|
||||
void Preferences::SetBoolean(std::string_view key, bool value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetBoolean(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
|
||||
void Preferences::PutBoolean(wpi::StringRef key, bool value) {
|
||||
void Preferences::PutBoolean(std::string_view key, bool value) {
|
||||
SetBoolean(key, value);
|
||||
}
|
||||
|
||||
void Preferences::InitBoolean(wpi::StringRef key, bool value) {
|
||||
void Preferences::InitBoolean(std::string_view key, bool value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDefaultBoolean(value);
|
||||
}
|
||||
|
||||
void Preferences::SetLong(wpi::StringRef key, int64_t value) {
|
||||
void Preferences::SetLong(std::string_view key, int64_t value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDouble(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
|
||||
void Preferences::PutLong(wpi::StringRef key, int64_t value) {
|
||||
void Preferences::PutLong(std::string_view key, int64_t value) {
|
||||
SetLong(key, value);
|
||||
}
|
||||
|
||||
void Preferences::InitLong(wpi::StringRef key, int64_t value) {
|
||||
void Preferences::InitLong(std::string_view key, int64_t value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDefaultDouble(value);
|
||||
}
|
||||
|
||||
bool Preferences::ContainsKey(wpi::StringRef key) {
|
||||
bool Preferences::ContainsKey(std::string_view key) {
|
||||
return m_table->ContainsKey(key);
|
||||
}
|
||||
|
||||
void Preferences::Remove(wpi::StringRef key) {
|
||||
void Preferences::Remove(std::string_view key) {
|
||||
m_table->Delete(key);
|
||||
}
|
||||
|
||||
@@ -159,7 +158,7 @@ Preferences::Preferences()
|
||||
: m_table(nt::NetworkTableInstance::GetDefault().GetTable(kTableName)) {
|
||||
m_table->GetEntry(".type").SetString("RobotPreferences");
|
||||
m_listener = m_table->AddEntryListener(
|
||||
[=](nt::NetworkTable* table, wpi::StringRef name,
|
||||
[=](nt::NetworkTable* table, std::string_view name,
|
||||
nt::NetworkTableEntry entry, std::shared_ptr<nt::Value> value,
|
||||
int flags) { entry.SetPersistent(); },
|
||||
NT_NOTIFY_NEW | NT_NOTIFY_IMMEDIATE);
|
||||
|
||||
@@ -178,7 +178,7 @@ void Relay::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSafeState([=]() { Set(kOff); });
|
||||
builder.AddSmallStringProperty(
|
||||
"Value",
|
||||
[=](wpi::SmallVectorImpl<char>& buf) -> wpi::StringRef {
|
||||
[=](wpi::SmallVectorImpl<char>& buf) -> std::string_view {
|
||||
switch (Get()) {
|
||||
case kOn:
|
||||
return "On";
|
||||
@@ -190,7 +190,7 @@ void Relay::InitSendable(SendableBuilder& builder) {
|
||||
return "Off";
|
||||
}
|
||||
},
|
||||
[=](wpi::StringRef value) {
|
||||
[=](std::string_view value) {
|
||||
if (value == "Off") {
|
||||
Set(kOff);
|
||||
} else if (value == "Forward") {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "frc/Tracer.h"
|
||||
|
||||
#include <wpi/Format.h>
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
@@ -25,7 +25,7 @@ void Tracer::ClearEpochs() {
|
||||
m_epochs.clear();
|
||||
}
|
||||
|
||||
void Tracer::AddEpoch(wpi::StringRef epochName) {
|
||||
void Tracer::AddEpoch(std::string_view epochName) {
|
||||
auto currentTime = hal::fpga_clock::now();
|
||||
m_epochs[epochName] = currentTime - m_startTime;
|
||||
m_startTime = currentTime;
|
||||
@@ -48,11 +48,9 @@ void Tracer::PrintEpochs(wpi::raw_ostream& os) {
|
||||
if (now - m_lastEpochsPrintTime > kMinPrintPeriod) {
|
||||
m_lastEpochsPrintTime = now;
|
||||
for (const auto& epoch : m_epochs) {
|
||||
os << '\t' << epoch.getKey() << ": "
|
||||
<< wpi::format(
|
||||
"%.6f",
|
||||
duration_cast<microseconds>(epoch.getValue()).count() / 1.0e6)
|
||||
<< "s\n";
|
||||
os << fmt::format(
|
||||
"\t{}: {:.6f}s\n", epoch.getKey(),
|
||||
duration_cast<microseconds>(epoch.getValue()).count() / 1.0e6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ bool Watchdog::IsExpired() const {
|
||||
return m_isExpired;
|
||||
}
|
||||
|
||||
void Watchdog::AddEpoch(wpi::StringRef epochName) {
|
||||
void Watchdog::AddEpoch(std::string_view epochName) {
|
||||
m_tracer.AddEpoch(epochName);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
wpi::StringRef LayoutType::GetLayoutName() const {
|
||||
std::string_view LayoutType::GetLayoutName() const {
|
||||
return m_layoutName;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ void RecordingController::StopRecording() {
|
||||
m_recordingControlEntry.SetBoolean(false);
|
||||
}
|
||||
|
||||
void RecordingController::SetRecordingFileNameFormat(wpi::StringRef format) {
|
||||
void RecordingController::SetRecordingFileNameFormat(std::string_view format) {
|
||||
m_recordingFileNameFormatEntry.SetString(format);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ void RecordingController::ClearRecordingFileNameFormat() {
|
||||
}
|
||||
|
||||
void RecordingController::AddEventMarker(
|
||||
wpi::StringRef name, wpi::StringRef description,
|
||||
std::string_view name, std::string_view description,
|
||||
ShuffleboardEventImportance importance) {
|
||||
if (name.empty()) {
|
||||
FRC_ReportError(err::Error, "{}",
|
||||
@@ -43,5 +43,6 @@ void RecordingController::AddEventMarker(
|
||||
return;
|
||||
}
|
||||
m_eventsTable->GetSubTable(name)->GetEntry("Info").SetStringArray(
|
||||
{description, ShuffleboardEventImportanceName(importance)});
|
||||
{std::string{description},
|
||||
std::string{ShuffleboardEventImportanceName(importance)}});
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ void Shuffleboard::Update() {
|
||||
GetInstance().Update();
|
||||
}
|
||||
|
||||
ShuffleboardTab& Shuffleboard::GetTab(wpi::StringRef title) {
|
||||
ShuffleboardTab& Shuffleboard::GetTab(std::string_view title) {
|
||||
return GetInstance().GetTab(title);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ void Shuffleboard::SelectTab(int index) {
|
||||
GetInstance().SelectTab(index);
|
||||
}
|
||||
|
||||
void Shuffleboard::SelectTab(wpi::StringRef title) {
|
||||
void Shuffleboard::SelectTab(std::string_view title) {
|
||||
GetInstance().SelectTab(title);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ void Shuffleboard::StopRecording() {
|
||||
GetRecordingController().StopRecording();
|
||||
}
|
||||
|
||||
void Shuffleboard::SetRecordingFileNameFormat(wpi::StringRef format) {
|
||||
void Shuffleboard::SetRecordingFileNameFormat(std::string_view format) {
|
||||
GetRecordingController().SetRecordingFileNameFormat(format);
|
||||
}
|
||||
|
||||
@@ -52,13 +52,13 @@ void Shuffleboard::ClearRecordingFileNameFormat() {
|
||||
GetRecordingController().ClearRecordingFileNameFormat();
|
||||
}
|
||||
|
||||
void Shuffleboard::AddEventMarker(wpi::StringRef name,
|
||||
wpi::StringRef description,
|
||||
void Shuffleboard::AddEventMarker(std::string_view name,
|
||||
std::string_view description,
|
||||
ShuffleboardEventImportance importance) {
|
||||
GetRecordingController().AddEventMarker(name, description, importance);
|
||||
}
|
||||
|
||||
void Shuffleboard::AddEventMarker(wpi::StringRef name,
|
||||
void Shuffleboard::AddEventMarker(std::string_view name,
|
||||
ShuffleboardEventImportance importance) {
|
||||
AddEventMarker(name, "", importance);
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardContainer.h"
|
||||
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/shuffleboard/ComplexWidget.h"
|
||||
#include "frc/shuffleboard/ShuffleboardComponent.h"
|
||||
@@ -70,7 +68,7 @@ ComplexWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
ComplexWidget& ShuffleboardContainer::Add(Sendable& sendable) {
|
||||
auto name = SendableRegistry::GetInstance().GetName(&sendable);
|
||||
if (name.empty()) {
|
||||
wpi::outs() << "Sendable must have a name\n";
|
||||
FRC_ReportError(err::Error, "{}", "Sendable must have a name");
|
||||
}
|
||||
return Add(name, sendable);
|
||||
}
|
||||
@@ -285,7 +283,7 @@ void ShuffleboardContainer::DisableIfActuator() {
|
||||
void ShuffleboardContainer::CheckTitle(std::string_view title) {
|
||||
std::string titleStr{title};
|
||||
if (m_usedTitles.count(titleStr) > 0) {
|
||||
wpi::errs() << "Title is already in use: " << title << "\n";
|
||||
FRC_ReportError(err::Error, "Title is already in use: {}", title);
|
||||
return;
|
||||
}
|
||||
m_usedTitles.insert(titleStr);
|
||||
|
||||
@@ -31,7 +31,7 @@ ShuffleboardInstance::ShuffleboardInstance(nt::NetworkTableInstance ntInstance)
|
||||
|
||||
ShuffleboardInstance::~ShuffleboardInstance() = default;
|
||||
|
||||
frc::ShuffleboardTab& ShuffleboardInstance::GetTab(wpi::StringRef title) {
|
||||
frc::ShuffleboardTab& ShuffleboardInstance::GetTab(std::string_view title) {
|
||||
if (m_impl->tabs.find(title) == m_impl->tabs.end()) {
|
||||
m_impl->tabs.try_emplace(title, ShuffleboardTab(*this, title));
|
||||
m_impl->tabsChanged = true;
|
||||
@@ -77,6 +77,6 @@ void ShuffleboardInstance::SelectTab(int index) {
|
||||
m_impl->rootMetaTable->GetEntry("Selected").ForceSetDouble(index);
|
||||
}
|
||||
|
||||
void ShuffleboardInstance::SelectTab(wpi::StringRef title) {
|
||||
void ShuffleboardInstance::SelectTab(std::string_view title) {
|
||||
m_impl->rootMetaTable->GetEntry("Selected").ForceSetString(title);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
ShuffleboardTab::ShuffleboardTab(ShuffleboardRoot& root, wpi::StringRef title)
|
||||
ShuffleboardTab::ShuffleboardTab(ShuffleboardRoot& root, std::string_view title)
|
||||
: ShuffleboardValue(title), ShuffleboardContainer(title), m_root(root) {}
|
||||
|
||||
ShuffleboardRoot& ShuffleboardTab::GetRoot() {
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
wpi::StringRef WidgetType::GetWidgetName() const {
|
||||
std::string_view WidgetType::GetWidgetName() const {
|
||||
return m_widgetName;
|
||||
}
|
||||
|
||||
@@ -114,9 +114,9 @@ void FieldObject2d::UpdateEntry(bool setDefault) {
|
||||
p += 8;
|
||||
}
|
||||
if (setDefault) {
|
||||
m_entry.SetDefaultRaw(wpi::StringRef{arr.data(), arr.size()});
|
||||
m_entry.SetDefaultRaw({arr.data(), arr.size()});
|
||||
} else {
|
||||
m_entry.ForceSetRaw(wpi::StringRef{arr.data(), arr.size()});
|
||||
m_entry.ForceSetRaw({arr.data(), arr.size()});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ void FieldObject2d::UpdateFromEntry() const {
|
||||
}
|
||||
} else if (val->IsRaw()) {
|
||||
// treat it simply as an array of doubles
|
||||
wpi::StringRef data = val->GetRaw();
|
||||
std::string_view data = val->GetRaw();
|
||||
|
||||
// must be triples of doubles
|
||||
auto size = data.size();
|
||||
@@ -152,7 +152,7 @@ void FieldObject2d::UpdateFromEntry() const {
|
||||
return;
|
||||
}
|
||||
m_poses.resize(size / (3 * 8));
|
||||
const char* p = data.begin();
|
||||
const char* p = data.data();
|
||||
for (size_t i = 0; i < size / (3 * 8); ++i) {
|
||||
double x = wpi::BitsToDouble(
|
||||
wpi::support::endian::readNext<uint64_t, wpi::support::big,
|
||||
|
||||
@@ -19,7 +19,8 @@ Mechanism2d::Mechanism2d(double width, double height,
|
||||
SetBackgroundColor(backgroundColor);
|
||||
}
|
||||
|
||||
MechanismRoot2d* Mechanism2d::GetRoot(wpi::StringRef name, double x, double y) {
|
||||
MechanismRoot2d* Mechanism2d::GetRoot(std::string_view name, double x,
|
||||
double y) {
|
||||
auto& obj = m_roots[name];
|
||||
if (obj) {
|
||||
return obj.get();
|
||||
|
||||
@@ -151,7 +151,7 @@ void SendableBuilderImpl::AddDoubleProperty(
|
||||
|
||||
void SendableBuilderImpl::AddStringProperty(
|
||||
std::string_view key, std::function<std::string()> getter,
|
||||
std::function<void(wpi::StringRef)> setter) {
|
||||
std::function<void(std::string_view)> setter) {
|
||||
m_properties.emplace_back(*m_table, key);
|
||||
if (getter) {
|
||||
m_properties.back().update = [=](nt::NetworkTableEntry entry,
|
||||
@@ -255,7 +255,7 @@ void SendableBuilderImpl::AddStringArrayProperty(
|
||||
|
||||
void SendableBuilderImpl::AddRawProperty(
|
||||
std::string_view key, std::function<std::string()> getter,
|
||||
std::function<void(wpi::StringRef)> setter) {
|
||||
std::function<void(std::string_view)> setter) {
|
||||
m_properties.emplace_back(*m_table, key);
|
||||
if (getter) {
|
||||
m_properties.back().update = [=](nt::NetworkTableEntry entry,
|
||||
@@ -303,8 +303,8 @@ void SendableBuilderImpl::AddValueProperty(
|
||||
|
||||
void SendableBuilderImpl::AddSmallStringProperty(
|
||||
std::string_view key,
|
||||
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(wpi::StringRef)> setter) {
|
||||
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(std::string_view)> setter) {
|
||||
m_properties.emplace_back(*m_table, key);
|
||||
if (getter) {
|
||||
m_properties.back().update = [=](nt::NetworkTableEntry entry,
|
||||
@@ -418,8 +418,8 @@ void SendableBuilderImpl::AddSmallStringArrayProperty(
|
||||
|
||||
void SendableBuilderImpl::AddSmallRawProperty(
|
||||
std::string_view key,
|
||||
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(wpi::StringRef)> setter) {
|
||||
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(std::string_view)> setter) {
|
||||
m_properties.emplace_back(*m_table, key);
|
||||
if (getter) {
|
||||
m_properties.back().update = [=](nt::NetworkTableEntry entry,
|
||||
|
||||
@@ -44,7 +44,7 @@ void SmartDashboard::init() {
|
||||
Singleton::GetInstance();
|
||||
}
|
||||
|
||||
bool SmartDashboard::ContainsKey(wpi::StringRef key) {
|
||||
bool SmartDashboard::ContainsKey(std::string_view key) {
|
||||
return Singleton::GetInstance().table->ContainsKey(key);
|
||||
}
|
||||
|
||||
@@ -52,39 +52,39 @@ std::vector<std::string> SmartDashboard::GetKeys(int types) {
|
||||
return Singleton::GetInstance().table->GetKeys(types);
|
||||
}
|
||||
|
||||
void SmartDashboard::SetPersistent(wpi::StringRef key) {
|
||||
void SmartDashboard::SetPersistent(std::string_view key) {
|
||||
Singleton::GetInstance().table->GetEntry(key).SetPersistent();
|
||||
}
|
||||
|
||||
void SmartDashboard::ClearPersistent(wpi::StringRef key) {
|
||||
void SmartDashboard::ClearPersistent(std::string_view key) {
|
||||
Singleton::GetInstance().table->GetEntry(key).ClearPersistent();
|
||||
}
|
||||
|
||||
bool SmartDashboard::IsPersistent(wpi::StringRef key) {
|
||||
bool SmartDashboard::IsPersistent(std::string_view key) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).IsPersistent();
|
||||
}
|
||||
|
||||
void SmartDashboard::SetFlags(wpi::StringRef key, unsigned int flags) {
|
||||
void SmartDashboard::SetFlags(std::string_view key, unsigned int flags) {
|
||||
Singleton::GetInstance().table->GetEntry(key).SetFlags(flags);
|
||||
}
|
||||
|
||||
void SmartDashboard::ClearFlags(wpi::StringRef key, unsigned int flags) {
|
||||
void SmartDashboard::ClearFlags(std::string_view key, unsigned int flags) {
|
||||
Singleton::GetInstance().table->GetEntry(key).ClearFlags(flags);
|
||||
}
|
||||
|
||||
unsigned int SmartDashboard::GetFlags(wpi::StringRef key) {
|
||||
unsigned int SmartDashboard::GetFlags(std::string_view key) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).GetFlags();
|
||||
}
|
||||
|
||||
void SmartDashboard::Delete(wpi::StringRef key) {
|
||||
void SmartDashboard::Delete(std::string_view key) {
|
||||
Singleton::GetInstance().table->Delete(key);
|
||||
}
|
||||
|
||||
nt::NetworkTableEntry SmartDashboard::GetEntry(wpi::StringRef key) {
|
||||
nt::NetworkTableEntry SmartDashboard::GetEntry(std::string_view key) {
|
||||
return Singleton::GetInstance().table->GetEntry(key);
|
||||
}
|
||||
|
||||
void SmartDashboard::PutData(wpi::StringRef key, Sendable* data) {
|
||||
void SmartDashboard::PutData(std::string_view key, Sendable* data) {
|
||||
if (!data) {
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "value");
|
||||
}
|
||||
@@ -111,7 +111,7 @@ void SmartDashboard::PutData(Sendable* value) {
|
||||
}
|
||||
}
|
||||
|
||||
Sendable* SmartDashboard::GetData(wpi::StringRef key) {
|
||||
Sendable* SmartDashboard::GetData(std::string_view key) {
|
||||
auto& inst = Singleton::GetInstance();
|
||||
std::scoped_lock lock(inst.tablesToDataMutex);
|
||||
auto it = inst.tablesToData.find(key);
|
||||
@@ -121,128 +121,132 @@ Sendable* SmartDashboard::GetData(wpi::StringRef key) {
|
||||
return SendableRegistry::GetInstance().GetSendable(it->getValue());
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutBoolean(wpi::StringRef keyName, bool value) {
|
||||
bool SmartDashboard::PutBoolean(std::string_view keyName, bool value) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).SetBoolean(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultBoolean(wpi::StringRef key, bool defaultValue) {
|
||||
bool SmartDashboard::SetDefaultBoolean(std::string_view key,
|
||||
bool defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultBoolean(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::GetBoolean(wpi::StringRef keyName, bool defaultValue) {
|
||||
bool SmartDashboard::GetBoolean(std::string_view keyName, bool defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).GetBoolean(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutNumber(wpi::StringRef keyName, double value) {
|
||||
bool SmartDashboard::PutNumber(std::string_view keyName, double value) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).SetDouble(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultNumber(wpi::StringRef key, double defaultValue) {
|
||||
bool SmartDashboard::SetDefaultNumber(std::string_view key,
|
||||
double defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultDouble(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
double SmartDashboard::GetNumber(wpi::StringRef keyName, double defaultValue) {
|
||||
double SmartDashboard::GetNumber(std::string_view keyName,
|
||||
double defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).GetDouble(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutString(wpi::StringRef keyName, wpi::StringRef value) {
|
||||
bool SmartDashboard::PutString(std::string_view keyName,
|
||||
std::string_view value) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).SetString(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultString(wpi::StringRef key,
|
||||
wpi::StringRef defaultValue) {
|
||||
bool SmartDashboard::SetDefaultString(std::string_view key,
|
||||
std::string_view defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultString(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
std::string SmartDashboard::GetString(wpi::StringRef keyName,
|
||||
wpi::StringRef defaultValue) {
|
||||
std::string SmartDashboard::GetString(std::string_view keyName,
|
||||
std::string_view defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).GetString(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutBooleanArray(wpi::StringRef key,
|
||||
bool SmartDashboard::PutBooleanArray(std::string_view key,
|
||||
wpi::ArrayRef<int> value) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetBooleanArray(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultBooleanArray(wpi::StringRef key,
|
||||
bool SmartDashboard::SetDefaultBooleanArray(std::string_view key,
|
||||
wpi::ArrayRef<int> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultBooleanArray(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
std::vector<int> SmartDashboard::GetBooleanArray(
|
||||
wpi::StringRef key, wpi::ArrayRef<int> defaultValue) {
|
||||
std::string_view key, wpi::ArrayRef<int> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).GetBooleanArray(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutNumberArray(wpi::StringRef key,
|
||||
bool SmartDashboard::PutNumberArray(std::string_view key,
|
||||
wpi::ArrayRef<double> value) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDoubleArray(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultNumberArray(wpi::StringRef key,
|
||||
bool SmartDashboard::SetDefaultNumberArray(std::string_view key,
|
||||
wpi::ArrayRef<double> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultDoubleArray(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
std::vector<double> SmartDashboard::GetNumberArray(
|
||||
wpi::StringRef key, wpi::ArrayRef<double> defaultValue) {
|
||||
std::string_view key, wpi::ArrayRef<double> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).GetDoubleArray(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutStringArray(wpi::StringRef key,
|
||||
bool SmartDashboard::PutStringArray(std::string_view key,
|
||||
wpi::ArrayRef<std::string> value) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetStringArray(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultStringArray(
|
||||
wpi::StringRef key, wpi::ArrayRef<std::string> defaultValue) {
|
||||
std::string_view key, wpi::ArrayRef<std::string> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultStringArray(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
std::vector<std::string> SmartDashboard::GetStringArray(
|
||||
wpi::StringRef key, wpi::ArrayRef<std::string> defaultValue) {
|
||||
std::string_view key, wpi::ArrayRef<std::string> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).GetStringArray(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutRaw(wpi::StringRef key, wpi::StringRef value) {
|
||||
bool SmartDashboard::PutRaw(std::string_view key, std::string_view value) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetRaw(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultRaw(wpi::StringRef key,
|
||||
wpi::StringRef defaultValue) {
|
||||
bool SmartDashboard::SetDefaultRaw(std::string_view key,
|
||||
std::string_view defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultRaw(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
std::string SmartDashboard::GetRaw(wpi::StringRef key,
|
||||
wpi::StringRef defaultValue) {
|
||||
std::string SmartDashboard::GetRaw(std::string_view key,
|
||||
std::string_view defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).GetRaw(defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutValue(wpi::StringRef keyName,
|
||||
bool SmartDashboard::PutValue(std::string_view keyName,
|
||||
std::shared_ptr<nt::Value> value) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).SetValue(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultValue(wpi::StringRef key,
|
||||
bool SmartDashboard::SetDefaultValue(std::string_view key,
|
||||
std::shared_ptr<nt::Value> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultValue(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
std::shared_ptr<nt::Value> SmartDashboard::GetValue(wpi::StringRef keyName) {
|
||||
std::shared_ptr<nt::Value> SmartDashboard::GetValue(std::string_view keyName) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).GetValue();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user