mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +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();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,12 +30,12 @@ using namespace frc;
|
||||
|
||||
int frc::RunHALInitialization() {
|
||||
if (!HAL_Initialize(500, 0)) {
|
||||
wpi::errs() << "FATAL ERROR: HAL could not be initialized\n";
|
||||
std::puts("FATAL ERROR: HAL could not be initialized");
|
||||
return -1;
|
||||
}
|
||||
HAL_Report(HALUsageReporting::kResourceType_Language,
|
||||
HALUsageReporting::kLanguage_CPlusPlus, 0, GetWPILibVersion());
|
||||
wpi::outs() << "\n********** Robot program starting **********\n";
|
||||
std::puts("\n********** Robot program starting **********");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -124,8 +124,8 @@ static void SetupCameraServerShared() {
|
||||
#endif
|
||||
|
||||
if (!cameraServerLib) {
|
||||
wpi::outs() << "Camera Server Library Not Found\n";
|
||||
wpi::outs().flush();
|
||||
std::puts("Camera Server Library Not Found");
|
||||
std::fflush(stdout);
|
||||
return;
|
||||
}
|
||||
auto symbol = dlsym(cameraServerLib, "CameraServer_SetCameraServerShared");
|
||||
@@ -133,15 +133,15 @@ static void SetupCameraServerShared() {
|
||||
auto setCameraServerShared = (SetCameraServerSharedFP)symbol;
|
||||
setCameraServerShared(new WPILibCameraServerShared{});
|
||||
} else {
|
||||
wpi::outs() << "Camera Server Shared Symbol Missing\n";
|
||||
wpi::outs().flush();
|
||||
std::puts("Camera Server Shared Symbol Missing");
|
||||
std::fflush(stdout);
|
||||
}
|
||||
#else
|
||||
CameraServer_SetCameraServerShared(new WPILibCameraServerShared{});
|
||||
#endif
|
||||
#else
|
||||
wpi::outs() << "Not loading CameraServerShared\n";
|
||||
wpi::outs().flush();
|
||||
std::puts("Not loading CameraServerShared");
|
||||
std::fflush(stdout);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <networktables/NetworkTable.h>
|
||||
@@ -53,7 +54,8 @@ class Preferences {
|
||||
* @param defaultValue the value to return if none exists in the table
|
||||
* @return either the value in the table, or the defaultValue
|
||||
*/
|
||||
std::string GetString(wpi::StringRef key, wpi::StringRef defaultValue = "");
|
||||
std::string GetString(std::string_view key,
|
||||
std::string_view defaultValue = "");
|
||||
|
||||
/**
|
||||
* Returns the int at the given key. If this table does not have a value for
|
||||
@@ -63,7 +65,7 @@ class Preferences {
|
||||
* @param defaultValue the value to return if none exists in the table
|
||||
* @return either the value in the table, or the defaultValue
|
||||
*/
|
||||
int GetInt(wpi::StringRef key, int defaultValue = 0);
|
||||
int GetInt(std::string_view key, int defaultValue = 0);
|
||||
|
||||
/**
|
||||
* Returns the double at the given key. If this table does not have a value
|
||||
@@ -73,7 +75,7 @@ class Preferences {
|
||||
* @param defaultValue the value to return if none exists in the table
|
||||
* @return either the value in the table, or the defaultValue
|
||||
*/
|
||||
double GetDouble(wpi::StringRef key, double defaultValue = 0.0);
|
||||
double GetDouble(std::string_view key, double defaultValue = 0.0);
|
||||
|
||||
/**
|
||||
* Returns the float at the given key. If this table does not have a value
|
||||
@@ -83,7 +85,7 @@ class Preferences {
|
||||
* @param defaultValue the value to return if none exists in the table
|
||||
* @return either the value in the table, or the defaultValue
|
||||
*/
|
||||
float GetFloat(wpi::StringRef key, float defaultValue = 0.0);
|
||||
float GetFloat(std::string_view key, float defaultValue = 0.0);
|
||||
|
||||
/**
|
||||
* Returns the boolean at the given key. If this table does not have a value
|
||||
@@ -93,7 +95,7 @@ class Preferences {
|
||||
* @param defaultValue the value to return if none exists in the table
|
||||
* @return either the value in the table, or the defaultValue
|
||||
*/
|
||||
bool GetBoolean(wpi::StringRef key, bool defaultValue = false);
|
||||
bool GetBoolean(std::string_view key, bool defaultValue = false);
|
||||
|
||||
/**
|
||||
* Returns the long (int64_t) at the given key. If this table does not have a
|
||||
@@ -104,7 +106,7 @@ class Preferences {
|
||||
* @param defaultValue the value to return if none exists in the table
|
||||
* @return either the value in the table, or the defaultValue
|
||||
*/
|
||||
int64_t GetLong(wpi::StringRef key, int64_t defaultValue = 0);
|
||||
int64_t GetLong(std::string_view key, int64_t defaultValue = 0);
|
||||
|
||||
/**
|
||||
* Puts the given string into the preferences table.
|
||||
@@ -115,7 +117,7 @@ class Preferences {
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
void SetString(wpi::StringRef key, wpi::StringRef value);
|
||||
void SetString(std::string_view key, std::string_view value);
|
||||
|
||||
/**
|
||||
* Puts the given string into the preferences table.
|
||||
@@ -127,13 +129,13 @@ class Preferences {
|
||||
* @param value the value
|
||||
*/
|
||||
WPI_DEPRECATED("Use SetString instead.")
|
||||
void PutString(wpi::StringRef key, wpi::StringRef value);
|
||||
void PutString(std::string_view key, std::string_view value);
|
||||
|
||||
/**
|
||||
* Puts the given string into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitString(wpi::StringRef key, wpi::StringRef value);
|
||||
void InitString(std::string_view key, std::string_view value);
|
||||
|
||||
/**
|
||||
* Puts the given int into the preferences table.
|
||||
@@ -143,7 +145,7 @@ class Preferences {
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
void SetInt(wpi::StringRef key, int value);
|
||||
void SetInt(std::string_view key, int value);
|
||||
|
||||
/**
|
||||
* Puts the given int into the preferences table.
|
||||
@@ -154,13 +156,13 @@ class Preferences {
|
||||
* @param value the value
|
||||
*/
|
||||
WPI_DEPRECATED("Use SetInt instead.")
|
||||
void PutInt(wpi::StringRef key, int value);
|
||||
void PutInt(std::string_view key, int value);
|
||||
|
||||
/**
|
||||
* Puts the given int into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitInt(wpi::StringRef key, int value);
|
||||
void InitInt(std::string_view key, int value);
|
||||
|
||||
/**
|
||||
* Puts the given double into the preferences table.
|
||||
@@ -170,7 +172,7 @@ class Preferences {
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
void SetDouble(wpi::StringRef key, double value);
|
||||
void SetDouble(std::string_view key, double value);
|
||||
|
||||
/**
|
||||
* Puts the given double into the preferences table.
|
||||
@@ -181,13 +183,13 @@ class Preferences {
|
||||
* @param value the value
|
||||
*/
|
||||
WPI_DEPRECATED("Use SetDouble instead.")
|
||||
void PutDouble(wpi::StringRef key, double value);
|
||||
void PutDouble(std::string_view key, double value);
|
||||
|
||||
/**
|
||||
* Puts the given double into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitDouble(wpi::StringRef key, double value);
|
||||
void InitDouble(std::string_view key, double value);
|
||||
|
||||
/**
|
||||
* Puts the given float into the preferences table.
|
||||
@@ -197,7 +199,7 @@ class Preferences {
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
void SetFloat(wpi::StringRef key, float value);
|
||||
void SetFloat(std::string_view key, float value);
|
||||
|
||||
/**
|
||||
* Puts the given float into the preferences table.
|
||||
@@ -208,13 +210,13 @@ class Preferences {
|
||||
* @param value the value
|
||||
*/
|
||||
WPI_DEPRECATED("Use SetFloat instead.")
|
||||
void PutFloat(wpi::StringRef key, float value);
|
||||
void PutFloat(std::string_view key, float value);
|
||||
|
||||
/**
|
||||
* Puts the given float into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitFloat(wpi::StringRef key, float value);
|
||||
void InitFloat(std::string_view key, float value);
|
||||
|
||||
/**
|
||||
* Puts the given boolean into the preferences table.
|
||||
@@ -224,7 +226,7 @@ class Preferences {
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
void SetBoolean(wpi::StringRef key, bool value);
|
||||
void SetBoolean(std::string_view key, bool value);
|
||||
|
||||
/**
|
||||
* Puts the given boolean into the preferences table.
|
||||
@@ -235,13 +237,13 @@ class Preferences {
|
||||
* @param value the value
|
||||
*/
|
||||
WPI_DEPRECATED("Use SetBoolean instead.")
|
||||
void PutBoolean(wpi::StringRef key, bool value);
|
||||
void PutBoolean(std::string_view key, bool value);
|
||||
|
||||
/**
|
||||
* Puts the given boolean into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitBoolean(wpi::StringRef key, bool value);
|
||||
void InitBoolean(std::string_view key, bool value);
|
||||
|
||||
/**
|
||||
* Puts the given long (int64_t) into the preferences table.
|
||||
@@ -251,7 +253,7 @@ class Preferences {
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
void SetLong(wpi::StringRef key, int64_t value);
|
||||
void SetLong(std::string_view key, int64_t value);
|
||||
|
||||
/**
|
||||
* Puts the given long (int64_t) into the preferences table.
|
||||
@@ -262,13 +264,13 @@ class Preferences {
|
||||
* @param value the value
|
||||
*/
|
||||
WPI_DEPRECATED("Use SetLong instead.")
|
||||
void PutLong(wpi::StringRef key, int64_t value);
|
||||
void PutLong(std::string_view key, int64_t value);
|
||||
|
||||
/**
|
||||
* Puts the given long into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitLong(wpi::StringRef key, int64_t value);
|
||||
void InitLong(std::string_view key, int64_t value);
|
||||
|
||||
/**
|
||||
* Returns whether or not there is a key with the given name.
|
||||
@@ -276,14 +278,14 @@ class Preferences {
|
||||
* @param key the key
|
||||
* @return if there is a value at the given key
|
||||
*/
|
||||
bool ContainsKey(wpi::StringRef key);
|
||||
bool ContainsKey(std::string_view key);
|
||||
|
||||
/**
|
||||
* Remove a preference.
|
||||
*
|
||||
* @param key the key
|
||||
*/
|
||||
void Remove(wpi::StringRef key);
|
||||
void Remove(std::string_view key);
|
||||
|
||||
/**
|
||||
* Remove all preferences.
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <hal/Main.h>
|
||||
#include <wpi/condition_variable.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ class SerialPort {
|
||||
* Use Write({data, len}) to get a buffer that is shorter than the length of
|
||||
* the string.
|
||||
*
|
||||
* @param buffer StringRef to the buffer to read the bytes from.
|
||||
* @param buffer the buffer to read the bytes from.
|
||||
* @return The number of bytes actually written into the port.
|
||||
*/
|
||||
int Write(std::string_view buffer);
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <string_view>
|
||||
|
||||
#include <hal/cpp/fpga_clock.h>
|
||||
#include <wpi/StringMap.h>
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
namespace wpi {
|
||||
class raw_ostream;
|
||||
@@ -48,7 +48,7 @@ class Tracer {
|
||||
*
|
||||
* @param epochName The name to associate with the epoch.
|
||||
*/
|
||||
void AddEpoch(wpi::StringRef epochName);
|
||||
void AddEpoch(std::string_view epochName);
|
||||
|
||||
/**
|
||||
* Prints list of epochs added so far and their times to the DriverStation.
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
#include <units/time.h>
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
#include "frc/Tracer.h"
|
||||
|
||||
@@ -76,7 +76,7 @@ class Watchdog {
|
||||
*
|
||||
* @param epochName The name to associate with the epoch.
|
||||
*/
|
||||
void AddEpoch(wpi::StringRef epochName);
|
||||
void AddEpoch(std::string_view epochName);
|
||||
|
||||
/**
|
||||
* Prints list of epochs added so far and their times.
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wpi/StringRef.h>
|
||||
#include <string_view>
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -25,7 +25,7 @@ class LayoutType {
|
||||
* Gets the string type of the layout as defined by that layout in
|
||||
* Shuffleboard.
|
||||
*/
|
||||
wpi::StringRef GetLayoutName() const;
|
||||
std::string_view GetLayoutName() const;
|
||||
|
||||
private:
|
||||
const char* m_layoutName;
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardEventImportance.h"
|
||||
|
||||
@@ -23,10 +23,10 @@ class RecordingController final {
|
||||
|
||||
void StartRecording();
|
||||
void StopRecording();
|
||||
void SetRecordingFileNameFormat(wpi::StringRef format);
|
||||
void SetRecordingFileNameFormat(std::string_view format);
|
||||
void ClearRecordingFileNameFormat();
|
||||
|
||||
void AddEventMarker(wpi::StringRef name, wpi::StringRef description,
|
||||
void AddEventMarker(std::string_view name, std::string_view description,
|
||||
ShuffleboardEventImportance importance);
|
||||
|
||||
private:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wpi/StringRef.h>
|
||||
#include <string_view>
|
||||
|
||||
#include "frc/shuffleboard/RecordingController.h"
|
||||
#include "frc/shuffleboard/ShuffleboardEventImportance.h"
|
||||
@@ -77,7 +77,7 @@ class Shuffleboard final {
|
||||
* @param title the title of the tab
|
||||
* @return the tab with the given title
|
||||
*/
|
||||
static ShuffleboardTab& GetTab(wpi::StringRef title);
|
||||
static ShuffleboardTab& GetTab(std::string_view title);
|
||||
|
||||
/**
|
||||
* Selects the tab in the dashboard with the given index in the range
|
||||
@@ -93,7 +93,7 @@ class Shuffleboard final {
|
||||
*
|
||||
* @param title the title of the tab to select
|
||||
*/
|
||||
static void SelectTab(wpi::StringRef title);
|
||||
static void SelectTab(std::string_view title);
|
||||
|
||||
/**
|
||||
* Enables user control of widgets containing actuators: speed controllers,
|
||||
@@ -141,7 +141,7 @@ class Shuffleboard final {
|
||||
*
|
||||
* @param format the format for the
|
||||
*/
|
||||
static void SetRecordingFileNameFormat(wpi::StringRef format);
|
||||
static void SetRecordingFileNameFormat(std::string_view format);
|
||||
|
||||
/**
|
||||
* Clears the custom name format for recording files. New recordings will use
|
||||
@@ -163,7 +163,8 @@ class Shuffleboard final {
|
||||
* @param description a description of the event
|
||||
* @param importance the importance of the event
|
||||
*/
|
||||
static void AddEventMarker(wpi::StringRef name, wpi::StringRef description,
|
||||
static void AddEventMarker(std::string_view name,
|
||||
std::string_view description,
|
||||
ShuffleboardEventImportance importance);
|
||||
|
||||
/**
|
||||
@@ -177,7 +178,7 @@ class Shuffleboard final {
|
||||
* @param name the name of the event
|
||||
* @param importance the importance of the event
|
||||
*/
|
||||
static void AddEventMarker(wpi::StringRef name,
|
||||
static void AddEventMarker(std::string_view name,
|
||||
ShuffleboardEventImportance importance);
|
||||
|
||||
private:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wpi/StringRef.h>
|
||||
#include <string_view>
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace frc {
|
||||
|
||||
enum ShuffleboardEventImportance { kTrivial, kLow, kNormal, kHigh, kCritical };
|
||||
|
||||
inline wpi::StringRef ShuffleboardEventImportanceName(
|
||||
inline std::string_view ShuffleboardEventImportanceName(
|
||||
ShuffleboardEventImportance importance) {
|
||||
switch (importance) {
|
||||
case kTrivial:
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardRoot.h"
|
||||
#include "frc/shuffleboard/ShuffleboardTab.h"
|
||||
@@ -19,7 +20,7 @@ class ShuffleboardInstance final : public ShuffleboardRoot {
|
||||
ShuffleboardInstance(ShuffleboardInstance&&) = default;
|
||||
ShuffleboardInstance& operator=(ShuffleboardInstance&&) = default;
|
||||
|
||||
frc::ShuffleboardTab& GetTab(wpi::StringRef title) override;
|
||||
frc::ShuffleboardTab& GetTab(std::string_view title) override;
|
||||
|
||||
void Update() override;
|
||||
|
||||
@@ -29,7 +30,7 @@ class ShuffleboardInstance final : public ShuffleboardRoot {
|
||||
|
||||
void SelectTab(int index) override;
|
||||
|
||||
void SelectTab(wpi::StringRef) override;
|
||||
void SelectTab(std::string_view) override;
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wpi/StringRef.h>
|
||||
#include <string_view>
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -25,7 +25,7 @@ class ShuffleboardRoot {
|
||||
* @param title the title of the tab
|
||||
* @return the tab with the given title
|
||||
*/
|
||||
virtual ShuffleboardTab& GetTab(wpi::StringRef title) = 0;
|
||||
virtual ShuffleboardTab& GetTab(std::string_view title) = 0;
|
||||
|
||||
/**
|
||||
* Updates all tabs.
|
||||
@@ -57,7 +57,7 @@ class ShuffleboardRoot {
|
||||
*
|
||||
* @param title the title of the tab to select
|
||||
*/
|
||||
virtual void SelectTab(wpi::StringRef title) = 0;
|
||||
virtual void SelectTab(std::string_view title) = 0;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardContainer.h"
|
||||
|
||||
@@ -24,7 +24,7 @@ class ShuffleboardRoot;
|
||||
*/
|
||||
class ShuffleboardTab final : public ShuffleboardContainer {
|
||||
public:
|
||||
ShuffleboardTab(ShuffleboardRoot& root, wpi::StringRef title);
|
||||
ShuffleboardTab(ShuffleboardRoot& root, std::string_view title);
|
||||
|
||||
ShuffleboardRoot& GetRoot();
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wpi/StringRef.h>
|
||||
#include <string_view>
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -25,7 +25,7 @@ class WidgetType {
|
||||
* Gets the string type of the widget as defined by that widget in
|
||||
* Shuffleboard.
|
||||
*/
|
||||
wpi::StringRef GetWidgetName() const;
|
||||
std::string_view GetWidgetName() const;
|
||||
|
||||
private:
|
||||
const char* m_widgetName;
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <string_view>
|
||||
|
||||
#include <hal/Value.h>
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
namespace frc::sim {
|
||||
|
||||
using NotifyCallback = std::function<void(wpi::StringRef, const HAL_Value*)>;
|
||||
using NotifyCallback = std::function<void(std::string_view, const HAL_Value*)>;
|
||||
using ConstBufferCallback = std::function<void(
|
||||
wpi::StringRef, const unsigned char* buffer, unsigned int count)>;
|
||||
std::string_view, const unsigned char* buffer, unsigned int count)>;
|
||||
using CancelCallbackFunc = void (*)(int32_t index, int32_t uid);
|
||||
using CancelCallbackNoIndexFunc = void (*)(int32_t uid);
|
||||
using CancelCallbackChannelFunc = void (*)(int32_t index, int32_t channel,
|
||||
|
||||
@@ -59,7 +59,7 @@ class Mechanism2d : public Sendable, public SendableHelper<Mechanism2d> {
|
||||
* @param y the root y coordinate
|
||||
* @return a new root object, or the existing one with the given name.
|
||||
*/
|
||||
MechanismRoot2d* GetRoot(wpi::StringRef name, double x, double y);
|
||||
MechanismRoot2d* GetRoot(std::string_view name, double x, double y);
|
||||
|
||||
/**
|
||||
* Set the Mechanism2d background color.
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <wpi/StringMap.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
@@ -63,13 +65,14 @@ class MechanismObject2d {
|
||||
template <typename T, typename... Args,
|
||||
typename =
|
||||
std::enable_if_t<std::is_convertible_v<T*, MechanismObject2d*>>>
|
||||
T* Append(wpi::StringRef name, Args&&... args) {
|
||||
T* Append(std::string_view name, Args&&... args) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
auto& obj = m_objects[name];
|
||||
if (obj) {
|
||||
throw std::runtime_error(("MechanismObject names must be unique! `" +
|
||||
name + "` was inserted twice!")
|
||||
.str());
|
||||
throw FRC_MakeError(
|
||||
err::Error,
|
||||
"MechanismObject names must be unique! `{}` was inserted twice!",
|
||||
name);
|
||||
}
|
||||
obj = std::make_unique<T>(name, std::forward<Args>(args)...);
|
||||
T* ex = static_cast<T*>(obj.get());
|
||||
|
||||
@@ -96,7 +96,7 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddStringProperty(
|
||||
std::string_view key, std::function<std::string()> getter,
|
||||
std::function<void(wpi::StringRef)> setter) = 0;
|
||||
std::function<void(std::string_view)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a boolean array property.
|
||||
@@ -140,7 +140,7 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddRawProperty(std::string_view key,
|
||||
std::function<std::string()> getter,
|
||||
std::function<void(wpi::StringRef)> setter) = 0;
|
||||
std::function<void(std::string_view)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a NetworkTableValue property.
|
||||
@@ -162,8 +162,8 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddSmallStringProperty(
|
||||
std::string_view key,
|
||||
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(wpi::StringRef)> setter) = 0;
|
||||
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(std::string_view)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a boolean array property (SmallVector form).
|
||||
@@ -213,8 +213,8 @@ class SendableBuilder {
|
||||
*/
|
||||
virtual void AddSmallRawProperty(
|
||||
std::string_view key,
|
||||
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(wpi::StringRef)> setter) = 0;
|
||||
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(std::string_view)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Get the network table.
|
||||
|
||||
@@ -100,7 +100,7 @@ class SendableBuilderImpl : public SendableBuilder {
|
||||
|
||||
void AddStringProperty(std::string_view key,
|
||||
std::function<std::string()> getter,
|
||||
std::function<void(wpi::StringRef)> setter) override;
|
||||
std::function<void(std::string_view)> setter) override;
|
||||
|
||||
void AddBooleanArrayProperty(
|
||||
std::string_view key, std::function<std::vector<int>()> getter,
|
||||
@@ -115,7 +115,7 @@ class SendableBuilderImpl : public SendableBuilder {
|
||||
std::function<void(wpi::ArrayRef<std::string>)> setter) override;
|
||||
|
||||
void AddRawProperty(std::string_view key, std::function<std::string()> getter,
|
||||
std::function<void(wpi::StringRef)> setter) override;
|
||||
std::function<void(std::string_view)> setter) override;
|
||||
|
||||
void AddValueProperty(
|
||||
std::string_view key, std::function<std::shared_ptr<nt::Value>()> getter,
|
||||
@@ -123,8 +123,8 @@ class SendableBuilderImpl : public SendableBuilder {
|
||||
|
||||
void AddSmallStringProperty(
|
||||
std::string_view key,
|
||||
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(wpi::StringRef)> setter) override;
|
||||
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(std::string_view)> setter) override;
|
||||
|
||||
void AddSmallBooleanArrayProperty(
|
||||
std::string_view key,
|
||||
@@ -146,8 +146,8 @@ class SendableBuilderImpl : public SendableBuilder {
|
||||
|
||||
void AddSmallRawProperty(
|
||||
std::string_view key,
|
||||
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(wpi::StringRef)> setter) override;
|
||||
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(std::string_view)> setter) override;
|
||||
|
||||
private:
|
||||
struct Property {
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
#include <wpi/StringMap.h>
|
||||
#include <wpi/StringRef.h>
|
||||
#include <wpi/deprecated.h>
|
||||
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
@@ -56,7 +56,7 @@ class SendableChooser : public SendableChooserBase {
|
||||
* @param name the name of the option
|
||||
* @param object the option
|
||||
*/
|
||||
void AddOption(wpi::StringRef name, T object);
|
||||
void AddOption(std::string_view name, T object);
|
||||
|
||||
/**
|
||||
* Add the given object to the list of options and marks it as the default.
|
||||
@@ -67,7 +67,7 @@ class SendableChooser : public SendableChooserBase {
|
||||
* @param name the name of the option
|
||||
* @param object the option
|
||||
*/
|
||||
void SetDefaultOption(wpi::StringRef name, T object);
|
||||
void SetDefaultOption(std::string_view name, T object);
|
||||
|
||||
/**
|
||||
* Adds the given object to the list of options.
|
||||
@@ -75,13 +75,13 @@ class SendableChooser : public SendableChooserBase {
|
||||
* On the SmartDashboard on the desktop, the object will appear as the given
|
||||
* name.
|
||||
*
|
||||
* @deprecated use AddOption(wpi::StringRef name, T object) instead.
|
||||
* @deprecated use AddOption(std::string_view name, T object) instead.
|
||||
*
|
||||
* @param name the name of the option
|
||||
* @param object the option
|
||||
*/
|
||||
WPI_DEPRECATED("use AddOption() instead")
|
||||
void AddObject(wpi::StringRef name, T object) { AddOption(name, object); }
|
||||
void AddObject(std::string_view name, T object) { AddOption(name, object); }
|
||||
|
||||
/**
|
||||
* Add the given object to the list of options and marks it as the default.
|
||||
@@ -89,13 +89,13 @@ class SendableChooser : public SendableChooserBase {
|
||||
* Functionally, this is very close to AddOption() except that it will use
|
||||
* this as the default option if none other is explicitly selected.
|
||||
*
|
||||
* @deprecated use SetDefaultOption(wpi::StringRef name, T object) instead.
|
||||
* @deprecated use SetDefaultOption(std::string_view name, T object) instead.
|
||||
*
|
||||
* @param name the name of the option
|
||||
* @param object the option
|
||||
*/
|
||||
WPI_DEPRECATED("use SetDefaultOption() instead")
|
||||
void AddDefault(wpi::StringRef name, T object) {
|
||||
void AddDefault(std::string_view name, T object) {
|
||||
SetDefaultOption(name, object);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,22 +7,21 @@
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
#include "frc/smartdashboard/SendableChooser.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
template <class T>
|
||||
void SendableChooser<T>::AddOption(wpi::StringRef name, T object) {
|
||||
void SendableChooser<T>::AddOption(std::string_view name, T object) {
|
||||
m_choices[name] = std::move(object);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void SendableChooser<T>::SetDefaultOption(wpi::StringRef name, T object) {
|
||||
void SendableChooser<T>::SetDefaultOption(std::string_view name, T object) {
|
||||
m_defaultChoice = name;
|
||||
AddOption(name, std::move(object));
|
||||
}
|
||||
@@ -53,7 +52,7 @@ void SendableChooser<T>::InitSendable(SendableBuilder& builder) {
|
||||
[=]() {
|
||||
std::vector<std::string> keys;
|
||||
for (const auto& choice : m_choices) {
|
||||
keys.push_back(choice.first());
|
||||
keys.emplace_back(choice.first());
|
||||
}
|
||||
|
||||
// Unlike std::map, wpi::StringMap elements
|
||||
@@ -65,17 +64,17 @@ void SendableChooser<T>::InitSendable(SendableBuilder& builder) {
|
||||
nullptr);
|
||||
builder.AddSmallStringProperty(
|
||||
kDefault,
|
||||
[=](wpi::SmallVectorImpl<char>&) -> wpi::StringRef {
|
||||
[=](wpi::SmallVectorImpl<char>&) -> std::string_view {
|
||||
return m_defaultChoice;
|
||||
},
|
||||
nullptr);
|
||||
builder.AddSmallStringProperty(
|
||||
kActive,
|
||||
[=](wpi::SmallVectorImpl<char>& buf) -> wpi::StringRef {
|
||||
[=](wpi::SmallVectorImpl<char>& buf) -> std::string_view {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
if (m_haveSelected) {
|
||||
buf.assign(m_selected.begin(), m_selected.end());
|
||||
return wpi::StringRef(buf.data(), buf.size());
|
||||
return {buf.data(), buf.size()};
|
||||
} else {
|
||||
return m_defaultChoice;
|
||||
}
|
||||
@@ -85,7 +84,7 @@ void SendableChooser<T>::InitSendable(SendableBuilder& builder) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
m_activeEntries.emplace_back(builder.GetEntry(kActive));
|
||||
}
|
||||
builder.AddStringProperty(kSelected, nullptr, [=](wpi::StringRef val) {
|
||||
builder.AddStringProperty(kSelected, nullptr, [=](std::string_view val) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
m_haveSelected = true;
|
||||
m_selected = val;
|
||||
|
||||
@@ -298,8 +298,8 @@ class SendableRegistry {
|
||||
* Data passed to ForeachLiveWindow() callback function
|
||||
*/
|
||||
struct CallbackData {
|
||||
CallbackData(Sendable* sendable_, wpi::StringRef name_,
|
||||
wpi::StringRef subsystem_, Sendable* parent_,
|
||||
CallbackData(Sendable* sendable_, std::string_view name_,
|
||||
std::string_view subsystem_, Sendable* parent_,
|
||||
std::shared_ptr<void>& data_, SendableBuilderImpl& builder_)
|
||||
: sendable(sendable_),
|
||||
name(name_),
|
||||
@@ -309,8 +309,8 @@ class SendableRegistry {
|
||||
builder(builder_) {}
|
||||
|
||||
Sendable* sendable;
|
||||
wpi::StringRef name;
|
||||
wpi::StringRef subsystem;
|
||||
std::string_view name;
|
||||
std::string_view subsystem;
|
||||
Sendable* parent;
|
||||
std::shared_ptr<void>& data;
|
||||
SendableBuilderImpl& builder;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <networktables/NetworkTableEntry.h>
|
||||
@@ -27,7 +28,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param key the key to search for
|
||||
* @return true if the table as a value assigned to the given key
|
||||
*/
|
||||
static bool ContainsKey(wpi::StringRef key);
|
||||
static bool ContainsKey(std::string_view key);
|
||||
|
||||
/**
|
||||
* @param types bitmask of types; 0 is treated as a "don't care".
|
||||
@@ -40,7 +41,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
*
|
||||
* @param key the key to make persistent
|
||||
*/
|
||||
static void SetPersistent(wpi::StringRef key);
|
||||
static void SetPersistent(std::string_view key);
|
||||
|
||||
/**
|
||||
* Stop making a key's value persistent through program restarts.
|
||||
@@ -48,7 +49,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
*
|
||||
* @param key the key name
|
||||
*/
|
||||
static void ClearPersistent(wpi::StringRef key);
|
||||
static void ClearPersistent(std::string_view key);
|
||||
|
||||
/**
|
||||
* Returns whether the value is persistent through program restarts.
|
||||
@@ -56,7 +57,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
*
|
||||
* @param key the key name
|
||||
*/
|
||||
static bool IsPersistent(wpi::StringRef key);
|
||||
static bool IsPersistent(std::string_view key);
|
||||
|
||||
/**
|
||||
* Sets flags on the specified key in this table. The key can
|
||||
@@ -65,7 +66,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param key the key name
|
||||
* @param flags the flags to set (bitmask)
|
||||
*/
|
||||
static void SetFlags(wpi::StringRef key, unsigned int flags);
|
||||
static void SetFlags(std::string_view key, unsigned int flags);
|
||||
|
||||
/**
|
||||
* Clears flags on the specified key in this table. The key can
|
||||
@@ -74,7 +75,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param key the key name
|
||||
* @param flags the flags to clear (bitmask)
|
||||
*/
|
||||
static void ClearFlags(wpi::StringRef key, unsigned int flags);
|
||||
static void ClearFlags(std::string_view key, unsigned int flags);
|
||||
|
||||
/**
|
||||
* Returns the flags for the specified key.
|
||||
@@ -82,14 +83,14 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param key the key name
|
||||
* @return the flags, or 0 if the key is not defined
|
||||
*/
|
||||
static unsigned int GetFlags(wpi::StringRef key);
|
||||
static unsigned int GetFlags(std::string_view key);
|
||||
|
||||
/**
|
||||
* Deletes the specified key in this table.
|
||||
*
|
||||
* @param key the key name
|
||||
*/
|
||||
static void Delete(wpi::StringRef key);
|
||||
static void Delete(std::string_view key);
|
||||
|
||||
/**
|
||||
* Returns an NT Entry mapping to the specified key
|
||||
@@ -99,7 +100,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param key the key
|
||||
* @return the entry for the key
|
||||
*/
|
||||
static nt::NetworkTableEntry GetEntry(wpi::StringRef key);
|
||||
static nt::NetworkTableEntry GetEntry(std::string_view key);
|
||||
|
||||
/**
|
||||
* Maps the specified key to the specified value in this table.
|
||||
@@ -113,7 +114,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param keyName the key
|
||||
* @param value the value
|
||||
*/
|
||||
static void PutData(wpi::StringRef key, Sendable* data);
|
||||
static void PutData(std::string_view key, Sendable* data);
|
||||
|
||||
/**
|
||||
* Maps the specified key (where the key is the name of the Sendable)
|
||||
@@ -135,7 +136,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param keyName the key
|
||||
* @return the value
|
||||
*/
|
||||
static Sendable* GetData(wpi::StringRef keyName);
|
||||
static Sendable* GetData(std::string_view keyName);
|
||||
|
||||
/**
|
||||
* Maps the specified key to the specified value in this table.
|
||||
@@ -147,7 +148,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param value the value
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
static bool PutBoolean(wpi::StringRef keyName, bool value);
|
||||
static bool PutBoolean(std::string_view keyName, bool value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -155,7 +156,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
static bool SetDefaultBoolean(wpi::StringRef key, bool defaultValue);
|
||||
static bool SetDefaultBoolean(std::string_view key, bool defaultValue);
|
||||
|
||||
/**
|
||||
* Returns the value at the specified key.
|
||||
@@ -165,7 +166,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param keyName the key
|
||||
* @return the value
|
||||
*/
|
||||
static bool GetBoolean(wpi::StringRef keyName, bool defaultValue);
|
||||
static bool GetBoolean(std::string_view keyName, bool defaultValue);
|
||||
|
||||
/**
|
||||
* Maps the specified key to the specified value in this table.
|
||||
@@ -177,7 +178,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param value the value
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
static bool PutNumber(wpi::StringRef keyName, double value);
|
||||
static bool PutNumber(std::string_view keyName, double value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -186,7 +187,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param defaultValue The default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
static bool SetDefaultNumber(wpi::StringRef key, double defaultValue);
|
||||
static bool SetDefaultNumber(std::string_view key, double defaultValue);
|
||||
|
||||
/**
|
||||
* Returns the value at the specified key.
|
||||
@@ -196,7 +197,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param keyName the key
|
||||
* @return the value
|
||||
*/
|
||||
static double GetNumber(wpi::StringRef keyName, double defaultValue);
|
||||
static double GetNumber(std::string_view keyName, double defaultValue);
|
||||
|
||||
/**
|
||||
* Maps the specified key to the specified value in this table.
|
||||
@@ -208,7 +209,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param value the value
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
static bool PutString(wpi::StringRef keyName, wpi::StringRef value);
|
||||
static bool PutString(std::string_view keyName, std::string_view value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -217,7 +218,8 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
static bool SetDefaultString(wpi::StringRef key, wpi::StringRef defaultValue);
|
||||
static bool SetDefaultString(std::string_view key,
|
||||
std::string_view defaultValue);
|
||||
|
||||
/**
|
||||
* Returns the value at the specified key.
|
||||
@@ -227,8 +229,8 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param keyName the key
|
||||
* @return the value
|
||||
*/
|
||||
static std::string GetString(wpi::StringRef keyName,
|
||||
wpi::StringRef defaultValue);
|
||||
static std::string GetString(std::string_view keyName,
|
||||
std::string_view defaultValue);
|
||||
|
||||
/**
|
||||
* Put a boolean array in the table.
|
||||
@@ -241,7 +243,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* std::vector<bool> is special-cased in C++. 0 is false, any
|
||||
* non-zero value is true.
|
||||
*/
|
||||
static bool PutBooleanArray(wpi::StringRef key, wpi::ArrayRef<int> value);
|
||||
static bool PutBooleanArray(std::string_view key, wpi::ArrayRef<int> value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -250,7 +252,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param defaultValue the default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
static bool SetDefaultBooleanArray(wpi::StringRef key,
|
||||
static bool SetDefaultBooleanArray(std::string_view key,
|
||||
wpi::ArrayRef<int> defaultValue);
|
||||
|
||||
/**
|
||||
@@ -271,7 +273,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* because std::vector<bool> is special-cased in C++. 0 is false, any
|
||||
* non-zero value is true.
|
||||
*/
|
||||
static std::vector<int> GetBooleanArray(wpi::StringRef key,
|
||||
static std::vector<int> GetBooleanArray(std::string_view key,
|
||||
wpi::ArrayRef<int> defaultValue);
|
||||
|
||||
/**
|
||||
@@ -281,7 +283,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param value The value that will be assigned.
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
static bool PutNumberArray(wpi::StringRef key, wpi::ArrayRef<double> value);
|
||||
static bool PutNumberArray(std::string_view key, wpi::ArrayRef<double> value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -290,7 +292,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param defaultValue The default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
static bool SetDefaultNumberArray(wpi::StringRef key,
|
||||
static bool SetDefaultNumberArray(std::string_view key,
|
||||
wpi::ArrayRef<double> defaultValue);
|
||||
|
||||
/**
|
||||
@@ -307,7 +309,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @note This makes a copy of the array. If the overhead of this is a concern,
|
||||
* use GetValue() instead.
|
||||
*/
|
||||
static std::vector<double> GetNumberArray(wpi::StringRef key,
|
||||
static std::vector<double> GetNumberArray(std::string_view key,
|
||||
wpi::ArrayRef<double> defaultValue);
|
||||
|
||||
/**
|
||||
@@ -317,7 +319,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param value The value that will be assigned.
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
static bool PutStringArray(wpi::StringRef key,
|
||||
static bool PutStringArray(std::string_view key,
|
||||
wpi::ArrayRef<std::string> value);
|
||||
|
||||
/**
|
||||
@@ -327,7 +329,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param defaultValue The default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
static bool SetDefaultStringArray(wpi::StringRef key,
|
||||
static bool SetDefaultStringArray(std::string_view key,
|
||||
wpi::ArrayRef<std::string> defaultValue);
|
||||
|
||||
/**
|
||||
@@ -345,7 +347,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* use GetValue() instead.
|
||||
*/
|
||||
static std::vector<std::string> GetStringArray(
|
||||
wpi::StringRef key, wpi::ArrayRef<std::string> defaultValue);
|
||||
std::string_view key, wpi::ArrayRef<std::string> defaultValue);
|
||||
|
||||
/**
|
||||
* Put a raw value (byte array) in the table.
|
||||
@@ -354,7 +356,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param value The value that will be assigned.
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
static bool PutRaw(wpi::StringRef key, wpi::StringRef value);
|
||||
static bool PutRaw(std::string_view key, std::string_view value);
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -363,7 +365,8 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param defaultValue The default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
static bool SetDefaultRaw(wpi::StringRef key, wpi::StringRef defaultValue);
|
||||
static bool SetDefaultRaw(std::string_view key,
|
||||
std::string_view defaultValue);
|
||||
|
||||
/**
|
||||
* Returns the raw value (byte array) the key maps to.
|
||||
@@ -379,7 +382,8 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @note This makes a copy of the raw contents. If the overhead of this is a
|
||||
* concern, use GetValue() instead.
|
||||
*/
|
||||
static std::string GetRaw(wpi::StringRef key, wpi::StringRef defaultValue);
|
||||
static std::string GetRaw(std::string_view key,
|
||||
std::string_view defaultValue);
|
||||
|
||||
/**
|
||||
* Maps the specified key to the specified complex value (such as an array) in
|
||||
@@ -392,7 +396,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param value the value
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
static bool PutValue(wpi::StringRef keyName,
|
||||
static bool PutValue(std::string_view keyName,
|
||||
std::shared_ptr<nt::Value> value);
|
||||
|
||||
/**
|
||||
@@ -402,7 +406,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param defaultValue The default value to set if key doesn't exist.
|
||||
* @returns False if the table key exists with a different type
|
||||
*/
|
||||
static bool SetDefaultValue(wpi::StringRef key,
|
||||
static bool SetDefaultValue(std::string_view key,
|
||||
std::shared_ptr<nt::Value> defaultValue);
|
||||
|
||||
/**
|
||||
@@ -412,7 +416,7 @@ class SmartDashboard : public Sendable, public SendableHelper<SmartDashboard> {
|
||||
* @param keyName the key
|
||||
* @param value the object to retrieve the value into
|
||||
*/
|
||||
static std::shared_ptr<nt::Value> GetValue(wpi::StringRef keyName);
|
||||
static std::shared_ptr<nt::Value> GetValue(std::string_view keyName);
|
||||
|
||||
/**
|
||||
* Posts a task from a listener to the ListenerExecutor, so that it can be run
|
||||
|
||||
Reference in New Issue
Block a user