WPILibC++ 2024.3.2
SendableBuilder.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <functional>
8#include <memory>
9#include <span>
10#include <string>
11#include <string_view>
12#include <vector>
13
14#include "wpi/SmallVector.h"
15
16namespace wpi {
17
18/**
19 * Helper class for building Sendable dashboard representations.
20 */
22 public:
23 /**
24 * The backend kinds used for the sendable builder.
25 */
27 /// Unknown.
29 /// NetworkTables.
31 };
32
33 virtual ~SendableBuilder() = default;
34
35 /**
36 * Set the string representation of the named data type that will be used
37 * by the smart dashboard for this sendable.
38 *
39 * @param type data type
40 */
42
43 /**
44 * Set a flag indicating if this sendable should be treated as an actuator.
45 * By default this flag is false.
46 *
47 * @param value true if actuator, false if not
48 */
49 virtual void SetActuator(bool value) = 0;
50
51 /**
52 * Set the function that should be called to set the Sendable into a safe
53 * state. This is called when entering and exiting Live Window mode.
54 *
55 * @param func function
56 */
57 virtual void SetSafeState(std::function<void()> func) = 0;
58
59 /**
60 * Add a boolean property.
61 *
62 * @param key property name
63 * @param getter getter function (returns current value)
64 * @param setter setter function (sets new value)
65 */
67 std::function<bool()> getter,
68 std::function<void(bool)> setter) = 0;
69
70 /**
71 * Add a constant boolean property.
72 *
73 * @param key property name
74 * @param value the value
75 */
76 virtual void PublishConstBoolean(std::string_view key, bool value) = 0;
77
78 /**
79 * Add an integer property.
80 *
81 * @param key property name
82 * @param getter getter function (returns current value)
83 * @param setter setter function (sets new value)
84 */
86 std::function<int64_t()> getter,
87 std::function<void(int64_t)> setter) = 0;
88
89 /**
90 * Add a constant integer property.
91 *
92 * @param key property name
93 * @param value the value
94 */
95 virtual void PublishConstInteger(std::string_view key, int64_t value) = 0;
96
97 /**
98 * Add a float property.
99 *
100 * @param key property name
101 * @param getter getter function (returns current value)
102 * @param setter setter function (sets new value)
103 */
105 std::function<float()> getter,
106 std::function<void(float)> setter) = 0;
107
108 /**
109 * Add a constant float property.
110 *
111 * @param key property name
112 * @param value the value
113 */
114 virtual void PublishConstFloat(std::string_view key, float value) = 0;
115
116 /**
117 * Add a double property.
118 *
119 * @param key property name
120 * @param getter getter function (returns current value)
121 * @param setter setter function (sets new value)
122 */
124 std::function<double()> getter,
125 std::function<void(double)> setter) = 0;
126
127 /**
128 * Add a constant double property.
129 *
130 * @param key property name
131 * @param value the value
132 */
133 virtual void PublishConstDouble(std::string_view key, double value) = 0;
134
135 /**
136 * Add a string property.
137 *
138 * @param key property name
139 * @param getter getter function (returns current value)
140 * @param setter setter function (sets new value)
141 */
142 virtual void AddStringProperty(
143 std::string_view key, std::function<std::string()> getter,
144 std::function<void(std::string_view)> setter) = 0;
145
146 /**
147 * Add a constant string property.
148 *
149 * @param key property name
150 * @param value the value
151 */
153 std::string_view value) = 0;
154
155 /**
156 * Add a boolean array property.
157 *
158 * @param key property name
159 * @param getter getter function (returns current value)
160 * @param setter setter function (sets new value)
161 */
163 std::string_view key, std::function<std::vector<int>()> getter,
164 std::function<void(std::span<const int>)> setter) = 0;
165
166 /**
167 * Add a constant boolean array property.
168 *
169 * @param key property name
170 * @param value the value
171 */
173 std::span<const int> value) = 0;
174
175 /**
176 * Add an integer array property.
177 *
178 * @param key property name
179 * @param getter getter function (returns current value)
180 * @param setter setter function (sets new value)
181 */
183 std::string_view key, std::function<std::vector<int64_t>()> getter,
184 std::function<void(std::span<const int64_t>)> setter) = 0;
185
186 /**
187 * Add a constant integer array property.
188 *
189 * @param key property name
190 * @param value the value
191 */
193 std::span<const int64_t> value) = 0;
194
195 /**
196 * Add a float array property.
197 *
198 * @param key property name
199 * @param getter getter function (returns current value)
200 * @param setter setter function (sets new value)
201 */
203 std::string_view key, std::function<std::vector<float>()> getter,
204 std::function<void(std::span<const float>)> setter) = 0;
205
206 /**
207 * Add a constant float array property.
208 *
209 * @param key property name
210 * @param value the value
211 */
213 std::span<const float> value) = 0;
214
215 /**
216 * Add a double array property.
217 *
218 * @param key property name
219 * @param getter getter function (returns current value)
220 * @param setter setter function (sets new value)
221 */
223 std::string_view key, std::function<std::vector<double>()> getter,
224 std::function<void(std::span<const double>)> setter) = 0;
225
226 /**
227 * Add a constant double array property.
228 *
229 * @param key property name
230 * @param value the value
231 */
233 std::span<const double> value) = 0;
234
235 /**
236 * Add a string array property.
237 *
238 * @param key property name
239 * @param getter getter function (returns current value)
240 * @param setter setter function (sets new value)
241 */
243 std::string_view key, std::function<std::vector<std::string>()> getter,
244 std::function<void(std::span<const std::string>)> setter) = 0;
245
246 /**
247 * Add a constant string array property.
248 *
249 * @param key property name
250 * @param value the value
251 */
253 std::span<const std::string> value) = 0;
254
255 /**
256 * Add a raw property.
257 *
258 * @param key property name
259 * @param typeString type string
260 * @param getter getter function (returns current value)
261 * @param setter setter function (sets new value)
262 */
263 virtual void AddRawProperty(
264 std::string_view key, std::string_view typeString,
265 std::function<std::vector<uint8_t>()> getter,
266 std::function<void(std::span<const uint8_t>)> setter) = 0;
267
268 /**
269 * Add a constant raw property.
270 *
271 * @param key property name
272 * @param typeString type string
273 * @param value the value
274 */
276 std::string_view typeString,
277 std::span<const uint8_t> value) = 0;
278
279 /**
280 * Add a string property (SmallString form).
281 *
282 * @param key property name
283 * @param getter getter function (returns current value)
284 * @param setter setter function (sets new value)
285 */
288 std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
289 std::function<void(std::string_view)> setter) = 0;
290
291 /**
292 * Add a boolean array property (SmallVector form).
293 *
294 * @param key property name
295 * @param getter getter function (returns current value)
296 * @param setter setter function (sets new value)
297 */
300 std::function<std::span<const int>(wpi::SmallVectorImpl<int>& buf)>
301 getter,
302 std::function<void(std::span<const int>)> setter) = 0;
303
304 /**
305 * Add an integer array property (SmallVector form).
306 *
307 * @param key property name
308 * @param getter getter function (returns current value)
309 * @param setter setter function (sets new value)
310 */
313 std::function<
314 std::span<const int64_t>(wpi::SmallVectorImpl<int64_t>& buf)>
315 getter,
316 std::function<void(std::span<const int64_t>)> setter) = 0;
317
318 /**
319 * Add a float array property (SmallVector form).
320 *
321 * @param key property name
322 * @param getter getter function (returns current value)
323 * @param setter setter function (sets new value)
324 */
327 std::function<std::span<const float>(wpi::SmallVectorImpl<float>& buf)>
328 getter,
329 std::function<void(std::span<const float>)> setter) = 0;
330
331 /**
332 * Add a double array property (SmallVector form).
333 *
334 * @param key property name
335 * @param getter getter function (returns current value)
336 * @param setter setter function (sets new value)
337 */
340 std::function<std::span<const double>(wpi::SmallVectorImpl<double>& buf)>
341 getter,
342 std::function<void(std::span<const double>)> setter) = 0;
343
344 /**
345 * Add a string array property (SmallVector form).
346 *
347 * @param key property name
348 * @param getter getter function (returns current value)
349 * @param setter setter function (sets new value)
350 */
353 std::function<
354 std::span<const std::string>(wpi::SmallVectorImpl<std::string>& buf)>
355 getter,
356 std::function<void(std::span<const std::string>)> setter) = 0;
357
358 /**
359 * Add a raw property (SmallVector form).
360 *
361 * @param key property name
362 * @param typeString type string
363 * @param getter getter function (returns current value)
364 * @param setter setter function (sets new value)
365 */
367 std::string_view key, std::string_view typeString,
368 std::function<std::span<uint8_t>(wpi::SmallVectorImpl<uint8_t>& buf)>
369 getter,
370 std::function<void(std::span<const uint8_t>)> setter) = 0;
371
372 /**
373 * Gets the kind of backend being used.
374 *
375 * @return Backend kind
376 */
377 virtual BackendKind GetBackendKind() const = 0;
378
379 /**
380 * Return whether this sendable has been published.
381 *
382 * @return True if it has been published, false if not.
383 */
384 virtual bool IsPublished() const = 0;
385
386 /**
387 * Update the published values by calling the getters for all properties.
388 */
389 virtual void Update() = 0;
390
391 /**
392 * Clear properties.
393 */
394 virtual void ClearProperties() = 0;
395};
396
397} // namespace wpi
This file defines the SmallVector class.
Helper class for building Sendable dashboard representations.
Definition: SendableBuilder.h:21
virtual void PublishConstBoolean(std::string_view key, bool value)=0
Add a constant boolean property.
virtual void AddDoubleProperty(std::string_view key, std::function< double()> getter, std::function< void(double)> setter)=0
Add a double property.
virtual void PublishConstBooleanArray(std::string_view key, std::span< const int > value)=0
Add a constant boolean array property.
virtual void PublishConstString(std::string_view key, std::string_view value)=0
Add a constant string property.
virtual void PublishConstRaw(std::string_view key, std::string_view typeString, std::span< const uint8_t > value)=0
Add a constant raw property.
virtual void AddSmallBooleanArrayProperty(std::string_view key, std::function< std::span< const int >(wpi::SmallVectorImpl< int > &buf)> getter, std::function< void(std::span< const int >)> setter)=0
Add a boolean array property (SmallVector form).
virtual ~SendableBuilder()=default
virtual 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)=0
Add a raw property.
virtual void PublishConstFloatArray(std::string_view key, std::span< const float > value)=0
Add a constant float array property.
virtual void AddStringArrayProperty(std::string_view key, std::function< std::vector< std::string >()> getter, std::function< void(std::span< const std::string >)> setter)=0
Add a string array property.
virtual void AddFloatProperty(std::string_view key, std::function< float()> getter, std::function< void(float)> setter)=0
Add a float property.
virtual void SetSmartDashboardType(std::string_view type)=0
Set the string representation of the named data type that will be used by the smart dashboard for thi...
virtual void ClearProperties()=0
Clear properties.
virtual void AddBooleanArrayProperty(std::string_view key, std::function< std::vector< int >()> getter, std::function< void(std::span< const int >)> setter)=0
Add a boolean array property.
virtual void PublishConstIntegerArray(std::string_view key, std::span< const int64_t > value)=0
Add a constant integer array property.
virtual void AddSmallStringArrayProperty(std::string_view key, std::function< std::span< const std::string >(wpi::SmallVectorImpl< std::string > &buf)> getter, std::function< void(std::span< const std::string >)> setter)=0
Add a string array property (SmallVector form).
virtual void AddSmallDoubleArrayProperty(std::string_view key, std::function< std::span< const double >(wpi::SmallVectorImpl< double > &buf)> getter, std::function< void(std::span< const double >)> setter)=0
Add a double array property (SmallVector form).
virtual void PublishConstFloat(std::string_view key, float value)=0
Add a constant float property.
virtual void AddBooleanProperty(std::string_view key, std::function< bool()> getter, std::function< void(bool)> setter)=0
Add a boolean property.
virtual void AddSmallIntegerArrayProperty(std::string_view key, std::function< std::span< const int64_t >(wpi::SmallVectorImpl< int64_t > &buf)> getter, std::function< void(std::span< const int64_t >)> setter)=0
Add an integer array property (SmallVector form).
virtual void AddSmallFloatArrayProperty(std::string_view key, std::function< std::span< const float >(wpi::SmallVectorImpl< float > &buf)> getter, std::function< void(std::span< const float >)> setter)=0
Add a float array property (SmallVector form).
virtual void AddFloatArrayProperty(std::string_view key, std::function< std::vector< float >()> getter, std::function< void(std::span< const float >)> setter)=0
Add a float array property.
virtual void AddSmallStringProperty(std::string_view key, std::function< std::string_view(wpi::SmallVectorImpl< char > &buf)> getter, std::function< void(std::string_view)> setter)=0
Add a string property (SmallString form).
virtual void SetSafeState(std::function< void()> func)=0
Set the function that should be called to set the Sendable into a safe state.
virtual void PublishConstStringArray(std::string_view key, std::span< const std::string > value)=0
Add a constant string array property.
virtual void Update()=0
Update the published values by calling the getters for all properties.
virtual void AddSmallRawProperty(std::string_view key, std::string_view typeString, std::function< std::span< uint8_t >(wpi::SmallVectorImpl< uint8_t > &buf)> getter, std::function< void(std::span< const uint8_t >)> setter)=0
Add a raw property (SmallVector form).
virtual void PublishConstDoubleArray(std::string_view key, std::span< const double > value)=0
Add a constant double array property.
virtual void PublishConstDouble(std::string_view key, double value)=0
Add a constant double property.
BackendKind
The backend kinds used for the sendable builder.
Definition: SendableBuilder.h:26
@ kNetworkTables
NetworkTables.
Definition: SendableBuilder.h:30
@ kUnknown
Unknown.
Definition: SendableBuilder.h:28
virtual void PublishConstInteger(std::string_view key, int64_t value)=0
Add a constant integer property.
virtual void SetActuator(bool value)=0
Set a flag indicating if this sendable should be treated as an actuator.
virtual BackendKind GetBackendKind() const =0
Gets the kind of backend being used.
virtual void AddIntegerProperty(std::string_view key, std::function< int64_t()> getter, std::function< void(int64_t)> setter)=0
Add an integer property.
virtual bool IsPublished() const =0
Return whether this sendable has been published.
virtual void AddStringProperty(std::string_view key, std::function< std::string()> getter, std::function< void(std::string_view)> setter)=0
Add a string property.
virtual void AddDoubleArrayProperty(std::string_view key, std::function< std::vector< double >()> getter, std::function< void(std::span< const double >)> setter)=0
Add a double array property.
virtual void AddIntegerArrayProperty(std::string_view key, std::function< std::vector< int64_t >()> getter, std::function< void(std::span< const int64_t >)> setter)=0
Add an integer array property.
basic_string_view< char > string_view
Definition: core.h:501
type
Definition: core.h:556
Definition: ntcore_cpp.h:26