mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
Remove GetTable from wpilibc Sendable interface.
This allows nearly all m_table member variables to be removed.
This commit is contained in:
@@ -22,11 +22,6 @@ class Sendable {
|
||||
*/
|
||||
virtual void InitTable(std::shared_ptr<nt::NetworkTable> subtable) = 0;
|
||||
|
||||
/**
|
||||
* @return the table that is currently associated with the sendable
|
||||
*/
|
||||
virtual std::shared_ptr<nt::NetworkTable> GetTable() const = 0;
|
||||
|
||||
/**
|
||||
* @return the string representation of the named data type that will be used
|
||||
* by the smart dashboard for this sendable
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "SmartDashboard/SendableChooserBase.h"
|
||||
#include "networktables/NetworkTable.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -35,6 +36,7 @@ namespace frc {
|
||||
template <class T>
|
||||
class SendableChooser : public SendableChooserBase {
|
||||
llvm::StringMap<T> m_choices;
|
||||
nt::NetworkTableEntry m_selectedEntry;
|
||||
|
||||
template <class U>
|
||||
static U _unwrap_smart_ptr(const U& value);
|
||||
|
||||
@@ -59,7 +59,7 @@ void SendableChooser<T>::AddDefault(llvm::StringRef name, T object) {
|
||||
template <class T>
|
||||
auto SendableChooser<T>::GetSelected()
|
||||
-> decltype(_unwrap_smart_ptr(m_choices[""])) {
|
||||
std::string selected = m_table->GetString(kSelected, m_defaultChoice);
|
||||
std::string selected = m_selectedEntry.GetString(m_defaultChoice);
|
||||
if (selected == "") {
|
||||
return decltype(_unwrap_smart_ptr(m_choices[""])){};
|
||||
} else {
|
||||
@@ -70,8 +70,8 @@ auto SendableChooser<T>::GetSelected()
|
||||
template <class T>
|
||||
void SendableChooser<T>::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
|
||||
std::vector<std::string> keys;
|
||||
m_table = subtable;
|
||||
if (m_table != nullptr) {
|
||||
if (subtable) {
|
||||
m_selectedEntry = subtable->GetEntry(kSelected);
|
||||
for (const auto& choice : m_choices) {
|
||||
keys.push_back(choice.first());
|
||||
}
|
||||
@@ -79,9 +79,9 @@ void SendableChooser<T>::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
|
||||
// Unlike std::map, llvm::StringMap elements are not sorted
|
||||
std::sort(keys.begin(), keys.end());
|
||||
|
||||
m_table->GetEntry(kOptions).SetValue(
|
||||
subtable->GetEntry(kOptions).SetValue(
|
||||
nt::Value::MakeStringArray(std::move(keys)));
|
||||
m_table->GetEntry(kDefault).SetString(m_defaultChoice);
|
||||
subtable->GetEntry(kDefault).SetString(m_defaultChoice);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ class SendableChooserBase : public Sendable {
|
||||
public:
|
||||
virtual ~SendableChooserBase() = default;
|
||||
|
||||
std::shared_ptr<nt::NetworkTable> GetTable() const override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
|
||||
protected:
|
||||
@@ -34,7 +33,6 @@ class SendableChooserBase : public Sendable {
|
||||
static const char* kSelected;
|
||||
|
||||
std::string m_defaultChoice;
|
||||
std::shared_ptr<nt::NetworkTable> m_table;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
Reference in New Issue
Block a user