16 #include <networktables/NetworkTable.h>
17 #include <networktables/NetworkTableEntry.h>
18 #include <networktables/NetworkTableValue.h>
19 #include <wpi/ArrayRef.h>
20 #include <wpi/SmallVector.h>
21 #include <wpi/Twine.h>
23 #include "frc/smartdashboard/SendableBuilder.h"
40 void SetTable(std::shared_ptr<nt::NetworkTable> table);
46 std::shared_ptr<nt::NetworkTable>
GetTable();
99 std::function<
void(
bool)> setter)
override;
102 std::function<
void(
double)> setter)
override;
105 std::function<std::string()> getter,
109 const wpi::Twine& key, std::function<std::vector<int>()> getter,
113 const wpi::Twine& key, std::function<std::vector<double>()> getter,
117 const wpi::Twine& key, std::function<std::vector<std::string>()> getter,
121 std::function<std::string()> getter,
125 const wpi::Twine& key, std::function<std::shared_ptr<nt::Value>()> getter,
126 std::function<
void(std::shared_ptr<nt::Value>)> setter)
override;
159 : entry(table.GetEntry(key)) {}
161 Property(
const Property&) =
delete;
162 Property& operator=(
const Property&) =
delete;
164 Property(Property&& other) noexcept
165 : entry(other.entry),
166 listener(other.listener),
167 update(std::move(other.update)),
168 createListener(std::move(other.createListener)) {
173 Property& operator=(Property&& other) noexcept {
175 listener = other.listener;
178 update = std::move(other.update);
179 createListener = std::move(other.createListener);
183 ~Property() { StopListener(); }
185 void StartListener() {
186 if (entry && listener == 0 && createListener)
187 listener = createListener(entry);
190 void StopListener() {
191 if (entry && listener != 0) {
192 entry.RemoveListener(listener);
198 NT_EntryListener listener = 0;
203 std::vector<Property> m_properties;
204 std::function<void()> m_safeState;
205 std::vector<std::function<void()>> m_updateTables;
206 std::shared_ptr<nt::NetworkTable> m_table;
208 bool m_actuator =
false;
A network table that knows its subtable path.
Definition: NetworkTable.h:54
void ClearProperties()
Clear properties.
void AddSmallStringArrayProperty(const wpi::Twine &key, std::function< wpi::ArrayRef< std::string >(wpi::SmallVectorImpl< std::string > &buf)> getter, std::function< void(wpi::ArrayRef< std::string >)> setter) override
Add a string array property (SmallVector form).
void AddSmallRawProperty(const wpi::Twine &key, std::function< wpi::StringRef(wpi::SmallVectorImpl< char > &buf)> getter, std::function< void(wpi::StringRef)> setter) override
Add a raw property (SmallVector form).
Definition: SendableBuilderImpl.h:27
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:42
void AddSmallDoubleArrayProperty(const wpi::Twine &key, std::function< wpi::ArrayRef< double >(wpi::SmallVectorImpl< double > &buf)> getter, std::function< void(wpi::ArrayRef< double >)> setter) override
Add a double array property (SmallVector form).
void SetActuator(bool value) override
Set a flag indicating if this sendable should be treated as an actuator.
bool IsActuator() const
Return whether this sendable should be treated as an actuator.
nt::NetworkTableEntry GetEntry(const wpi::Twine &key) override
Add a property without getters or setters.
NetworkTables Entry.
Definition: NetworkTableEntry.h:39
void StartListeners()
Hook setters for all properties.
void AddDoubleArrayProperty(const wpi::Twine &key, std::function< std::vector< double >()> getter, std::function< void(wpi::ArrayRef< double >)> setter) override
Add a double array property.
void AddRawProperty(const wpi::Twine &key, std::function< std::string()> getter, std::function< void(wpi::StringRef)> setter) override
Add a raw property.
void StartLiveWindowMode()
Start LiveWindow mode by hooking the setters for all properties.
void SetSmartDashboardType(const wpi::Twine &type) override
Set the string representation of the named data type that will be used by the smart dashboard for thi...
void SetTable(std::shared_ptr< nt::NetworkTable > table)
Set the network table.
void StopLiveWindowMode()
Stop LiveWindow mode by unhooking the setters for all properties.
bool HasTable() const
Return whether this sendable has an associated table.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void SetUpdateTable(std::function< void()> func) override
Set the function that should be called to update the network table for things other than properties.
void AddSmallStringProperty(const wpi::Twine &key, std::function< wpi::StringRef(wpi::SmallVectorImpl< char > &buf)> getter, std::function< void(wpi::StringRef)> setter) override
Add a string property (SmallString form).
void AddStringProperty(const wpi::Twine &key, std::function< std::string()> getter, std::function< void(wpi::StringRef)> setter) override
Add a string property.
void StopListeners()
Unhook setters for all properties.
void AddBooleanArrayProperty(const wpi::Twine &key, std::function< std::vector< int >()> getter, std::function< void(wpi::ArrayRef< int >)> setter) override
Add a boolean array property.
void SetSafeState(std::function< void()> func) override
Set the function that should be called to set the Sendable into a safe state.
void UpdateTable()
Update the network table values by calling the getters for all properties.
void AddBooleanProperty(const wpi::Twine &key, std::function< bool()> getter, std::function< void(bool)> setter) override
Add a boolean property.
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
void AddStringArrayProperty(const wpi::Twine &key, std::function< std::vector< std::string >()> getter, std::function< void(wpi::ArrayRef< std::string >)> setter) override
Add a string array property.
void AddSmallBooleanArrayProperty(const wpi::Twine &key, std::function< wpi::ArrayRef< int >(wpi::SmallVectorImpl< int > &buf)> getter, std::function< void(wpi::ArrayRef< int >)> setter) override
Add a boolean array property (SmallVector form).
void AddValueProperty(const wpi::Twine &key, std::function< std::shared_ptr< nt::Value >()> getter, std::function< void(std::shared_ptr< nt::Value >)> setter) override
Add a NetworkTableValue property.
void AddDoubleProperty(const wpi::Twine &key, std::function< double()> getter, std::function< void(double)> setter) override
Add a double property.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:85
std::shared_ptr< nt::NetworkTable > GetTable()
Get the network table.
Definition: SendableBuilder.h:23