mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[wpilibc] Return reference from GetInstance (#3247)
Improves consistency across all classes. Affects Preferences, LiveWindow, and CameraServer. Old commands Scheduler::GetInstance() was not updated as this is already deprecated.
This commit is contained in:
@@ -108,7 +108,7 @@ void IterativeRobotBase::LoopFunc() {
|
||||
// Call DisabledInit() if we are now just entering disabled mode from
|
||||
// either a different mode or from power-on.
|
||||
if (m_lastMode != Mode::kDisabled) {
|
||||
LiveWindow::GetInstance()->SetEnabled(false);
|
||||
LiveWindow::GetInstance().SetEnabled(false);
|
||||
Shuffleboard::DisableActuatorWidgets();
|
||||
DisabledInit();
|
||||
m_watchdog.AddEpoch("DisabledInit()");
|
||||
@@ -122,7 +122,7 @@ void IterativeRobotBase::LoopFunc() {
|
||||
// Call AutonomousInit() if we are now just entering autonomous mode from
|
||||
// either a different mode or from power-on.
|
||||
if (m_lastMode != Mode::kAutonomous) {
|
||||
LiveWindow::GetInstance()->SetEnabled(false);
|
||||
LiveWindow::GetInstance().SetEnabled(false);
|
||||
Shuffleboard::DisableActuatorWidgets();
|
||||
AutonomousInit();
|
||||
m_watchdog.AddEpoch("AutonomousInit()");
|
||||
@@ -136,7 +136,7 @@ void IterativeRobotBase::LoopFunc() {
|
||||
// Call TeleopInit() if we are now just entering teleop mode from
|
||||
// either a different mode or from power-on.
|
||||
if (m_lastMode != Mode::kTeleop) {
|
||||
LiveWindow::GetInstance()->SetEnabled(false);
|
||||
LiveWindow::GetInstance().SetEnabled(false);
|
||||
Shuffleboard::DisableActuatorWidgets();
|
||||
TeleopInit();
|
||||
m_watchdog.AddEpoch("TeleopInit()");
|
||||
@@ -150,7 +150,7 @@ void IterativeRobotBase::LoopFunc() {
|
||||
// Call TestInit() if we are now just entering test mode from
|
||||
// either a different mode or from power-on.
|
||||
if (m_lastMode != Mode::kTest) {
|
||||
LiveWindow::GetInstance()->SetEnabled(true);
|
||||
LiveWindow::GetInstance().SetEnabled(true);
|
||||
Shuffleboard::EnableActuatorWidgets();
|
||||
TestInit();
|
||||
m_watchdog.AddEpoch("TestInit()");
|
||||
@@ -167,7 +167,7 @@ void IterativeRobotBase::LoopFunc() {
|
||||
|
||||
SmartDashboard::UpdateValues();
|
||||
m_watchdog.AddEpoch("SmartDashboard::UpdateValues()");
|
||||
LiveWindow::GetInstance()->UpdateValues();
|
||||
LiveWindow::GetInstance().UpdateValues();
|
||||
m_watchdog.AddEpoch("LiveWindow::UpdateValues()");
|
||||
Shuffleboard::Update();
|
||||
m_watchdog.AddEpoch("Shuffleboard::Update()");
|
||||
|
||||
@@ -17,9 +17,9 @@ using namespace frc;
|
||||
// The Preferences table name
|
||||
static wpi::StringRef kTableName{"Preferences"};
|
||||
|
||||
Preferences* Preferences::GetInstance() {
|
||||
Preferences& Preferences::GetInstance() {
|
||||
static Preferences instance;
|
||||
return &instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
std::vector<std::string> Preferences::GetKeys() {
|
||||
@@ -143,3 +143,5 @@ Preferences::Preferences()
|
||||
NT_NOTIFY_NEW | NT_NOTIFY_IMMEDIATE);
|
||||
HAL_Report(HALUsageReporting::kResourceType_Preferences, 0);
|
||||
}
|
||||
|
||||
Preferences::~Preferences() = default;
|
||||
|
||||
@@ -61,9 +61,9 @@ std::shared_ptr<LiveWindow::Impl::Component> LiveWindow::Impl::GetOrAdd(
|
||||
return data;
|
||||
}
|
||||
|
||||
LiveWindow* LiveWindow::GetInstance() {
|
||||
LiveWindow& LiveWindow::GetInstance() {
|
||||
static LiveWindow instance;
|
||||
return &instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void LiveWindow::EnableTelemetry(Sendable* sendable) {
|
||||
|
||||
@@ -214,7 +214,7 @@ RobotBase::RobotBase() : m_ds(DriverStation::GetInstance()) {
|
||||
->GetEntry("LW Enabled")
|
||||
.SetBoolean(false);
|
||||
|
||||
LiveWindow::GetInstance()->SetEnabled(false);
|
||||
LiveWindow::GetInstance().SetEnabled(false);
|
||||
}
|
||||
|
||||
RobotBase::RobotBase(RobotBase&&) noexcept
|
||||
|
||||
@@ -35,9 +35,9 @@ class Preferences : public ErrorBase {
|
||||
/**
|
||||
* Get the one and only {@link Preferences} object.
|
||||
*
|
||||
* @return pointer to the {@link Preferences}
|
||||
* @return reference to the {@link Preferences}
|
||||
*/
|
||||
static Preferences* GetInstance();
|
||||
static Preferences& GetInstance();
|
||||
|
||||
/**
|
||||
* Returns a vector of all the keys.
|
||||
@@ -226,7 +226,7 @@ class Preferences : public ErrorBase {
|
||||
|
||||
protected:
|
||||
Preferences();
|
||||
~Preferences() override = default;
|
||||
~Preferences() override;
|
||||
|
||||
Preferences(Preferences&&) = default;
|
||||
Preferences& operator=(Preferences&&) = default;
|
||||
|
||||
@@ -29,7 +29,7 @@ class LiveWindow {
|
||||
* This is a singleton to guarantee that there is only a single instance
|
||||
* regardless of how many times GetInstance is called.
|
||||
*/
|
||||
static LiveWindow* GetInstance();
|
||||
static LiveWindow& GetInstance();
|
||||
|
||||
/**
|
||||
* Enable telemetry for a single component.
|
||||
@@ -69,6 +69,7 @@ class LiveWindow {
|
||||
|
||||
private:
|
||||
LiveWindow();
|
||||
~LiveWindow() = default;
|
||||
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> m_impl;
|
||||
|
||||
Reference in New Issue
Block a user