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 "SendableBuilder.h" 41 void SetTable(std::shared_ptr<nt::NetworkTable> table);
47 std::shared_ptr<nt::NetworkTable>
GetTable();
82 std::function<
void(
bool)> setter)
override;
85 std::function<
void(
double)> setter)
override;
88 std::function<std::string()> getter,
92 const wpi::Twine& key, std::function<std::vector<int>()> getter,
96 const wpi::Twine& key, std::function<std::vector<double>()> getter,
100 const wpi::Twine& key, std::function<std::vector<std::string>()> getter,
104 std::function<std::string()> getter,
108 const wpi::Twine& key, std::function<std::shared_ptr<nt::Value>()> getter,
109 std::function<
void(std::shared_ptr<nt::Value>)> setter)
override;
142 : entry(table.GetEntry(key)) {}
144 Property(
const Property&) =
delete;
145 Property& operator=(
const Property&) =
delete;
147 Property(Property&& other) noexcept
148 : entry(other.entry),
149 listener(other.listener),
150 update(std::move(other.update)),
151 createListener(std::move(other.createListener)) {
156 Property& operator=(Property&& other) noexcept {
158 listener = other.listener;
161 update = std::move(other.update);
162 createListener = std::move(other.createListener);
166 ~Property() { StopListener(); }
168 void StartListener() {
169 if (entry && listener == 0 && createListener)
170 listener = createListener(entry);
173 void StopListener() {
174 if (entry && listener != 0) {
175 entry.RemoveListener(listener);
181 NT_EntryListener listener = 0;
182 std::function<void(nt::NetworkTableEntry entry, uint64_t time)> update;
183 std::function<NT_EntryListener(nt::NetworkTableEntry entry)> createListener;
186 std::vector<Property> m_properties;
187 std::function<void()> m_safeState;
188 std::function<void()> m_updateTable;
189 std::shared_ptr<nt::NetworkTable> m_table;
Definition: Utility.cpp:119
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.cpp:350
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).
Definition: SendableBuilderImpl.cpp:272
void SetSafeState(std::function< void()> func) override
Set the function that should be called to set the Sendable into a safe state.
Definition: SendableBuilderImpl.cpp:54
void AddStringProperty(const wpi::Twine &key, std::function< std::string()> getter, std::function< void(wpi::StringRef)> setter) override
Add a string property.
Definition: SendableBuilderImpl.cpp:112
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:41
void StopLiveWindowMode()
Stop LiveWindow mode by unhooking the setters for all properties.
Definition: SendableBuilderImpl.cpp:45
nt::NetworkTableEntry GetEntry(const wpi::Twine &key) override
Add a property without getters or setters.
Definition: SendableBuilderImpl.cpp:62
std::shared_ptr< nt::NetworkTable > GetTable()
Get the network table.
Definition: SendableBuilderImpl.cpp:20
void SetTable(std::shared_ptr< nt::NetworkTable > table)
Set the network table.
Definition: SendableBuilderImpl.cpp: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.
Definition: SendableBuilderImpl.cpp:181
void SetUpdateTable(std::function< void()> func) override
Set the function that should be called to update the network table for things other than properties...
Definition: SendableBuilderImpl.cpp:58
void AddBooleanProperty(const wpi::Twine &key, std::function< bool()> getter, std::function< void(bool)> setter) override
Add a boolean property.
Definition: SendableBuilderImpl.cpp:66
void StartLiveWindowMode()
Start LiveWindow mode by hooking the setters for all properties.
Definition: SendableBuilderImpl.cpp:40
Definition: SendableBuilderImpl.h:27
void AddRawProperty(const wpi::Twine &key, std::function< std::string()> getter, std::function< void(wpi::StringRef)> setter) override
Add a raw property.
Definition: SendableBuilderImpl.cpp:204
void UpdateTable()
Update the network table values by calling the getters for all properties.
Definition: SendableBuilderImpl.cpp:24
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
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.
Definition: SendableBuilderImpl.cpp:135
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.
Definition: SendableBuilderImpl.cpp:158
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).
Definition: SendableBuilderImpl.cpp:297
Definition: SendableBuilder.h:23
NetworkTables Entry.
Definition: NetworkTableEntry.h:35
void StartListeners()
Hook setters for all properties.
Definition: SendableBuilderImpl.cpp:32
void AddDoubleProperty(const wpi::Twine &key, std::function< double()> getter, std::function< void(double)> setter) override
Add a double property.
Definition: SendableBuilderImpl.cpp:89
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...
Definition: SendableBuilderImpl.cpp:50
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).
Definition: SendableBuilderImpl.cpp:247
A network table that knows its subtable path.
Definition: NetworkTable.h:44
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
void StopListeners()
Unhook setters for all properties.
Definition: SendableBuilderImpl.cpp:36
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.
Definition: SendableBuilderImpl.cpp:227
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).
Definition: SendableBuilderImpl.cpp:323