16 #include <llvm/ArrayRef.h> 17 #include <llvm/SmallVector.h> 18 #include <llvm/Twine.h> 19 #include <networktables/NetworkTable.h> 20 #include <networktables/NetworkTableEntry.h> 21 #include <networktables/NetworkTableValue.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 llvm::Twine& key, std::function<std::vector<int>()> getter,
96 const llvm::Twine& key, std::function<std::vector<double>()> getter,
100 const llvm::Twine& key, std::function<std::vector<std::string>()> getter,
104 std::function<std::string()> getter,
109 std::function<std::shared_ptr<nt::Value>()> getter,
110 std::function<
void(std::shared_ptr<nt::Value>)> setter)
override;
144 : entry(table.GetEntry(key)) {}
146 Property(
const Property&) =
delete;
147 Property& operator=(
const Property&) =
delete;
149 Property(Property&& other) noexcept
150 : entry(other.entry),
151 listener(other.listener),
152 update(std::move(other.update)),
153 createListener(std::move(other.createListener)) {
158 Property& operator=(Property&& other) noexcept {
160 listener = other.listener;
163 update = std::move(other.update);
164 createListener = std::move(other.createListener);
168 ~Property() { StopListener(); }
170 void StartListener() {
171 if (entry && listener == 0 && createListener)
172 listener = createListener(entry);
175 void StopListener() {
176 if (entry && listener != 0) {
177 entry.RemoveListener(listener);
183 NT_EntryListener listener = 0;
184 std::function<void(nt::NetworkTableEntry entry, uint64_t time)> update;
185 std::function<NT_EntryListener(nt::NetworkTableEntry entry)> createListener;
188 std::vector<Property> m_properties;
189 std::function<void()> m_safeState;
190 std::function<void()> m_updateTable;
191 std::shared_ptr<nt::NetworkTable> m_table;
Definition: RobotController.cpp:14
void AddBooleanArrayProperty(const llvm::Twine &key, std::function< std::vector< int >()> getter, std::function< void(llvm::ArrayRef< int >)> setter) override
Add a boolean array property.
Definition: SendableBuilderImpl.cpp:135
void AddSmallRawProperty(const llvm::Twine &key, std::function< llvm::StringRef(llvm::SmallVectorImpl< char > &buf)> getter, std::function< void(llvm::StringRef)> setter) override
Add a raw property (SmallVector form).
Definition: SendableBuilderImpl.cpp:350
void AddSmallDoubleArrayProperty(const llvm::Twine &key, std::function< llvm::ArrayRef< double >(llvm::SmallVectorImpl< double > &buf)> getter, std::function< void(llvm::ArrayRef< double >)> setter) override
Add a double array property (SmallVector form).
Definition: SendableBuilderImpl.cpp:297
void AddSmallStringProperty(const llvm::Twine &key, std::function< llvm::StringRef(llvm::SmallVectorImpl< char > &buf)> getter, std::function< void(llvm::StringRef)> setter) override
Add a string property (SmallString form).
Definition: SendableBuilderImpl.cpp:247
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
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
void AddValueProperty(const llvm::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 StopLiveWindowMode()
Stop LiveWindow mode by unhooking the setters for all properties.
Definition: SendableBuilderImpl.cpp:45
void AddSmallBooleanArrayProperty(const llvm::Twine &key, std::function< llvm::ArrayRef< int >(llvm::SmallVectorImpl< int > &buf)> getter, std::function< void(llvm::ArrayRef< int >)> setter) override
Add a boolean array property (SmallVector form).
Definition: SendableBuilderImpl.cpp:272
void AddBooleanProperty(const llvm::Twine &key, std::function< bool()> getter, std::function< void(bool)> setter) override
Add a boolean property.
Definition: SendableBuilderImpl.cpp:66
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:32
void AddStringArrayProperty(const llvm::Twine &key, std::function< std::vector< std::string >()> getter, std::function< void(llvm::ArrayRef< std::string >)> setter) override
Add a string array property.
Definition: SendableBuilderImpl.cpp:181
void AddRawProperty(const llvm::Twine &key, std::function< std::string()> getter, std::function< void(llvm::StringRef)> setter) override
Add a raw property.
Definition: SendableBuilderImpl.cpp:204
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 AddSmallStringArrayProperty(const llvm::Twine &key, std::function< llvm::ArrayRef< std::string >(llvm::SmallVectorImpl< std::string > &buf)> getter, std::function< void(llvm::ArrayRef< std::string >)> setter) override
Add a string array property (SmallVector form).
Definition: SendableBuilderImpl.cpp:323
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 SetSmartDashboardType(const llvm::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 StartLiveWindowMode()
Start LiveWindow mode by hooking the setters for all properties.
Definition: SendableBuilderImpl.cpp:40
Definition: SendableBuilderImpl.h:27
void AddDoubleProperty(const llvm::Twine &key, std::function< double()> getter, std::function< void(double)> setter) override
Add a double property.
Definition: SendableBuilderImpl.cpp:89
void UpdateTable()
Update the network table values by calling the getters for all properties.
Definition: SendableBuilderImpl.cpp:24
void AddDoubleArrayProperty(const llvm::Twine &key, std::function< std::vector< double >()> getter, std::function< void(llvm::ArrayRef< double >)> setter) override
Add a double array property.
Definition: SendableBuilderImpl.cpp:158
void AddStringProperty(const llvm::Twine &key, std::function< std::string()> getter, std::function< void(llvm::StringRef)> setter) override
Add a string property.
Definition: SendableBuilderImpl.cpp:112
Definition: SendableBuilder.h:23
NetworkTables Entry.
Definition: NetworkTableEntry.h:35
void StartListeners()
Hook setters for all properties.
Definition: SendableBuilderImpl.cpp:32
nt::NetworkTableEntry GetEntry(const llvm::Twine &key) override
Add a property without getters or setters.
Definition: SendableBuilderImpl.cpp:62
A network table that knows its subtable path.
Definition: NetworkTable.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42
void StopListeners()
Unhook setters for all properties.
Definition: SendableBuilderImpl.cpp:36