[wpilibc] Use std::string_view instead of Twine (#3380)

Use fmtlib where needed for string formatting into std::string_view.
This commit is contained in:
Peter Johnson
2021-05-26 17:44:18 -07:00
committed by GitHub
parent 50915cb7ed
commit 4e2c3051be
76 changed files with 387 additions and 419 deletions

View File

@@ -30,7 +30,7 @@ wpi::SmallSet<Subsystem*, 4> CommandBase::GetRequirements() const {
return m_requirements;
}
void CommandBase::SetName(const wpi::Twine& name) {
void CommandBase::SetName(std::string_view name) {
frc::SendableRegistry::GetInstance().SetName(this, name);
}
@@ -42,7 +42,7 @@ std::string CommandBase::GetSubsystem() const {
return frc::SendableRegistry::GetInstance().GetSubsystem(this);
}
void CommandBase::SetSubsystem(const wpi::Twine& subsystem) {
void CommandBase::SetSubsystem(std::string_view subsystem) {
frc::SendableRegistry::GetInstance().SetSubsystem(this, subsystem);
}

View File

@@ -8,9 +8,9 @@
using namespace frc2;
PrintCommand::PrintCommand(const wpi::Twine& message)
: CommandHelper{[str = message.str()] { wpi::outs() << str << "\n"; }, {}} {
}
PrintCommand::PrintCommand(std::string_view message)
: CommandHelper{
[str = std::string(message)] { wpi::outs() << str << "\n"; }, {}} {}
bool PrintCommand::RunsWhenDisabled() const {
return true;

View File

@@ -51,7 +51,7 @@ std::string SubsystemBase::GetName() const {
return frc::SendableRegistry::GetInstance().GetName(this);
}
void SubsystemBase::SetName(const wpi::Twine& name) {
void SubsystemBase::SetName(std::string_view name) {
frc::SendableRegistry::GetInstance().SetName(this, name);
}
@@ -59,7 +59,7 @@ std::string SubsystemBase::GetSubsystem() const {
return frc::SendableRegistry::GetInstance().GetSubsystem(this);
}
void SubsystemBase::SetSubsystem(const wpi::Twine& name) {
void SubsystemBase::SetSubsystem(std::string_view name) {
frc::SendableRegistry::GetInstance().SetSubsystem(this, name);
}

View File

@@ -4,11 +4,13 @@
#include "frc2/command/WaitCommand.h"
#include <fmt/format.h>
using namespace frc2;
WaitCommand::WaitCommand(units::second_t duration) : m_duration{duration} {
auto durationStr = std::to_string(duration.to<double>());
SetName(wpi::Twine(GetName()) + ": " + wpi::Twine(durationStr) + " seconds");
SetName(fmt::format("{}: {} seconds", GetName(), durationStr));
}
void WaitCommand::Initialize() {

View File

@@ -12,9 +12,9 @@ NetworkButton::NetworkButton(nt::NetworkTableEntry entry)
}) {}
NetworkButton::NetworkButton(std::shared_ptr<nt::NetworkTable> table,
const wpi::Twine& field)
std::string_view field)
: NetworkButton(table->GetEntry(field)) {}
NetworkButton::NetworkButton(const wpi::Twine& table, const wpi::Twine& field)
NetworkButton::NetworkButton(std::string_view table, std::string_view field)
: NetworkButton(nt::NetworkTableInstance::GetDefault().GetTable(table),
field) {}