diff --git a/wpilibc/wpilibC++/include/Commands/Command.h b/wpilibc/wpilibC++/include/Commands/Command.h index 9c6463ca9c..c9f99d1745 100644 --- a/wpilibc/wpilibC++/include/Commands/Command.h +++ b/wpilibc/wpilibC++/include/Commands/Command.h @@ -175,7 +175,7 @@ class Command : public ErrorBase, public NamedSendable, public ITableListener { static int m_commandCounter; public: - virtual std::string GetName(); + virtual std::string GetName() const; virtual void InitTable(::std::shared_ptr table); virtual ::std::shared_ptr GetTable() const; virtual std::string GetSmartDashboardType() const; diff --git a/wpilibc/wpilibC++/include/Commands/Scheduler.h b/wpilibc/wpilibC++/include/Commands/Scheduler.h index 7e89d6d4fb..5060868c66 100644 --- a/wpilibc/wpilibC++/include/Commands/Scheduler.h +++ b/wpilibc/wpilibC++/include/Commands/Scheduler.h @@ -42,7 +42,7 @@ class Scheduler : public ErrorBase, public NamedSendable { std::string GetSmartDashboardType() const; void InitTable(::std::shared_ptr subTable); ::std::shared_ptr GetTable() const; - std::string GetName(); + std::string GetName() const; std::string GetType() const; private: diff --git a/wpilibc/wpilibC++/include/Commands/Subsystem.h b/wpilibc/wpilibC++/include/Commands/Subsystem.h index c9581ffd6c..5858a10d2c 100644 --- a/wpilibc/wpilibC++/include/Commands/Subsystem.h +++ b/wpilibc/wpilibC++/include/Commands/Subsystem.h @@ -38,7 +38,7 @@ class Subsystem : public ErrorBase, public NamedSendable { bool m_initializedDefaultCommand = false; public: - virtual std::string GetName(); + virtual std::string GetName() const; virtual void InitTable(::std::shared_ptr table); virtual ::std::shared_ptr GetTable() const; virtual std::string GetSmartDashboardType() const; diff --git a/wpilibc/wpilibC++/include/SmartDashboard/NamedSendable.h b/wpilibc/wpilibC++/include/SmartDashboard/NamedSendable.h index e6171b58f9..0dd1b248d9 100644 --- a/wpilibc/wpilibC++/include/SmartDashboard/NamedSendable.h +++ b/wpilibc/wpilibC++/include/SmartDashboard/NamedSendable.h @@ -22,7 +22,7 @@ class NamedSendable : public Sendable { * @return the name of the subtable of SmartDashboard that the Sendable object * will use */ - virtual std::string GetName() = 0; + virtual std::string GetName() const = 0; }; #endif /* NAMEDSENDABLE_H_ */ diff --git a/wpilibc/wpilibC++/src/Commands/Command.cpp b/wpilibc/wpilibC++/src/Commands/Command.cpp index 4317bc4b0d..a81620a667 100644 --- a/wpilibc/wpilibC++/src/Commands/Command.cpp +++ b/wpilibc/wpilibC++/src/Commands/Command.cpp @@ -23,7 +23,7 @@ int Command::m_commandCounter = 0; * Creates a new command. * The name of this command will be default. */ -Command::Command() : Command(nullptr, -1.0) {} +Command::Command() : Command("", -1.0) {} /** * Creates a new command with the given name and no timeout. @@ -50,7 +50,14 @@ Command::Command(const std::string &name, double timeout) { wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0"); m_timeout = timeout; - m_name = name; + + // If name contains an empty string + if (name.length() == 0) { + m_name = std::string("Command_") + std::string(typeid(*this).name()); + } + else { + m_name = name; + } } Command::~Command() { // TODO deal with cleaning up all listeners @@ -357,10 +364,7 @@ void Command::SetRunWhenDisabled(bool run) { m_runWhenDisabled = run; } */ bool Command::WillRunWhenDisabled() const { return m_runWhenDisabled; } -std::string Command::GetName() { - if (m_name.length() == 0) { - m_name = std::string("Command_") + std::string(typeid(*this).name()); - } +std::string Command::GetName() const { return m_name; } diff --git a/wpilibc/wpilibC++/src/Commands/Scheduler.cpp b/wpilibc/wpilibC++/src/Commands/Scheduler.cpp index 96a7646422..af23728265 100644 --- a/wpilibc/wpilibC++/src/Commands/Scheduler.cpp +++ b/wpilibc/wpilibC++/src/Commands/Scheduler.cpp @@ -252,7 +252,7 @@ void Scheduler::UpdateTable() { } } -std::string Scheduler::GetName() { return "Scheduler"; } +std::string Scheduler::GetName() const { return "Scheduler"; } std::string Scheduler::GetType() const { return "Scheduler"; } diff --git a/wpilibc/wpilibC++/src/Commands/Subsystem.cpp b/wpilibc/wpilibC++/src/Commands/Subsystem.cpp index 0fb1ce7b15..bd75de3a4c 100644 --- a/wpilibc/wpilibC++/src/Commands/Subsystem.cpp +++ b/wpilibc/wpilibC++/src/Commands/Subsystem.cpp @@ -122,7 +122,7 @@ void Subsystem::ConfirmCommand() { } } -std::string Subsystem::GetName() { return m_name; } +std::string Subsystem::GetName() const { return m_name; } std::string Subsystem::GetSmartDashboardType() const { return "Subsystem"; }