From ab137abab5edf5a9e31536268f2a10d80df5bb92 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 1 Dec 2017 20:50:35 -0800 Subject: [PATCH] Use llvm::Twine across C++ Command structure. --- wpilibc/src/main/native/cpp/Buttons/NetworkButton.cpp | 5 +++-- wpilibc/src/main/native/cpp/Commands/CommandGroup.cpp | 2 +- .../src/main/native/cpp/Commands/ConditionalCommand.cpp | 2 +- wpilibc/src/main/native/cpp/Commands/InstantCommand.cpp | 2 +- wpilibc/src/main/native/cpp/Commands/PIDCommand.cpp | 6 +++--- wpilibc/src/main/native/cpp/Commands/PIDSubsystem.cpp | 6 +++--- wpilibc/src/main/native/cpp/Commands/PrintCommand.cpp | 8 ++++---- wpilibc/src/main/native/cpp/Commands/TimedCommand.cpp | 2 +- wpilibc/src/main/native/cpp/Commands/WaitCommand.cpp | 2 +- wpilibc/src/main/native/cpp/Commands/WaitForChildren.cpp | 2 +- .../src/main/native/cpp/Commands/WaitUntilCommand.cpp | 2 +- wpilibc/src/main/native/include/Buttons/NetworkButton.h | 7 ++++--- wpilibc/src/main/native/include/Commands/CommandGroup.h | 5 +++-- .../main/native/include/Commands/ConditionalCommand.h | 4 ++-- .../src/main/native/include/Commands/InstantCommand.h | 4 ++-- wpilibc/src/main/native/include/Commands/PIDCommand.h | 9 +++++---- wpilibc/src/main/native/include/Commands/PIDSubsystem.h | 9 +++++---- wpilibc/src/main/native/include/Commands/PrintCommand.h | 4 +++- wpilibc/src/main/native/include/Commands/TimedCommand.h | 4 ++-- wpilibc/src/main/native/include/Commands/WaitCommand.h | 4 ++-- .../src/main/native/include/Commands/WaitForChildren.h | 4 ++-- .../src/main/native/include/Commands/WaitUntilCommand.h | 4 ++-- 22 files changed, 52 insertions(+), 45 deletions(-) diff --git a/wpilibc/src/main/native/cpp/Buttons/NetworkButton.cpp b/wpilibc/src/main/native/cpp/Buttons/NetworkButton.cpp index 34d646481a..ac66f9a856 100644 --- a/wpilibc/src/main/native/cpp/Buttons/NetworkButton.cpp +++ b/wpilibc/src/main/native/cpp/Buttons/NetworkButton.cpp @@ -12,12 +12,13 @@ using namespace frc; -NetworkButton::NetworkButton(llvm::StringRef tableName, llvm::StringRef field) +NetworkButton::NetworkButton(const llvm::Twine& tableName, + const llvm::Twine& field) : NetworkButton(nt::NetworkTableInstance::GetDefault().GetTable(tableName), field) {} NetworkButton::NetworkButton(std::shared_ptr table, - llvm::StringRef field) + const llvm::Twine& field) : m_entry(table->GetEntry(field)) {} bool NetworkButton::Get() { diff --git a/wpilibc/src/main/native/cpp/Commands/CommandGroup.cpp b/wpilibc/src/main/native/cpp/Commands/CommandGroup.cpp index d5e796f46d..8ccb89475a 100644 --- a/wpilibc/src/main/native/cpp/Commands/CommandGroup.cpp +++ b/wpilibc/src/main/native/cpp/Commands/CommandGroup.cpp @@ -16,7 +16,7 @@ using namespace frc; * * @param name The name for this command group */ -CommandGroup::CommandGroup(const std::string& name) : Command(name) {} +CommandGroup::CommandGroup(const llvm::Twine& name) : Command(name) {} /** * Adds a new Command to the group. The Command will be started after all the diff --git a/wpilibc/src/main/native/cpp/Commands/ConditionalCommand.cpp b/wpilibc/src/main/native/cpp/Commands/ConditionalCommand.cpp index 576994342e..752ea8f03e 100644 --- a/wpilibc/src/main/native/cpp/Commands/ConditionalCommand.cpp +++ b/wpilibc/src/main/native/cpp/Commands/ConditionalCommand.cpp @@ -42,7 +42,7 @@ ConditionalCommand::ConditionalCommand(Command* onTrue, Command* onFalse) { * @param onTrue The Command to execute if Condition() returns true * @param onFalse The Command to execute if Condition() returns false */ -ConditionalCommand::ConditionalCommand(const std::string& name, Command* onTrue, +ConditionalCommand::ConditionalCommand(const llvm::Twine& name, Command* onTrue, Command* onFalse) : Command(name) { m_onTrue = onTrue; diff --git a/wpilibc/src/main/native/cpp/Commands/InstantCommand.cpp b/wpilibc/src/main/native/cpp/Commands/InstantCommand.cpp index a9a6a67bdb..341af85c88 100644 --- a/wpilibc/src/main/native/cpp/Commands/InstantCommand.cpp +++ b/wpilibc/src/main/native/cpp/Commands/InstantCommand.cpp @@ -14,6 +14,6 @@ using namespace frc; * * @param name The name for this command */ -InstantCommand::InstantCommand(const std::string& name) : Command(name) {} +InstantCommand::InstantCommand(const llvm::Twine& name) : Command(name) {} bool InstantCommand::IsFinished() { return true; } diff --git a/wpilibc/src/main/native/cpp/Commands/PIDCommand.cpp b/wpilibc/src/main/native/cpp/Commands/PIDCommand.cpp index 28eb5f2bcc..a0a294f1bf 100644 --- a/wpilibc/src/main/native/cpp/Commands/PIDCommand.cpp +++ b/wpilibc/src/main/native/cpp/Commands/PIDCommand.cpp @@ -11,7 +11,7 @@ using namespace frc; -PIDCommand::PIDCommand(const std::string& name, double p, double i, double d, +PIDCommand::PIDCommand(const llvm::Twine& name, double p, double i, double d, double f, double period) : Command(name) { m_controller = std::make_shared(p, i, d, this, this, period); @@ -22,12 +22,12 @@ PIDCommand::PIDCommand(double p, double i, double d, double f, double period) { std::make_shared(p, i, d, f, this, this, period); } -PIDCommand::PIDCommand(const std::string& name, double p, double i, double d) +PIDCommand::PIDCommand(const llvm::Twine& name, double p, double i, double d) : Command(name) { m_controller = std::make_shared(p, i, d, this, this); } -PIDCommand::PIDCommand(const std::string& name, double p, double i, double d, +PIDCommand::PIDCommand(const llvm::Twine& name, double p, double i, double d, double period) : Command(name) { m_controller = std::make_shared(p, i, d, this, this, period); diff --git a/wpilibc/src/main/native/cpp/Commands/PIDSubsystem.cpp b/wpilibc/src/main/native/cpp/Commands/PIDSubsystem.cpp index eeabf7fbf6..eec0152de5 100644 --- a/wpilibc/src/main/native/cpp/Commands/PIDSubsystem.cpp +++ b/wpilibc/src/main/native/cpp/Commands/PIDSubsystem.cpp @@ -19,7 +19,7 @@ using namespace frc; * @param i the integral value * @param d the derivative value */ -PIDSubsystem::PIDSubsystem(const std::string& name, double p, double i, +PIDSubsystem::PIDSubsystem(const llvm::Twine& name, double p, double i, double d) : Subsystem(name) { m_controller = std::make_shared(p, i, d, this, this); @@ -35,7 +35,7 @@ PIDSubsystem::PIDSubsystem(const std::string& name, double p, double i, * @param d the derivative value * @param f the feedforward value */ -PIDSubsystem::PIDSubsystem(const std::string& name, double p, double i, +PIDSubsystem::PIDSubsystem(const llvm::Twine& name, double p, double i, double d, double f) : Subsystem(name) { m_controller = std::make_shared(p, i, d, f, this, this); @@ -55,7 +55,7 @@ PIDSubsystem::PIDSubsystem(const std::string& name, double p, double i, * @param f the feedfoward value * @param period the time (in seconds) between calculations */ -PIDSubsystem::PIDSubsystem(const std::string& name, double p, double i, +PIDSubsystem::PIDSubsystem(const llvm::Twine& name, double p, double i, double d, double f, double period) : Subsystem(name) { m_controller = diff --git a/wpilibc/src/main/native/cpp/Commands/PrintCommand.cpp b/wpilibc/src/main/native/cpp/Commands/PrintCommand.cpp index d89871b911..6b5093d52a 100644 --- a/wpilibc/src/main/native/cpp/Commands/PrintCommand.cpp +++ b/wpilibc/src/main/native/cpp/Commands/PrintCommand.cpp @@ -11,9 +11,9 @@ using namespace frc; -PrintCommand::PrintCommand(const std::string& message) - : InstantCommand("Print \"" + message + "\"") { - m_message = message; +PrintCommand::PrintCommand(const llvm::Twine& message) + : InstantCommand("Print \"" + message + llvm::Twine('"')) { + m_message = message.str(); } -void PrintCommand::Initialize() { llvm::outs() << m_message << "\n"; } +void PrintCommand::Initialize() { llvm::outs() << m_message << '\n'; } diff --git a/wpilibc/src/main/native/cpp/Commands/TimedCommand.cpp b/wpilibc/src/main/native/cpp/Commands/TimedCommand.cpp index 0a7148605b..dbc58ab0dd 100644 --- a/wpilibc/src/main/native/cpp/Commands/TimedCommand.cpp +++ b/wpilibc/src/main/native/cpp/Commands/TimedCommand.cpp @@ -15,7 +15,7 @@ using namespace frc; * @param name the name of the command * @param timeout the time (in seconds) before this command "times out" */ -TimedCommand::TimedCommand(const std::string& name, double timeout) +TimedCommand::TimedCommand(const llvm::Twine& name, double timeout) : Command(name, timeout) {} /** diff --git a/wpilibc/src/main/native/cpp/Commands/WaitCommand.cpp b/wpilibc/src/main/native/cpp/Commands/WaitCommand.cpp index 2930d67a9a..972e30c10a 100644 --- a/wpilibc/src/main/native/cpp/Commands/WaitCommand.cpp +++ b/wpilibc/src/main/native/cpp/Commands/WaitCommand.cpp @@ -23,5 +23,5 @@ WaitCommand::WaitCommand(double timeout) * * @param timeout the time (in seconds) before this command "times out" */ -WaitCommand::WaitCommand(const std::string& name, double timeout) +WaitCommand::WaitCommand(const llvm::Twine& name, double timeout) : TimedCommand(name, timeout) {} diff --git a/wpilibc/src/main/native/cpp/Commands/WaitForChildren.cpp b/wpilibc/src/main/native/cpp/Commands/WaitForChildren.cpp index c8c0bcacc2..1ff16e48d5 100644 --- a/wpilibc/src/main/native/cpp/Commands/WaitForChildren.cpp +++ b/wpilibc/src/main/native/cpp/Commands/WaitForChildren.cpp @@ -14,7 +14,7 @@ using namespace frc; WaitForChildren::WaitForChildren(double timeout) : Command("WaitForChildren", timeout) {} -WaitForChildren::WaitForChildren(const std::string& name, double timeout) +WaitForChildren::WaitForChildren(const llvm::Twine& name, double timeout) : Command(name, timeout) {} bool WaitForChildren::IsFinished() { diff --git a/wpilibc/src/main/native/cpp/Commands/WaitUntilCommand.cpp b/wpilibc/src/main/native/cpp/Commands/WaitUntilCommand.cpp index 301d9bf237..56f22330b0 100644 --- a/wpilibc/src/main/native/cpp/Commands/WaitUntilCommand.cpp +++ b/wpilibc/src/main/native/cpp/Commands/WaitUntilCommand.cpp @@ -23,7 +23,7 @@ WaitUntilCommand::WaitUntilCommand(double time) m_time = time; } -WaitUntilCommand::WaitUntilCommand(const std::string& name, double time) +WaitUntilCommand::WaitUntilCommand(const llvm::Twine& name, double time) : Command(name, time) { m_time = time; } diff --git a/wpilibc/src/main/native/include/Buttons/NetworkButton.h b/wpilibc/src/main/native/include/Buttons/NetworkButton.h index e436821827..54fef89df1 100644 --- a/wpilibc/src/main/native/include/Buttons/NetworkButton.h +++ b/wpilibc/src/main/native/include/Buttons/NetworkButton.h @@ -9,7 +9,7 @@ #include -#include +#include #include "Buttons/Button.h" #include "networktables/NetworkTable.h" @@ -19,8 +19,9 @@ namespace frc { class NetworkButton : public Button { public: - NetworkButton(llvm::StringRef tableName, llvm::StringRef field); - NetworkButton(std::shared_ptr table, llvm::StringRef field); + NetworkButton(const llvm::Twine& tableName, const llvm::Twine& field); + NetworkButton(std::shared_ptr table, + const llvm::Twine& field); virtual ~NetworkButton() = default; virtual bool Get(); diff --git a/wpilibc/src/main/native/include/Commands/CommandGroup.h b/wpilibc/src/main/native/include/Commands/CommandGroup.h index f8bd70d98b..6cd0fc1dd4 100644 --- a/wpilibc/src/main/native/include/Commands/CommandGroup.h +++ b/wpilibc/src/main/native/include/Commands/CommandGroup.h @@ -8,9 +8,10 @@ #pragma once #include -#include #include +#include + #include "Commands/Command.h" #include "Commands/CommandGroupEntry.h" @@ -36,7 +37,7 @@ namespace frc { class CommandGroup : public Command { public: CommandGroup() = default; - explicit CommandGroup(const std::string& name); + explicit CommandGroup(const llvm::Twine& name); virtual ~CommandGroup() = default; void AddSequential(Command* command); diff --git a/wpilibc/src/main/native/include/Commands/ConditionalCommand.h b/wpilibc/src/main/native/include/Commands/ConditionalCommand.h index 826ccd881a..2832550de1 100644 --- a/wpilibc/src/main/native/include/Commands/ConditionalCommand.h +++ b/wpilibc/src/main/native/include/Commands/ConditionalCommand.h @@ -7,7 +7,7 @@ #pragma once -#include +#include #include "Commands/Command.h" #include "Commands/InstantCommand.h" @@ -33,7 +33,7 @@ namespace frc { class ConditionalCommand : public Command { public: explicit ConditionalCommand(Command* onTrue, Command* onFalse = nullptr); - ConditionalCommand(const std::string& name, Command* onTrue, + ConditionalCommand(const llvm::Twine& name, Command* onTrue, Command* onFalse = nullptr); virtual ~ConditionalCommand() = default; diff --git a/wpilibc/src/main/native/include/Commands/InstantCommand.h b/wpilibc/src/main/native/include/Commands/InstantCommand.h index d69e3148ff..59c7b2b633 100644 --- a/wpilibc/src/main/native/include/Commands/InstantCommand.h +++ b/wpilibc/src/main/native/include/Commands/InstantCommand.h @@ -7,7 +7,7 @@ #pragma once -#include +#include #include "Commands/Command.h" @@ -20,7 +20,7 @@ namespace frc { */ class InstantCommand : public Command { public: - explicit InstantCommand(const std::string& name); + explicit InstantCommand(const llvm::Twine& name); InstantCommand() = default; virtual ~InstantCommand() = default; diff --git a/wpilibc/src/main/native/include/Commands/PIDCommand.h b/wpilibc/src/main/native/include/Commands/PIDCommand.h index 26f23b902c..c1390434ed 100644 --- a/wpilibc/src/main/native/include/Commands/PIDCommand.h +++ b/wpilibc/src/main/native/include/Commands/PIDCommand.h @@ -8,7 +8,8 @@ #pragma once #include -#include + +#include #include "Commands/Command.h" #include "PIDController.h" @@ -19,10 +20,10 @@ namespace frc { class PIDCommand : public Command, public PIDOutput, public PIDSource { public: - PIDCommand(const std::string& name, double p, double i, double d); - PIDCommand(const std::string& name, double p, double i, double d, + PIDCommand(const llvm::Twine& name, double p, double i, double d); + PIDCommand(const llvm::Twine& name, double p, double i, double d, double period); - PIDCommand(const std::string& name, double p, double i, double d, double f, + PIDCommand(const llvm::Twine& name, double p, double i, double d, double f, double period); PIDCommand(double p, double i, double d); PIDCommand(double p, double i, double d, double period); diff --git a/wpilibc/src/main/native/include/Commands/PIDSubsystem.h b/wpilibc/src/main/native/include/Commands/PIDSubsystem.h index 0c5a27469c..41e48ebf61 100644 --- a/wpilibc/src/main/native/include/Commands/PIDSubsystem.h +++ b/wpilibc/src/main/native/include/Commands/PIDSubsystem.h @@ -8,7 +8,8 @@ #pragma once #include -#include + +#include #include "Commands/Subsystem.h" #include "PIDController.h" @@ -28,9 +29,9 @@ namespace frc { */ class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource { public: - PIDSubsystem(const std::string& name, double p, double i, double d); - PIDSubsystem(const std::string& name, double p, double i, double d, double f); - PIDSubsystem(const std::string& name, double p, double i, double d, double f, + PIDSubsystem(const llvm::Twine& name, double p, double i, double d); + PIDSubsystem(const llvm::Twine& name, double p, double i, double d, double f); + PIDSubsystem(const llvm::Twine& name, double p, double i, double d, double f, double period); PIDSubsystem(double p, double i, double d); PIDSubsystem(double p, double i, double d, double f); diff --git a/wpilibc/src/main/native/include/Commands/PrintCommand.h b/wpilibc/src/main/native/include/Commands/PrintCommand.h index 7b479641a3..0adb236321 100644 --- a/wpilibc/src/main/native/include/Commands/PrintCommand.h +++ b/wpilibc/src/main/native/include/Commands/PrintCommand.h @@ -9,13 +9,15 @@ #include +#include + #include "Commands/InstantCommand.h" namespace frc { class PrintCommand : public InstantCommand { public: - explicit PrintCommand(const std::string& message); + explicit PrintCommand(const llvm::Twine& message); virtual ~PrintCommand() = default; protected: diff --git a/wpilibc/src/main/native/include/Commands/TimedCommand.h b/wpilibc/src/main/native/include/Commands/TimedCommand.h index 6253848f6c..197f060c51 100644 --- a/wpilibc/src/main/native/include/Commands/TimedCommand.h +++ b/wpilibc/src/main/native/include/Commands/TimedCommand.h @@ -7,7 +7,7 @@ #pragma once -#include +#include #include "Commands/Command.h" @@ -20,7 +20,7 @@ namespace frc { */ class TimedCommand : public Command { public: - TimedCommand(const std::string& name, double timeout); + TimedCommand(const llvm::Twine& name, double timeout); explicit TimedCommand(double timeout); virtual ~TimedCommand() = default; diff --git a/wpilibc/src/main/native/include/Commands/WaitCommand.h b/wpilibc/src/main/native/include/Commands/WaitCommand.h index b674fd0b9e..55470c5e08 100644 --- a/wpilibc/src/main/native/include/Commands/WaitCommand.h +++ b/wpilibc/src/main/native/include/Commands/WaitCommand.h @@ -7,7 +7,7 @@ #pragma once -#include +#include #include "Commands/TimedCommand.h" @@ -16,7 +16,7 @@ namespace frc { class WaitCommand : public TimedCommand { public: explicit WaitCommand(double timeout); - WaitCommand(const std::string& name, double timeout); + WaitCommand(const llvm::Twine& name, double timeout); virtual ~WaitCommand() = default; }; diff --git a/wpilibc/src/main/native/include/Commands/WaitForChildren.h b/wpilibc/src/main/native/include/Commands/WaitForChildren.h index 7336c021d6..9a07ded5f7 100644 --- a/wpilibc/src/main/native/include/Commands/WaitForChildren.h +++ b/wpilibc/src/main/native/include/Commands/WaitForChildren.h @@ -7,7 +7,7 @@ #pragma once -#include +#include #include "Commands/Command.h" @@ -16,7 +16,7 @@ namespace frc { class WaitForChildren : public Command { public: explicit WaitForChildren(double timeout); - WaitForChildren(const std::string& name, double timeout); + WaitForChildren(const llvm::Twine& name, double timeout); virtual ~WaitForChildren() = default; protected: diff --git a/wpilibc/src/main/native/include/Commands/WaitUntilCommand.h b/wpilibc/src/main/native/include/Commands/WaitUntilCommand.h index 9accc68421..40725a8489 100644 --- a/wpilibc/src/main/native/include/Commands/WaitUntilCommand.h +++ b/wpilibc/src/main/native/include/Commands/WaitUntilCommand.h @@ -7,7 +7,7 @@ #pragma once -#include +#include #include "Commands/Command.h" @@ -16,7 +16,7 @@ namespace frc { class WaitUntilCommand : public Command { public: explicit WaitUntilCommand(double time); - WaitUntilCommand(const std::string& name, double time); + WaitUntilCommand(const llvm::Twine& name, double time); virtual ~WaitUntilCommand() = default; protected: