WPILibC++ 2024.3.2
BooleanArrayTopic.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// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY
6
7#pragma once
8
9#include <stdint.h>
10
11#include <utility>
12#include <span>
13#include <string_view>
14#include <vector>
15
16#include <wpi/json_fwd.h>
17
18#include "networktables/Topic.h"
19
20namespace wpi {
21template <typename T>
22class SmallVectorImpl;
23} // namespace wpi
24
25namespace nt {
26
27class BooleanArrayTopic;
28
29/**
30 * NetworkTables BooleanArray subscriber.
31 */
33 public:
35 using ValueType = std::vector<int>;
36 using ParamType = std::span<const int>;
38
39 using SmallRetType = std::span<int>;
40 using SmallElemType = int;
42
43
45
46 /**
47 * Construct from a subscriber handle; recommended to use
48 * BooleanArrayTopic::Subscribe() instead.
49 *
50 * @param handle Native handle
51 * @param defaultValue Default value
52 */
54
55 /**
56 * Get the last published value.
57 * If no value has been published, returns the stored default value.
58 *
59 * @return value
60 */
61 ValueType Get() const;
62
63 /**
64 * Get the last published value.
65 * If no value has been published, returns the passed defaultValue.
66 *
67 * @param defaultValue default value to return if no value has been published
68 * @return value
69 */
70 ValueType Get(ParamType defaultValue) const;
71
72 /**
73 * Get the last published value.
74 * If no value has been published, returns the stored default value.
75 *
76 * @param buf storage for returned value
77 * @return value
78 */
80
81 /**
82 * Get the last published value.
83 * If no value has been published, returns the passed defaultValue.
84 *
85 * @param buf storage for returned value
86 * @param defaultValue default value to return if no value has been published
87 * @return value
88 */
90
91 /**
92 * Get the last published value along with its timestamp
93 * If no value has been published, returns the stored default value and a
94 * timestamp of 0.
95 *
96 * @return timestamped value
97 */
99
100 /**
101 * Get the last published value along with its timestamp.
102 * If no value has been published, returns the passed defaultValue and a
103 * timestamp of 0.
104 *
105 * @param defaultValue default value to return if no value has been published
106 * @return timestamped value
107 */
109
110 /**
111 * Get the last published value along with its timestamp.
112 * If no value has been published, returns the stored default value and a
113 * timestamp of 0.
114 *
115 * @param buf storage for returned value
116 * @return timestamped value
117 */
120
121 /**
122 * Get the last published value along with its timestamp.
123 * If no value has been published, returns the passed defaultValue and a
124 * timestamp of 0.
125 *
126 * @param buf storage for returned value
127 * @param defaultValue default value to return if no value has been published
128 * @return timestamped value
129 */
132 ParamType defaultValue) const;
133
134 /**
135 * Get an array of all value changes since the last call to ReadQueue.
136 * Also provides a timestamp for each value.
137 *
138 * @note The "poll storage" subscribe option can be used to set the queue
139 * depth.
140 *
141 * @return Array of timestamped values; empty array if no new changes have
142 * been published since the previous call.
143 */
144 std::vector<TimestampedValueType> ReadQueue();
145
146 /**
147 * Get the corresponding topic.
148 *
149 * @return Topic
150 */
151 TopicType GetTopic() const;
152
153 private:
154 ValueType m_defaultValue;
155};
156
157/**
158 * NetworkTables BooleanArray publisher.
159 */
161 public:
163 using ValueType = std::vector<int>;
164 using ParamType = std::span<const int>;
165
166 using SmallRetType = std::span<int>;
167 using SmallElemType = int;
168
170
172
173 /**
174 * Construct from a publisher handle; recommended to use
175 * BooleanArrayTopic::Publish() instead.
176 *
177 * @param handle Native handle
178 */
179 explicit BooleanArrayPublisher(NT_Publisher handle);
180
181 /**
182 * Publish a new value.
183 *
184 * @param value value to publish
185 * @param time timestamp; 0 indicates current NT time should be used
186 */
187 void Set(ParamType value, int64_t time = 0);
188
189 /**
190 * Publish a default value.
191 * On reconnect, a default value will never be used in preference to a
192 * published value.
193 *
194 * @param value value
195 */
196 void SetDefault(ParamType value);
197
198 /**
199 * Get the corresponding topic.
200 *
201 * @return Topic
202 */
203 TopicType GetTopic() const;
204};
205
206/**
207 * NetworkTables BooleanArray entry.
208 *
209 * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed.
210 */
212 public BooleanArrayPublisher {
213 public:
217 using ValueType = std::vector<int>;
218 using ParamType = std::span<const int>;
219
220 using SmallRetType = std::span<int>;
221 using SmallElemType = int;
222
224
225 BooleanArrayEntry() = default;
226
227 /**
228 * Construct from an entry handle; recommended to use
229 * BooleanArrayTopic::GetEntry() instead.
230 *
231 * @param handle Native handle
232 * @param defaultValue Default value
233 */
234 BooleanArrayEntry(NT_Entry handle, ParamType defaultValue);
235
236 /**
237 * Determines if the native handle is valid.
238 *
239 * @return True if the native handle is valid, false otherwise.
240 */
241 explicit operator bool() const { return m_subHandle != 0; }
242
243 /**
244 * Gets the native handle for the entry.
245 *
246 * @return Native handle
247 */
248 NT_Entry GetHandle() const { return m_subHandle; }
249
250 /**
251 * Get the corresponding topic.
252 *
253 * @return Topic
254 */
255 TopicType GetTopic() const;
256
257 /**
258 * Stops publishing the entry if it's published.
259 */
260 void Unpublish();
261};
262
263/**
264 * NetworkTables BooleanArray topic.
265 */
266class BooleanArrayTopic final : public Topic {
267 public:
271 using ValueType = std::vector<int>;
272 using ParamType = std::span<const int>;
274 /** The default type string for this topic type. */
275 static constexpr std::string_view kTypeString = "boolean[]";
276
277 BooleanArrayTopic() = default;
278
279 /**
280 * Construct from a topic handle; recommended to use
281 * NetworkTableInstance::GetBooleanArrayTopic() instead.
282 *
283 * @param handle Native handle
284 */
285 explicit BooleanArrayTopic(NT_Topic handle) : Topic{handle} {}
286
287 /**
288 * Construct from a generic topic.
289 *
290 * @param topic Topic
291 */
292 explicit BooleanArrayTopic(Topic topic) : Topic{topic} {}
293
294 /**
295 * Create a new subscriber to the topic.
296 *
297 * <p>The subscriber is only active as long as the returned object
298 * is not destroyed.
299 *
300 * @note Subscribers that do not match the published data type do not return
301 * any values. To determine if the data type matches, use the appropriate
302 * Topic functions.
303 *
304 * @param defaultValue default value used when a default is not provided to a
305 * getter function
306 * @param options subscribe options
307 * @return subscriber
308 */
309 [[nodiscard]]
311 ParamType defaultValue,
312 const PubSubOptions& options = kDefaultPubSubOptions);
313 /**
314 * Create a new subscriber to the topic, with specific type string.
315 *
316 * <p>The subscriber is only active as long as the returned object
317 * is not destroyed.
318 *
319 * @note Subscribers that do not match the published data type do not return
320 * any values. To determine if the data type matches, use the appropriate
321 * Topic functions.
322 *
323 * @param typeString type string
324 * @param defaultValue default value used when a default is not provided to a
325 * getter function
326 * @param options subscribe options
327 * @return subscriber
328 */
329 [[nodiscard]]
331 std::string_view typeString, ParamType defaultValue,
332 const PubSubOptions& options = kDefaultPubSubOptions);
333
334 /**
335 * Create a new publisher to the topic.
336 *
337 * The publisher is only active as long as the returned object
338 * is not destroyed.
339 *
340 * @note It is not possible to publish two different data types to the same
341 * topic. Conflicts between publishers are typically resolved by the
342 * server on a first-come, first-served basis. Any published values that
343 * do not match the topic's data type are dropped (ignored). To determine
344 * if the data type matches, use the appropriate Topic functions.
345 *
346 * @param options publish options
347 * @return publisher
348 */
349 [[nodiscard]]
351
352 /**
353 * Create a new publisher to the topic, with type string and initial
354 * properties.
355 *
356 * The publisher is only active as long as the returned object
357 * is not destroyed.
358 *
359 * @note It is not possible to publish two different data types to the same
360 * topic. Conflicts between publishers are typically resolved by the
361 * server on a first-come, first-served basis. Any published values that
362 * do not match the topic's data type are dropped (ignored). To determine
363 * if the data type matches, use the appropriate Topic functions.
364 *
365 * @param typeString type string
366 * @param properties JSON properties
367 * @param options publish options
368 * @return publisher
369 */
370 [[nodiscard]]
372 const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions);
373
374 /**
375 * Create a new entry for the topic.
376 *
377 * Entries act as a combination of a subscriber and a weak publisher. The
378 * subscriber is active as long as the entry is not destroyed. The publisher
379 * is created when the entry is first written to, and remains active until
380 * either Unpublish() is called or the entry is destroyed.
381 *
382 * @note It is not possible to use two different data types with the same
383 * topic. Conflicts between publishers are typically resolved by the
384 * server on a first-come, first-served basis. Any published values that
385 * do not match the topic's data type are dropped (ignored), and the entry
386 * will show no new values if the data type does not match. To determine
387 * if the data type matches, use the appropriate Topic functions.
388 *
389 * @param defaultValue default value used when a default is not provided to a
390 * getter function
391 * @param options publish and/or subscribe options
392 * @return entry
393 */
394 [[nodiscard]]
395 EntryType GetEntry(ParamType defaultValue,
396 const PubSubOptions& options = kDefaultPubSubOptions);
397 /**
398 * Create a new entry for the topic, with specific type string.
399 *
400 * Entries act as a combination of a subscriber and a weak publisher. The
401 * subscriber is active as long as the entry is not destroyed. The publisher
402 * is created when the entry is first written to, and remains active until
403 * either Unpublish() is called or the entry is destroyed.
404 *
405 * @note It is not possible to use two different data types with the same
406 * topic. Conflicts between publishers are typically resolved by the
407 * server on a first-come, first-served basis. Any published values that
408 * do not match the topic's data type are dropped (ignored), and the entry
409 * will show no new values if the data type does not match. To determine
410 * if the data type matches, use the appropriate Topic functions.
411 *
412 * @param typeString type string
413 * @param defaultValue default value used when a default is not provided to a
414 * getter function
415 * @param options publish and/or subscribe options
416 * @return entry
417 */
418 [[nodiscard]]
419 EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue,
420 const PubSubOptions& options = kDefaultPubSubOptions);
421
422};
423
424} // namespace nt
425
NetworkTables BooleanArray entry.
Definition: BooleanArrayTopic.h:212
BooleanArrayTopic TopicType
Definition: BooleanArrayTopic.h:216
BooleanArrayEntry()=default
NT_Entry GetHandle() const
Gets the native handle for the entry.
Definition: BooleanArrayTopic.h:248
BooleanArrayEntry(NT_Entry handle, ParamType defaultValue)
Construct from an entry handle; recommended to use BooleanArrayTopic::GetEntry() instead.
void Unpublish()
Stops publishing the entry if it's published.
Definition: BooleanArrayTopic.inc:90
TopicType GetTopic() const
Get the corresponding topic.
Definition: BooleanArrayTopic.inc:86
NetworkTables BooleanArray publisher.
Definition: BooleanArrayTopic.h:160
std::span< const int > ParamType
Definition: BooleanArrayTopic.h:164
int SmallElemType
Definition: BooleanArrayTopic.h:167
std::vector< int > ValueType
Definition: BooleanArrayTopic.h:163
TopicType GetTopic() const
Get the corresponding topic.
Definition: BooleanArrayTopic.inc:77
std::span< int > SmallRetType
Definition: BooleanArrayTopic.h:166
void SetDefault(ParamType value)
Publish a default value.
Definition: BooleanArrayTopic.inc:73
void Set(ParamType value, int64_t time=0)
Publish a new value.
Definition: BooleanArrayTopic.inc:68
NetworkTables BooleanArray subscriber.
Definition: BooleanArrayTopic.h:32
std::span< int > SmallRetType
Definition: BooleanArrayTopic.h:39
ValueType Get() const
Get the last published value.
Definition: BooleanArrayTopic.inc:22
SmallRetType Get(wpi::SmallVectorImpl< SmallElemType > &buf, ParamType defaultValue) const
Get the last published value.
BooleanArraySubscriber(NT_Subscriber handle, ParamType defaultValue)
Construct from a subscriber handle; recommended to use BooleanArrayTopic::Subscribe() instead.
TopicType GetTopic() const
Get the corresponding topic.
Definition: BooleanArrayTopic.inc:61
std::vector< TimestampedValueType > ReadQueue()
Get an array of all value changes since the last call to ReadQueue.
Definition: BooleanArrayTopic.inc:57
ValueType Get(ParamType defaultValue) const
Get the last published value.
TimestampedValueType GetAtomic() const
Get the last published value along with its timestamp If no value has been published,...
Definition: BooleanArrayTopic.inc:39
std::vector< int > ValueType
Definition: BooleanArrayTopic.h:35
TimestampedValueType GetAtomic(ParamType defaultValue) const
Get the last published value along with its timestamp.
TimestampedValueViewType GetAtomic(wpi::SmallVectorImpl< SmallElemType > &buf, ParamType defaultValue) const
Get the last published value along with its timestamp.
std::span< const int > ParamType
Definition: BooleanArrayTopic.h:36
int SmallElemType
Definition: BooleanArrayTopic.h:40
NetworkTables BooleanArray topic.
Definition: BooleanArrayTopic.h:266
SubscriberType SubscribeEx(std::string_view typeString, ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic, with specific type string.
Definition: BooleanArrayTopic.inc:101
PublisherType PublishEx(std::string_view typeString, const wpi::json &properties, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic, with type string and initial properties.
Definition: BooleanArrayTopic.inc:115
SubscriberType Subscribe(ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic.
Definition: BooleanArrayTopic.inc:94
BooleanArrayTopic(NT_Topic handle)
Construct from a topic handle; recommended to use NetworkTableInstance::GetBooleanArrayTopic() instea...
Definition: BooleanArrayTopic.h:285
PublisherType Publish(const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic.
Definition: BooleanArrayTopic.inc:109
BooleanArrayTopic(Topic topic)
Construct from a generic topic.
Definition: BooleanArrayTopic.h:292
std::vector< int > ValueType
Definition: BooleanArrayTopic.h:271
std::span< const int > ParamType
Definition: BooleanArrayTopic.h:272
static constexpr std::string_view kTypeString
The default type string for this topic type.
Definition: BooleanArrayTopic.h:275
EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new entry for the topic, with specific type string.
Definition: BooleanArrayTopic.inc:129
EntryType GetEntry(ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new entry for the topic.
Definition: BooleanArrayTopic.inc:122
BooleanArrayPublisher PublisherType
Definition: BooleanArrayTopic.h:269
BooleanArraySubscriber SubscriberType
Definition: BooleanArrayTopic.h:268
BooleanArrayEntry EntryType
Definition: BooleanArrayTopic.h:270
BooleanArrayTopic()=default
NetworkTables publisher.
Definition: Topic.h:364
NetworkTables subscriber.
Definition: Topic.h:309
NT_Subscriber m_subHandle
Definition: Topic.h:360
NetworkTables Topic.
Definition: Topic.h:28
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:579
basic_string_view< char > string_view
Definition: core.h:501
NT_Handle NT_Topic
Definition: ntcore_c.h:40
NT_Handle NT_Subscriber
Definition: ntcore_c.h:41
NT_Handle NT_Publisher
Definition: ntcore_c.h:42
NT_Handle NT_Entry
Definition: ntcore_c.h:35
Timestamped< std::vector< int > > TimestampedBooleanArray
Timestamped BooleanArray.
Definition: ntcore_cpp_types.h:555
Timestamped< std::span< int > > TimestampedBooleanArrayView
Timestamped BooleanArray view (for SmallVector-taking functions).
Definition: ntcore_cpp_types.h:561
constexpr PubSubOptions kDefaultPubSubOptions
Default publish/subscribe options.
Definition: ntcore_cpp.h:390
NetworkTables (ntcore) namespace.
Definition: ntcore_cpp.h:36
Definition: ntcore_cpp.h:26
NetworkTables publish/subscribe options.
Definition: ntcore_cpp.h:305
Timestamped value.
Definition: ntcore_cpp_types.h:30