20#include "wpi/util/SmallVector.hpp"
40 void SetTable(std::shared_ptr<wpi::nt::NetworkTable> table);
46 std::shared_ptr<wpi::nt::NetworkTable>
GetTable()
override;
87 std::function<
void(
bool)> setter)
override;
92 std::function<
void(int64_t)> setter)
override;
97 std::function<
void(
float)> setter)
override;
102 std::function<
void(
double)> setter)
override;
107 std::function<std::string()> getter,
108 std::function<
void(std::string_view)> setter)
override;
111 std::string_view value)
override;
114 std::string_view key, std::function<std::vector<int>()> getter,
115 std::function<
void(std::span<const int>)> setter)
override;
118 std::span<const int> value)
override;
121 std::string_view key, std::function<std::vector<int64_t>()> getter,
122 std::function<
void(std::span<const int64_t>)> setter)
override;
125 std::span<const int64_t> value)
override;
128 std::string_view key, std::function<std::vector<float>()> getter,
129 std::function<
void(std::span<const float>)> setter)
override;
132 std::span<const float> value)
override;
135 std::string_view key, std::function<std::vector<double>()> getter,
136 std::function<
void(std::span<const double>)> setter)
override;
139 std::span<const double> value)
override;
142 std::string_view key, std::function<std::vector<std::string>()> getter,
143 std::function<
void(std::span<const std::string>)> setter)
override;
146 std::span<const std::string> value)
override;
149 std::string_view key, std::string_view typeString,
150 std::function<std::vector<uint8_t>()> getter,
151 std::function<
void(std::span<const uint8_t>)> setter)
override;
154 std::span<const uint8_t> value)
override;
157 std::string_view key,
160 std::function<
void(std::string_view)> setter)
override;
163 std::string_view key,
166 std::function<
void(std::span<const int>)> setter)
override;
169 std::string_view key,
173 std::function<
void(std::span<const int64_t>)> setter)
override;
176 std::string_view key,
180 std::function<
void(std::span<const float>)> setter)
override;
183 std::string_view key,
187 std::function<
void(std::span<const double>)> setter)
override;
190 std::string_view key,
191 std::function<std::span<const std::string>(
194 std::function<
void(std::span<const std::string>)> setter)
override;
197 std::string_view key, std::string_view typeString,
201 std::function<
void(std::span<const uint8_t>)> setter)
override;
205 virtual ~Property() =
default;
206 virtual void Update(
bool controllable, int64_t time) = 0;
209 template <
typename Topic>
210 struct PropertyImpl :
public Property {
211 void Update(
bool controllable, int64_t time)
override;
213 using Publisher =
typename Topic::PublisherType;
214 using Subscriber =
typename Topic::SubscriberType;
217 std::function<void(Publisher& pub, int64_t time)> updateNetwork;
218 std::function<void(Subscriber& sub)> updateLocal;
221 template <
typename Topic,
typename Getter,
typename Setter>
222 void AddPropertyImpl(Topic topic, Getter getter, Setter setter);
224 template <
typename Topic,
typename Value>
225 void PublishConstImpl(Topic topic, Value value);
227 template <
typename T,
size_t Size,
typename Topic,
typename Getter,
229 void AddSmallPropertyImpl(Topic topic, Getter getter, Setter setter);
231 std::vector<std::unique_ptr<Property>> m_properties;
233 std::shared_ptr<wpi::nt::NetworkTable> m_table;
234 bool m_controllable =
false;
235 bool m_actuator =
false;
SendableBuilderImpl()=default
void AddStringProperty(std::string_view key, std::function< std::string()> getter, std::function< void(std::string_view)> setter) override
Add a string property.
void AddFloatArrayProperty(std::string_view key, std::function< std::vector< float >()> getter, std::function< void(std::span< const float >)> setter) override
Add a float array property.
void PublishConstDouble(std::string_view key, double value) override
Add a constant double property.
void AddSmallBooleanArrayProperty(std::string_view key, std::function< std::span< const int >(wpi::util::SmallVectorImpl< int > &buf)> getter, std::function< void(std::span< const int >)> setter) override
void PublishConstStringArray(std::string_view key, std::span< const std::string > value) override
Add a constant string array property.
void PublishConstFloat(std::string_view key, float value) override
Add a constant float property.
void AddRawProperty(std::string_view key, std::string_view typeString, std::function< std::vector< uint8_t >()> getter, std::function< void(std::span< const uint8_t >)> setter) override
Add a raw property.
void AddSmallStringArrayProperty(std::string_view key, std::function< std::span< const std::string >(wpi::util::SmallVectorImpl< std::string > &buf)> getter, std::function< void(std::span< const std::string >)> setter) override
void PublishConstRaw(std::string_view key, std::string_view typeString, std::span< const uint8_t > value) override
Add a constant raw property.
void StartListeners()
Hook setters for all properties.
void AddIntegerProperty(std::string_view key, std::function< int64_t()> getter, std::function< void(int64_t)> setter) override
Add an integer property.
void SetUpdateTable(wpi::util::unique_function< void()> func) override
Set the function that should be called to update the network table for things other than properties.
void ClearProperties() override
Clear properties.
void AddSmallFloatArrayProperty(std::string_view key, std::function< std::span< const float >(wpi::util::SmallVectorImpl< float > &buf)> getter, std::function< void(std::span< const float >)> setter) override
void AddBooleanProperty(std::string_view key, std::function< bool()> getter, std::function< void(bool)> setter) override
Add a boolean property.
void PublishConstInteger(std::string_view key, int64_t value) override
Add a constant integer property.
void StopListeners()
Unhook setters for all properties.
void PublishConstFloatArray(std::string_view key, std::span< const float > value) override
Add a constant float array property.
void AddSmallIntegerArrayProperty(std::string_view key, std::function< std::span< const int64_t >(wpi::util::SmallVectorImpl< int64_t > &buf)> getter, std::function< void(std::span< const int64_t >)> setter) override
void PublishConstIntegerArray(std::string_view key, std::span< const int64_t > value) override
Add a constant integer array property.
void PublishConstString(std::string_view key, std::string_view value) override
Add a constant string property.
void SetSmartDashboardType(std::string_view type) override
Set the string representation of the named data type that will be used by the smart dashboard for thi...
void AddStringArrayProperty(std::string_view key, std::function< std::vector< std::string >()> getter, std::function< void(std::span< const std::string >)> setter) override
Add a string array property.
void PublishConstBoolean(std::string_view key, bool value) override
Add a constant boolean property.
void SetTable(std::shared_ptr< wpi::nt::NetworkTable > table)
Set the network table.
SendableBuilderImpl(SendableBuilderImpl &&)=default
bool IsActuator() const
Return whether this sendable should be treated as an actuator.
void Update() override
Synchronize with network table values by calling the getters for all properties and setters when the ...
void AddIntegerArrayProperty(std::string_view key, std::function< std::vector< int64_t >()> getter, std::function< void(std::span< const int64_t >)> setter) override
Add an integer array property.
wpi::nt::Topic GetTopic(std::string_view key) override
Add a property without getters or setters.
void AddSmallRawProperty(std::string_view key, std::string_view typeString, std::function< std::span< uint8_t >(wpi::util::SmallVectorImpl< uint8_t > &buf)> getter, std::function< void(std::span< const uint8_t >)> setter) override
std::shared_ptr< wpi::nt::NetworkTable > GetTable() override
Get the network table.
void PublishConstBooleanArray(std::string_view key, std::span< const int > value) override
Add a constant boolean array property.
bool IsPublished() const override
Return whether this sendable has an associated table.
void PublishConstDoubleArray(std::string_view key, std::span< const double > value) override
Add a constant double array property.
void AddDoubleProperty(std::string_view key, std::function< double()> getter, std::function< void(double)> setter) override
Add a double property.
SendableBuilderImpl & operator=(SendableBuilderImpl &&)=default
void SetActuator(bool value) override
Set a flag indicating if this sendable should be treated as an actuator.
void AddSmallDoubleArrayProperty(std::string_view key, std::function< std::span< const double >(wpi::util::SmallVectorImpl< double > &buf)> getter, std::function< void(std::span< const double >)> setter) override
void AddSmallStringProperty(std::string_view key, std::function< std::string_view(wpi::util::SmallVectorImpl< char > &buf)> getter, std::function< void(std::string_view)> setter) override
void AddFloatProperty(std::string_view key, std::function< float()> getter, std::function< void(float)> setter) override
Add a float property.
void AddDoubleArrayProperty(std::string_view key, std::function< std::vector< double >()> getter, std::function< void(std::span< const double >)> setter) override
Add a double array property.
void AddBooleanArrayProperty(std::string_view key, std::function< std::vector< int >()> getter, std::function< void(std::span< const int >)> setter) override
Add a boolean array property.
~SendableBuilderImpl() override=default
NetworkTables Boolean publisher.
Definition BooleanTopic.hpp:127
Helper class for building Sendable dashboard representations for NetworkTables.
Definition NTSendableBuilder.hpp:21
NetworkTables String publisher.
Definition StringTopic.hpp:184
NetworkTables Topic.
Definition Topic.hpp:27
Definition BooleanTopic.hpp:24
unique_function is a type-erasing functor similar to std::function.
Definition FunctionExtras.hpp:57
Definition CvSource.hpp:15