WPILibC++ 2023.4.3
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 an integer property.
64 *
65 * @param key property name
66 * @param getter getter function (returns current value)
67 * @param setter setter function (sets new value)
68 */
70 std::function<int64_t()> getter,
71 std::function<void(int64_t)> setter) = 0;
72
73 /**
74 * Add a float property.
75 *
76 * @param key property name
77 * @param getter getter function (returns current value)
78 * @param setter setter function (sets new value)
79 */
81 std::function<float()> getter,
82 std::function<void(float)> setter) = 0;
83
84 /**
85 * Add a double property.
86 *
87 * @param key property name
88 * @param getter getter function (returns current value)
89 * @param setter setter function (sets new value)
90 */
92 std::function<double()> getter,
93 std::function<void(double)> setter) = 0;
94
95 /**
96 * Add a string property.
97 *
98 * @param key property name
99 * @param getter getter function (returns current value)
100 * @param setter setter function (sets new value)
101 */
102 virtual void AddStringProperty(
103 std::string_view key, std::function<std::string()> getter,
104 std::function<void(std::string_view)> setter) = 0;
105
106 /**
107 * Add a boolean array property.
108 *
109 * @param key property name
110 * @param getter getter function (returns current value)
111 * @param setter setter function (sets new value)
112 */
114 std::string_view key, std::function<std::vector<int>()> getter,
115 std::function<void(std::span<const int>)> setter) = 0;
116
117 /**
118 * Add an integer array property.
119 *
120 * @param key property name
121 * @param getter getter function (returns current value)
122 * @param setter setter function (sets new value)
123 */
125 std::string_view key, std::function<std::vector<int64_t>()> getter,
126 std::function<void(std::span<const int64_t>)> setter) = 0;
127
128 /**
129 * Add a float array property.
130 *
131 * @param key property name
132 * @param getter getter function (returns current value)
133 * @param setter setter function (sets new value)
134 */
136 std::string_view key, std::function<std::vector<float>()> getter,
137 std::function<void(std::span<const float>)> setter) = 0;
138
139 /**
140 * Add a double array property.
141 *
142 * @param key property name
143 * @param getter getter function (returns current value)
144 * @param setter setter function (sets new value)
145 */
147 std::string_view key, std::function<std::vector<double>()> getter,
148 std::function<void(std::span<const double>)> setter) = 0;
149
150 /**
151 * Add a string array property.
152 *
153 * @param key property name
154 * @param getter getter function (returns current value)
155 * @param setter setter function (sets new value)
156 */
158 std::string_view key, std::function<std::vector<std::string>()> getter,
159 std::function<void(std::span<const std::string>)> setter) = 0;
160
161 /**
162 * Add a raw property.
163 *
164 * @param key property name
165 * @param typeString type string
166 * @param getter getter function (returns current value)
167 * @param setter setter function (sets new value)
168 */
169 virtual void AddRawProperty(
170 std::string_view key, std::string_view typeString,
171 std::function<std::vector<uint8_t>()> getter,
172 std::function<void(std::span<const uint8_t>)> setter) = 0;
173
174 /**
175 * Add a string property (SmallString form).
176 *
177 * @param key property name
178 * @param getter getter function (returns current value)
179 * @param setter setter function (sets new value)
180 */
183 std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
184 std::function<void(std::string_view)> setter) = 0;
185
186 /**
187 * Add a boolean array property (SmallVector form).
188 *
189 * @param key property name
190 * @param getter getter function (returns current value)
191 * @param setter setter function (sets new value)
192 */
195 std::function<std::span<const int>(wpi::SmallVectorImpl<int>& buf)>
196 getter,
197 std::function<void(std::span<const int>)> setter) = 0;
198
199 /**
200 * Add an integer array property (SmallVector form).
201 *
202 * @param key property name
203 * @param getter getter function (returns current value)
204 * @param setter setter function (sets new value)
205 */
208 std::function<
209 std::span<const int64_t>(wpi::SmallVectorImpl<int64_t>& buf)>
210 getter,
211 std::function<void(std::span<const int64_t>)> setter) = 0;
212
213 /**
214 * Add a float array property (SmallVector form).
215 *
216 * @param key property name
217 * @param getter getter function (returns current value)
218 * @param setter setter function (sets new value)
219 */
222 std::function<std::span<const float>(wpi::SmallVectorImpl<float>& buf)>
223 getter,
224 std::function<void(std::span<const float>)> setter) = 0;
225
226 /**
227 * Add a double array property (SmallVector form).
228 *
229 * @param key property name
230 * @param getter getter function (returns current value)
231 * @param setter setter function (sets new value)
232 */
235 std::function<std::span<const double>(wpi::SmallVectorImpl<double>& buf)>
236 getter,
237 std::function<void(std::span<const double>)> setter) = 0;
238
239 /**
240 * Add a string array property (SmallVector form).
241 *
242 * @param key property name
243 * @param getter getter function (returns current value)
244 * @param setter setter function (sets new value)
245 */
248 std::function<
249 std::span<const std::string>(wpi::SmallVectorImpl<std::string>& buf)>
250 getter,
251 std::function<void(std::span<const std::string>)> setter) = 0;
252
253 /**
254 * Add a raw property (SmallVector form).
255 *
256 * @param key property name
257 * @param typeString type string
258 * @param getter getter function (returns current value)
259 * @param setter setter function (sets new value)
260 */
262 std::string_view key, std::string_view typeString,
263 std::function<std::span<uint8_t>(wpi::SmallVectorImpl<uint8_t>& buf)>
264 getter,
265 std::function<void(std::span<const uint8_t>)> setter) = 0;
266
267 /**
268 * Gets the kind of backend being used.
269 *
270 * @return Backend kind
271 */
272 virtual BackendKind GetBackendKind() const = 0;
273
274 /**
275 * Return whether this sendable has been published.
276 *
277 * @return True if it has been published, false if not.
278 */
279 virtual bool IsPublished() const = 0;
280
281 /**
282 * Update the published values by calling the getters for all properties.
283 */
284 virtual void Update() = 0;
285
286 /**
287 * Clear properties.
288 */
289 virtual void ClearProperties() = 0;
290};
291
292} // namespace wpi
Definition: core.h:1240
Definition: SendableBuilder.h:18
virtual void AddDoubleProperty(std::string_view key, std::function< double()> getter, std::function< void(double)> setter)=0
Add a double 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 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 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 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 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).
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 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:520
type
Definition: core.h:575
::int64_t int64_t
Definition: Meta.h:59
/file This file defines the SmallVector class.
Definition: AprilTagFieldLayout.h:18