[wpilib] Deprecate getInstance() in favor of static functions (#3440)

Co-authored-by: Noam Zaks <imnoamzaks@gmail.com>
This commit is contained in:
Peter Johnson
2021-06-15 23:06:03 -07:00
committed by GitHub
parent 26ff9371d9
commit 362066a9b7
105 changed files with 1500 additions and 1539 deletions

View File

@@ -10,7 +10,7 @@
using namespace frc2;
CommandBase::CommandBase() {
wpi::SendableRegistry::GetInstance().Add(this, GetTypeName(*this));
wpi::SendableRegistry::Add(this, GetTypeName(*this));
}
void CommandBase::AddRequirements(
@@ -31,19 +31,19 @@ wpi::SmallSet<Subsystem*, 4> CommandBase::GetRequirements() const {
}
void CommandBase::SetName(std::string_view name) {
wpi::SendableRegistry::GetInstance().SetName(this, name);
wpi::SendableRegistry::SetName(this, name);
}
std::string CommandBase::GetName() const {
return wpi::SendableRegistry::GetInstance().GetName(this);
return wpi::SendableRegistry::GetName(this);
}
std::string CommandBase::GetSubsystem() const {
return wpi::SendableRegistry::GetInstance().GetSubsystem(this);
return wpi::SendableRegistry::GetSubsystem(this);
}
void CommandBase::SetSubsystem(std::string_view subsystem) {
wpi::SendableRegistry::GetInstance().SetSubsystem(this, subsystem);
wpi::SendableRegistry::SetSubsystem(this, subsystem);
}
void CommandBase::InitSendable(wpi::SendableBuilder& builder) {

View File

@@ -70,20 +70,18 @@ CommandScheduler::CommandScheduler()
}) {
HAL_Report(HALUsageReporting::kResourceType_Command,
HALUsageReporting::kCommand2_Scheduler);
wpi::SendableRegistry::GetInstance().AddLW(this, "Scheduler");
auto scheduler = frc::LiveWindow::GetInstance();
scheduler->enabled = [this] {
wpi::SendableRegistry::AddLW(this, "Scheduler");
frc::LiveWindow::SetEnabledCallback([this] {
this->Disable();
this->CancelAll();
};
scheduler->disabled = [this] { this->Enable(); };
});
frc::LiveWindow::SetDisabledCallback([this] { this->Enable(); });
}
CommandScheduler::~CommandScheduler() {
wpi::SendableRegistry::GetInstance().Remove(this);
auto scheduler = frc::LiveWindow::GetInstance();
scheduler->enabled = nullptr;
scheduler->disabled = nullptr;
wpi::SendableRegistry::Remove(this);
frc::LiveWindow::SetEnabledCallback(nullptr);
frc::LiveWindow::SetDisabledCallback(nullptr);
std::unique_ptr<Impl>().swap(m_impl);
}

View File

@@ -13,7 +13,7 @@
using namespace frc2;
SubsystemBase::SubsystemBase() {
wpi::SendableRegistry::GetInstance().AddLW(this, GetTypeName(*this));
wpi::SendableRegistry::AddLW(this, GetTypeName(*this));
CommandScheduler::GetInstance().RegisterSubsystem({this});
}
@@ -48,22 +48,21 @@ void SubsystemBase::InitSendable(wpi::SendableBuilder& builder) {
}
std::string SubsystemBase::GetName() const {
return wpi::SendableRegistry::GetInstance().GetName(this);
return wpi::SendableRegistry::GetName(this);
}
void SubsystemBase::SetName(std::string_view name) {
wpi::SendableRegistry::GetInstance().SetName(this, name);
wpi::SendableRegistry::SetName(this, name);
}
std::string SubsystemBase::GetSubsystem() const {
return wpi::SendableRegistry::GetInstance().GetSubsystem(this);
return wpi::SendableRegistry::GetSubsystem(this);
}
void SubsystemBase::SetSubsystem(std::string_view name) {
wpi::SendableRegistry::GetInstance().SetSubsystem(this, name);
wpi::SendableRegistry::SetSubsystem(this, name);
}
void SubsystemBase::AddChild(std::string name, wpi::Sendable* child) {
auto& registry = wpi::SendableRegistry::GetInstance();
registry.AddLW(child, GetSubsystem(), name);
wpi::SendableRegistry::AddLW(child, GetSubsystem(), name);
}