Remove GetTable from wpilibc Sendable interface.

This allows nearly all m_table member variables to be removed.
This commit is contained in:
Peter Johnson
2017-09-02 00:35:30 -07:00
parent 040a8c6bcc
commit 0d4fde17e0
57 changed files with 87 additions and 259 deletions

View File

@@ -86,11 +86,10 @@ std::string ADXL345_I2C::GetSmartDashboardType() const {
}
void ADXL345_I2C::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_table = subtable;
if (m_table) {
m_xEntry = m_table->GetEntry("X");
m_yEntry = m_table->GetEntry("Y");
m_zEntry = m_table->GetEntry("Z");
if (subtable) {
m_xEntry = subtable->GetEntry("X");
m_yEntry = subtable->GetEntry("Y");
m_zEntry = subtable->GetEntry("Z");
UpdateTable();
} else {
m_xEntry = nt::NetworkTableEntry();
@@ -104,7 +103,3 @@ void ADXL345_I2C::UpdateTable() {
if (m_yEntry) m_yEntry.SetDouble(GetY());
if (m_zEntry) m_zEntry.SetDouble(GetZ());
}
std::shared_ptr<nt::NetworkTable> ADXL345_I2C::GetTable() const {
return m_table;
}

View File

@@ -113,11 +113,10 @@ std::string ADXL345_SPI::GetSmartDashboardType() const {
}
void ADXL345_SPI::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_table = subtable;
if (m_table) {
m_xEntry = m_table->GetEntry("X");
m_yEntry = m_table->GetEntry("Y");
m_zEntry = m_table->GetEntry("Z");
if (subtable) {
m_xEntry = subtable->GetEntry("X");
m_yEntry = subtable->GetEntry("Y");
m_zEntry = subtable->GetEntry("Z");
UpdateTable();
} else {
m_xEntry = nt::NetworkTableEntry();
@@ -131,7 +130,3 @@ void ADXL345_SPI::UpdateTable() {
if (m_yEntry) m_yEntry.SetDouble(GetY());
if (m_zEntry) m_zEntry.SetDouble(GetZ());
}
std::shared_ptr<nt::NetworkTable> ADXL345_SPI::GetTable() const {
return m_table;
}

View File

@@ -168,11 +168,10 @@ std::string ADXL362::GetSmartDashboardType() const {
}
void ADXL362::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_table = subtable;
if (m_table) {
m_xEntry = m_table->GetEntry("X");
m_yEntry = m_table->GetEntry("Y");
m_zEntry = m_table->GetEntry("Z");
if (subtable) {
m_xEntry = subtable->GetEntry("X");
m_yEntry = subtable->GetEntry("Y");
m_zEntry = subtable->GetEntry("Z");
UpdateTable();
} else {
m_xEntry = nt::NetworkTableEntry();
@@ -186,5 +185,3 @@ void ADXL362::UpdateTable() {
if (m_yEntry) m_yEntry.SetDouble(GetY());
if (m_zEntry) m_zEntry.SetDouble(GetZ());
}
std::shared_ptr<nt::NetworkTable> ADXL362::GetTable() const { return m_table; }

View File

@@ -130,15 +130,10 @@ std::string AnalogAccelerometer::GetSmartDashboardType() const {
void AnalogAccelerometer::InitTable(
std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
if (m_table) {
m_valueEntry = m_table->GetEntry("Value");
if (subTable) {
m_valueEntry = subTable->GetEntry("Value");
UpdateTable();
} else {
m_valueEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> AnalogAccelerometer::GetTable() const {
return m_table;
}

View File

@@ -431,15 +431,10 @@ std::string AnalogInput::GetSmartDashboardType() const {
}
void AnalogInput::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
if (m_table) {
m_valueEntry = m_table->GetEntry("Value");
if (subTable) {
m_valueEntry = subTable->GetEntry("Value");
UpdateTable();
} else {
m_valueEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> AnalogInput::GetTable() const {
return m_table;
}

View File

@@ -106,15 +106,10 @@ std::string AnalogOutput::GetSmartDashboardType() const {
}
void AnalogOutput::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
if (m_table) {
m_valueEntry = m_table->GetEntry("Value");
if (subTable) {
m_valueEntry = subTable->GetEntry("Value");
UpdateTable();
} else {
m_valueEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> AnalogOutput::GetTable() const {
return m_table;
}

View File

@@ -88,9 +88,8 @@ std::string AnalogPotentiometer::GetSmartDashboardType() const {
*/
void AnalogPotentiometer::InitTable(
std::shared_ptr<nt::NetworkTable> subtable) {
m_table = subtable;
if (m_table) {
m_valueEntry = m_table->GetEntry("Value");
if (subtable) {
m_valueEntry = subtable->GetEntry("Value");
UpdateTable();
} else {
m_valueEntry = nt::NetworkTableEntry();
@@ -100,7 +99,3 @@ void AnalogPotentiometer::InitTable(
void AnalogPotentiometer::UpdateTable() {
if (m_valueEntry) m_valueEntry.SetDouble(Get());
}
std::shared_ptr<nt::NetworkTable> AnalogPotentiometer::GetTable() const {
return m_table;
}

View File

@@ -60,11 +60,10 @@ std::string BuiltInAccelerometer::GetSmartDashboardType() const {
void BuiltInAccelerometer::InitTable(
std::shared_ptr<nt::NetworkTable> subtable) {
m_table = subtable;
if (m_table != nullptr) {
m_xEntry = m_table->GetEntry("X");
m_yEntry = m_table->GetEntry("Y");
m_zEntry = m_table->GetEntry("Z");
if (subtable != nullptr) {
m_xEntry = subtable->GetEntry("X");
m_yEntry = subtable->GetEntry("Y");
m_zEntry = subtable->GetEntry("Z");
UpdateTable();
} else {
m_xEntry = nt::NetworkTableEntry();
@@ -78,7 +77,3 @@ void BuiltInAccelerometer::UpdateTable() {
if (m_yEntry) m_yEntry.SetDouble(GetY());
if (m_zEntry) m_zEntry.SetDouble(GetZ());
}
std::shared_ptr<nt::NetworkTable> BuiltInAccelerometer::GetTable() const {
return m_table;
}

View File

@@ -46,13 +46,10 @@ void Trigger::ToggleWhenActive(Command* command) {
std::string Trigger::GetSmartDashboardType() const { return "Button"; }
void Trigger::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_table = subtable;
if (m_table) {
m_pressedEntry = m_table->GetEntry("pressed");
if (subtable) {
m_pressedEntry = subtable->GetEntry("pressed");
m_pressedEntry.SetBoolean(Get());
} else {
m_pressedEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> Trigger::GetTable() const { return m_table; }

View File

@@ -435,12 +435,11 @@ std::string Command::GetSmartDashboardType() const { return "Command"; }
void Command::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
if (m_runningListener != 0) m_runningEntry.RemoveListener(m_runningListener);
m_table = subtable;
if (m_table != nullptr) {
m_table->GetEntry(kName).SetString(GetName());
m_runningEntry = m_table->GetEntry(kRunning);
if (subtable) {
subtable->GetEntry(kName).SetString(GetName());
m_runningEntry = subtable->GetEntry(kRunning);
m_runningEntry.SetBoolean(IsRunning());
m_isParentedEntry = m_table->GetEntry(kIsParented);
m_isParentedEntry = subtable->GetEntry(kIsParented);
m_isParentedEntry.SetBoolean(m_parent != nullptr);
m_runningListener = m_runningEntry.AddListener(
@@ -455,5 +454,3 @@ void Command::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
}
}
std::shared_ptr<nt::NetworkTable> Command::GetTable() const { return m_table; }

View File

@@ -218,7 +218,6 @@ void Scheduler::ResetAll() {
m_buttons.clear();
m_additions.clear();
m_commands.clear();
m_table = nullptr;
m_namesEntry = nt::NetworkTableEntry();
m_idsEntry = nt::NetworkTableEntry();
m_cancelEntry = nt::NetworkTableEntry();
@@ -229,7 +228,7 @@ void Scheduler::ResetAll() {
* SmartDashboard.
*/
void Scheduler::UpdateTable() {
if (m_table != nullptr) {
if (m_cancelEntry && m_namesEntry && m_idsEntry) {
// Get the list of possible commands to cancel
auto new_toCancel = m_cancelEntry.GetValue();
if (new_toCancel)
@@ -277,11 +276,10 @@ std::string Scheduler::GetType() const { return "Scheduler"; }
std::string Scheduler::GetSmartDashboardType() const { return "Scheduler"; }
void Scheduler::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
if (m_table) {
m_namesEntry = m_table->GetEntry("Names");
m_idsEntry = m_table->GetEntry("Ids");
m_cancelEntry = m_table->GetEntry("Cancel");
if (subTable) {
m_namesEntry = subTable->GetEntry("Names");
m_idsEntry = subTable->GetEntry("Ids");
m_cancelEntry = subTable->GetEntry("Cancel");
m_namesEntry.SetStringArray(commands);
m_idsEntry.SetDoubleArray(ids);
m_cancelEntry.SetDoubleArray(toCancel);
@@ -291,7 +289,3 @@ void Scheduler::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_cancelEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> Scheduler::GetTable() const {
return m_table;
}

View File

@@ -64,7 +64,7 @@ void Subsystem::SetDefaultCommand(Command* command) {
m_defaultCommand = command;
}
if (m_table != nullptr) {
if (m_hasDefaultEntry && m_defaultEntry) {
if (m_defaultCommand != nullptr) {
m_hasDefaultEntry.SetBoolean(true);
m_defaultEntry.SetString(m_defaultCommand->GetName());
@@ -119,7 +119,7 @@ void Subsystem::Periodic() {}
*/
void Subsystem::ConfirmCommand() {
if (m_currentCommandChanged) {
if (m_table != nullptr) {
if (m_hasCommandEntry && m_commandEntry) {
if (m_currentCommand != nullptr) {
m_hasCommandEntry.SetBoolean(true);
m_commandEntry.SetString(m_currentCommand->GetName());
@@ -136,12 +136,11 @@ std::string Subsystem::GetName() const { return m_name; }
std::string Subsystem::GetSmartDashboardType() const { return "Subsystem"; }
void Subsystem::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_table = subtable;
if (m_table != nullptr) {
m_hasDefaultEntry = m_table->GetEntry("hasDefault");
m_defaultEntry = m_table->GetEntry("default");
m_hasCommandEntry = m_table->GetEntry("hasCommand");
m_commandEntry = m_table->GetEntry("command");
if (subtable != nullptr) {
m_hasDefaultEntry = subtable->GetEntry("hasDefault");
m_defaultEntry = subtable->GetEntry("default");
m_hasCommandEntry = subtable->GetEntry("hasCommand");
m_commandEntry = subtable->GetEntry("command");
if (m_defaultCommand != nullptr) {
m_hasDefaultEntry.SetBoolean(true);
@@ -157,7 +156,3 @@ void Subsystem::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
}
}
}
std::shared_ptr<nt::NetworkTable> Subsystem::GetTable() const {
return m_table;
}

View File

@@ -336,17 +336,12 @@ void Compressor::StopLiveWindowMode() {
std::string Compressor::GetSmartDashboardType() const { return "Compressor"; }
void Compressor::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
if (m_table) {
m_enabledEntry = m_table->GetEntry("Enabled");
m_pressureSwitchEntry = m_table->GetEntry("Pressure switch");
if (subTable) {
m_enabledEntry = subTable->GetEntry("Enabled");
m_pressureSwitchEntry = subTable->GetEntry("Pressure switch");
UpdateTable();
} else {
m_enabledEntry = nt::NetworkTableEntry();
m_pressureSwitchEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> Compressor::GetTable() const {
return m_table;
}

View File

@@ -613,13 +613,10 @@ void Counter::StopLiveWindowMode() {}
std::string Counter::GetSmartDashboardType() const { return "Counter"; }
void Counter::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
if (m_table) {
m_valueEntry = m_table->GetEntry("Value");
if (subTable) {
m_valueEntry = subTable->GetEntry("Value");
UpdateTable();
} else {
m_valueEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> Counter::GetTable() const { return m_table; }

View File

@@ -116,15 +116,10 @@ std::string DigitalInput::GetSmartDashboardType() const {
}
void DigitalInput::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
if (m_table) {
m_valueEntry = m_table->GetEntry("Value");
if (subTable) {
m_valueEntry = subTable->GetEntry("Value");
UpdateTable();
} else {
m_valueEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> DigitalInput::GetTable() const {
return m_table;
}

View File

@@ -257,15 +257,10 @@ std::string DigitalOutput::GetSmartDashboardType() const {
}
void DigitalOutput::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
if (m_table != nullptr) {
m_valueEntry = m_table->GetEntry("Value");
if (subTable) {
m_valueEntry = subTable->GetEntry("Value");
UpdateTable();
} else {
m_valueEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> DigitalOutput::GetTable() const {
return m_table;
}

View File

@@ -227,15 +227,10 @@ std::string DoubleSolenoid::GetSmartDashboardType() const {
}
void DoubleSolenoid::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
if (m_table) {
m_valueEntry = m_table->GetEntry("Value");
if (subTable) {
m_valueEntry = subTable->GetEntry("Value");
UpdateTable();
} else {
m_valueEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> DoubleSolenoid::GetTable() const {
return m_table;
}

View File

@@ -506,11 +506,10 @@ std::string Encoder::GetSmartDashboardType() const {
}
void Encoder::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
if (m_table) {
m_speedEntry = m_table->GetEntry("Speed");
m_distanceEntry = m_table->GetEntry("Distance");
m_distancePerTickEntry = m_table->GetEntry("Distance per Tick");
if (subTable) {
m_speedEntry = subTable->GetEntry("Speed");
m_distanceEntry = subTable->GetEntry("Distance");
m_distancePerTickEntry = subTable->GetEntry("Distance per Tick");
UpdateTable();
} else {
m_speedEntry = nt::NetworkTableEntry();
@@ -518,5 +517,3 @@ void Encoder::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_distancePerTickEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> Encoder::GetTable() const { return m_table; }

View File

@@ -40,13 +40,10 @@ void GyroBase::StopLiveWindowMode() {}
std::string GyroBase::GetSmartDashboardType() const { return "Gyro"; }
void GyroBase::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
if (m_table) {
m_valueEntry = m_table->GetEntry("Value");
if (subTable) {
m_valueEntry = subTable->GetEntry("Value");
UpdateTable();
} else {
m_valueEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> GyroBase::GetTable() const { return m_table; }

View File

@@ -562,19 +562,18 @@ std::string PIDController::GetSmartDashboardType() const {
void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
RemoveListeners();
m_table = subtable;
if (m_table) {
m_pEntry = m_table->GetEntry(kP);
if (subtable) {
m_pEntry = subtable->GetEntry(kP);
m_pEntry.SetDouble(GetP());
m_iEntry = m_table->GetEntry(kI);
m_iEntry = subtable->GetEntry(kI);
m_iEntry.SetDouble(GetI());
m_dEntry = m_table->GetEntry(kD);
m_dEntry = subtable->GetEntry(kD);
m_dEntry.SetDouble(GetD());
m_fEntry = m_table->GetEntry(kF);
m_fEntry = subtable->GetEntry(kF);
m_fEntry.SetDouble(GetF());
m_setpointEntry = m_table->GetEntry(kSetpoint);
m_setpointEntry = subtable->GetEntry(kSetpoint);
m_setpointEntry.SetDouble(GetSetpoint());
m_enabledEntry = m_table->GetEntry(kEnabled);
m_enabledEntry = subtable->GetEntry(kEnabled);
m_enabledEntry.SetBoolean(IsEnabled());
m_pListener = m_pEntry.AddListener(
@@ -649,10 +648,6 @@ double PIDController::GetContinuousError(double error) const {
return error;
}
std::shared_ptr<nt::NetworkTable> PIDController::GetTable() const {
return m_table;
}
void PIDController::UpdateTable() {}
void PIDController::StartLiveWindowMode() { Disable(); }

View File

@@ -341,13 +341,10 @@ void PWM::StopLiveWindowMode() {
std::string PWM::GetSmartDashboardType() const { return "Speed Controller"; }
void PWM::InitTable(std::shared_ptr<NetworkTable> subTable) {
m_table = subTable;
if (m_table) {
m_valueEntry = m_table->GetEntry("Value");
if (subTable) {
m_valueEntry = subTable->GetEntry("Value");
UpdateTable();
} else {
m_valueEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<NetworkTable> PWM::GetTable() const { return m_table; }

View File

@@ -189,16 +189,15 @@ std::string PowerDistributionPanel::GetSmartDashboardType() const {
void PowerDistributionPanel::InitTable(
std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
if (m_table != nullptr) {
if (subTable != nullptr) {
for (size_t i = 0; i < sizeof(m_chanEntry) / sizeof(m_chanEntry[0]); ++i) {
llvm::SmallString<32> buf;
llvm::raw_svector_ostream oss(buf);
oss << "Chan" << i;
m_chanEntry[i] = m_table->GetEntry(oss.str());
m_chanEntry[i] = subTable->GetEntry(oss.str());
}
m_voltageEntry = m_table->GetEntry("Voltage");
m_totalCurrentEntry = m_table->GetEntry("TotalCurrent");
m_voltageEntry = subTable->GetEntry("Voltage");
m_totalCurrentEntry = subTable->GetEntry("TotalCurrent");
UpdateTable();
} else {
for (size_t i = 0; i < sizeof(m_chanEntry) / sizeof(m_chanEntry[0]); ++i) {
@@ -208,7 +207,3 @@ void PowerDistributionPanel::InitTable(
m_totalCurrentEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> PowerDistributionPanel::GetTable() const {
return m_table;
}

View File

@@ -315,13 +315,10 @@ void Relay::StopLiveWindowMode() {
std::string Relay::GetSmartDashboardType() const { return "Relay"; }
void Relay::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
if (m_table) {
m_valueEntry = m_table->GetEntry("Value");
if (subTable) {
m_valueEntry = subTable->GetEntry("Value");
UpdateTable();
} else {
m_valueEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> Relay::GetTable() const { return m_table; }

View File

@@ -121,13 +121,10 @@ void Servo::StopLiveWindowMode() {
std::string Servo::GetSmartDashboardType() const { return "Servo"; }
void Servo::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
if (m_table) {
m_valueEntry = m_table->GetEntry("Value");
if (subTable) {
m_valueEntry = subTable->GetEntry("Value");
UpdateTable();
} else {
m_valueEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> Servo::GetTable() const { return m_table; }

View File

@@ -13,10 +13,6 @@ const char* SendableChooserBase::kDefault = "default";
const char* SendableChooserBase::kOptions = "options";
const char* SendableChooserBase::kSelected = "selected";
std::shared_ptr<nt::NetworkTable> SendableChooserBase::GetTable() const {
return m_table;
}
std::string SendableChooserBase::GetSmartDashboardType() const {
return "String Chooser";
}

View File

@@ -135,13 +135,10 @@ void Solenoid::StopLiveWindowMode() {
std::string Solenoid::GetSmartDashboardType() const { return "Solenoid"; }
void Solenoid::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
if (m_table) {
m_valueEntry = m_table->GetEntry("Value");
if (subTable) {
m_valueEntry = subTable->GetEntry("Value");
UpdateTable();
} else {
m_valueEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<nt::NetworkTable> Solenoid::GetTable() const { return m_table; }

View File

@@ -331,13 +331,10 @@ void Ultrasonic::StopLiveWindowMode() {}
std::string Ultrasonic::GetSmartDashboardType() const { return "Ultrasonic"; }
void Ultrasonic::InitTable(std::shared_ptr<NetworkTable> subTable) {
m_table = subTable;
if (m_table != nullptr) {
m_valueEntry = m_table->GetEntry("Value");
if (subTable) {
m_valueEntry = subTable->GetEntry("Value");
UpdateTable();
} else {
m_valueEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<NetworkTable> Ultrasonic::GetTable() const { return m_table; }