WPILibC++ 2024.1.1-beta-4
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
19 public:
20 /**
21 * The backend kinds used for the sendable builder.
22 */
24
25 virtual ~SendableBuilder() = default;
26
27 /**
28 * Set the string representation of the named data type that will be used
29 * by the smart dashboard for this sendable.
30 *
31 * @param type data type
32 */
34
35 /**
36 * Set a flag indicating if this sendable should be treated as an actuator.
37 * By default this flag is false.
38 *
39 * @param value true if actuator, false if not
40 */
41 virtual void SetActuator(bool value) = 0;
42
43 /**
44 * Set the function that should be called to set the Sendable into a safe
45 * state. This is called when entering and exiting Live Window mode.
46 *
47 * @param func function
48 */
49 virtual void SetSafeState(std::function<void()> func) = 0;
50
51 /**
52 * Add a boolean property.
53 *
54 * @param key property name
55 * @param getter getter function (returns current value)
56 * @param setter setter function (sets new value)
57 */
59 std::function<bool()> getter,
60 std::function<void(bool)> setter) = 0;
61
62 /**
63 * Add a constant boolean property.
64 *
65 * @param key property name
66 * @param value the value
67 */
68 virtual void PublishConstBoolean(std::string_view key, bool value) = 0;
69
70 /**
71 * Add an integer property.
72 *
73 * @param key property name
74 * @param getter getter function (returns current value)
75 * @param setter setter function (sets new value)
76 */
78 std::function<int64_t()> getter,
79 std::function<void(int64_t)> setter) = 0;
80
81 /**
82 * Add a constant integer property.
83 *
84 * @param key property name
85 * @param value the value
86 */
87 virtual void PublishConstInteger(std::string_view key, int64_t value) = 0;
88
89 /**
90 * Add a float property.
91 *
92 * @param key property name
93 * @param getter getter function (returns current value)
94 * @param setter setter function (sets new value)
95 */
97 std::function<float()> getter,
98 std::function<void(float)> setter) = 0;
99
100 /**
101 * Add a constant float property.
102 *
103 * @param key property name
104 * @param value the value
105 */
106 virtual void PublishConstFloat(std::string_view key, float value) = 0;
107
108 /**
109 * Add a double property.
110 *
111 * @param key property name
112 * @param getter getter function (returns current value)
113 * @param setter setter function (sets new value)
114 */
116 std::function<double()> getter,
117 std::function<void(double)> setter) = 0;
118
119 /**
120 * Add a constant double property.
121 *
122 * @param key property name
123 * @param value the value
124 */
125 virtual void PublishConstDouble(std::string_view key, double value) = 0;
126
127 /**
128 * Add a string property.
129 *
130 * @param key property name
131 * @param getter getter function (returns current value)
132 * @param setter setter function (sets new value)
133 */
134 virtual void AddStringProperty(
135 std::string_view key, std::function<std::string()> getter,
136 std::function<void(std::string_view)> setter) = 0;
137
138 /**
139 * Add a constant string property.
140 *
141 * @param key property name
142 * @param value the value
143 */
145 std::string_view value) = 0;
146
147 /**
148 * Add a boolean array property.
149 *
150 * @param key property name
151 * @param getter getter function (returns current value)
152 * @param setter setter function (sets new value)
153 */
155 std::string_view key, std::function<std::vector<int>()> getter,
156 std::function<void(std::span<const int>)> setter) = 0;
157
158 /**
159 * Add a constant boolean array property.
160 *
161 * @param key property name
162 * @param value the value
163 */
165 std::span<const int> value) = 0;
166
167 /**
168 * Add an integer array property.
169 *
170 * @param key property name
171 * @param getter getter function (returns current value)
172 * @param setter setter function (sets new value)
173 */
175 std::string_view key, std::function<std::vector<int64_t>()> getter,
176 std::function<void(std::span<const int64_t>)> setter) = 0;
177
178 /**
179 * Add a constant integer array property.
180 *
181 * @param key property name
182 * @param value the value
183 */
185 std::span<const int64_t> value) = 0;
186
187 /**
188 * Add a float array property.
189 *
190 * @param key property name
191 * @param getter getter function (returns current value)
192 * @param setter setter function (sets new value)
193 */
195 std::string_view key, std::function<std::vector<float>()> getter,
196 std::function<void(std::span<const float>)> setter) = 0;
197
198 /**
199 * Add a constant float array property.
200 *
201 * @param key property name
202 * @param value the value
203 */
205 std::span<const float> value) = 0;
206
207 /**
208 * Add a double array property.
209 *
210 * @param key property name
211 * @param getter getter function (returns current value)
212 * @param setter setter function (sets new value)
213 */
215 std::string_view key, std::function<std::vector<double>()> getter,
216 std::function<void(std::span<const double>)> setter) = 0;
217
218 /**
219 * Add a constant double array property.
220 *
221 * @param key property name
222 * @param value the value
223 */
225 std::span<const double> value) = 0;
226
227 /**
228 * Add a string array property.
229 *
230 * @param key property name
231 * @param getter getter function (returns current value)
232 * @param setter setter function (sets new value)
233 */
235 std::string_view key, std::function<std::vector<std::string>()> getter,
236 std::function<void(std::span<const std::string>)> setter) = 0;
237
238 /**
239 * Add a constant string array property.
240 *
241 * @param key property name
242 * @param value the value
243 */
245 std::span<const std::string> value) = 0;
246
247 /**
248 * Add a raw property.
249 *
250 * @param key property name
251 * @param typeString type string
252 * @param getter getter function (returns current value)
253 * @param setter setter function (sets new value)
254 */
255 virtual void AddRawProperty(
256 std::string_view key, std::string_view typeString,
257 std::function<std::vector<uint8_t>()> getter,
258 std::function<void(std::span<const uint8_t>)> setter) = 0;
259
260 /**
261 * Add a constant raw property.
262 *
263 * @param key property name
264 * @param typeString type string
265 * @param value the value
266 */
268 std::string_view typeString,
269 std::span<const uint8_t> value) = 0;
270
271 /**
272 * Add a string property (SmallString form).
273 *
274 * @param key property name
275 * @param getter getter function (returns current value)
276 * @param setter setter function (sets new value)
277 */
280 std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
281 std::function<void(std::string_view)> setter) = 0;
282
283 /**
284 * Add a boolean array property (SmallVector form).
285 *
286 * @param key property name
287 * @param getter getter function (returns current value)
288 * @param setter setter function (sets new value)
289 */
292 std::function<std::span<const int>(wpi::SmallVectorImpl<int>& buf)>
293 getter,
294 std::function<void(std::span<const int>)> setter) = 0;
295
296 /**
297 * Add an integer array property (SmallVector form).
298 *
299 * @param key property name
300 * @param getter getter function (returns current value)
301 * @param setter setter function (sets new value)
302 */
305 std::function<
306 std::span<const int64_t>(wpi::SmallVectorImpl<int64_t>& buf)>
307 getter,
308 std::function<void(std::span<const int64_t>)> setter) = 0;
309
310 /**
311 * Add a float array property (SmallVector form).
312 *
313 * @param key property name
314 * @param getter getter function (returns current value)
315 * @param setter setter function (sets new value)
316 */
319 std::function<std::span<const float>(wpi::SmallVectorImpl<float>& buf)>
320 getter,
321 std::function<void(std::span<const float>)> setter) = 0;
322
323 /**
324 * Add a double array property (SmallVector form).
325 *
326 * @param key property name
327 * @param getter getter function (returns current value)
328 * @param setter setter function (sets new value)
329 */
332 std::function<std::span<const double>(wpi::SmallVectorImpl<double>& buf)>
333 getter,
334 std::function<void(std::span<const double>)> setter) = 0;
335
336 /**
337 * Add a string array property (SmallVector form).
338 *
339 * @param key property name
340 * @param getter getter function (returns current value)
341 * @param setter setter function (sets new value)
342 */
345 std::function<
346 std::span<const std::string>(wpi::SmallVectorImpl<std::string>& buf)>
347 getter,
348 std::function<void(std::span<const std::string>)> setter) = 0;
349
350 /**
351 * Add a raw property (SmallVector form).
352 *
353 * @param key property name
354 * @param typeString type string
355 * @param getter getter function (returns current value)
356 * @param setter setter function (sets new value)
357 */
359 std::string_view key, std::string_view typeString,
360 std::function<std::span<uint8_t>(wpi::SmallVectorImpl<uint8_t>& buf)>
361 getter,
362 std::function<void(std::span<const uint8_t>)> setter) = 0;
363
364 /**
365 * Gets the kind of backend being used.
366 *
367 * @return Backend kind
368 */
369 virtual BackendKind GetBackendKind() const = 0;
370
371 /**
372 * Return whether this sendable has been published.
373 *
374 * @return True if it has been published, false if not.
375 */
376 virtual bool IsPublished() const = 0;
377
378 /**
379 * Update the published values by calling the getters for all properties.
380 */
381 virtual void Update() = 0;
382
383 /**
384 * Clear properties.
385 */
386 virtual void ClearProperties() = 0;
387};
388
389} // namespace wpi
This file defines the SmallVector class.
Definition: SendableBuilder.h:18
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:23
@ kNetworkTables
Definition: SendableBuilder.h:23
@ kUnknown
Definition: SendableBuilder.h:23
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