WPILibC++ 2024.3.2
IntegerArrayTopic.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 IntegerArrayTopic;
28
29/**
30 * NetworkTables IntegerArray subscriber.
31 */
33 public:
35 using ValueType = std::vector<int64_t>;
36 using ParamType = std::span<const int64_t>;
38
39 using SmallRetType = std::span<int64_t>;
40 using SmallElemType = int64_t;
42
43
45
46 /**
47 * Construct from a subscriber handle; recommended to use
48 * IntegerArrayTopic::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 IntegerArray publisher.
159 */
161 public:
163 using ValueType = std::vector<int64_t>;
164 using ParamType = std::span<const int64_t>;
165
166 using SmallRetType = std::span<int64_t>;
167 using SmallElemType = int64_t;
168
170
172
173 /**
174 * Construct from a publisher handle; recommended to use
175 * IntegerArrayTopic::Publish() instead.
176 *
177 * @param handle Native handle
178 */
179 explicit IntegerArrayPublisher(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 IntegerArray entry.
208 *
209 * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed.
210 */
212 public IntegerArrayPublisher {
213 public:
217 using ValueType = std::vector<int64_t>;
218 using ParamType = std::span<const int64_t>;
219
220 using SmallRetType = std::span<int64_t>;
221 using SmallElemType = int64_t;
222
224
225 IntegerArrayEntry() = default;
226
227 /**
228 * Construct from an entry handle; recommended to use
229 * IntegerArrayTopic::GetEntry() instead.
230 *
231 * @param handle Native handle
232 * @param defaultValue Default value
233 */
234 IntegerArrayEntry(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 IntegerArray topic.
265 */
266class IntegerArrayTopic final : public Topic {
267 public:
271 using ValueType = std::vector<int64_t>;
272 using ParamType = std::span<const int64_t>;
274 /** The default type string for this topic type. */
275 static constexpr std::string_view kTypeString = "int[]";
276
277 IntegerArrayTopic() = default;
278
279 /**
280 * Construct from a topic handle; recommended to use
281 * NetworkTableInstance::GetIntegerArrayTopic() instead.
282 *
283 * @param handle Native handle
284 */
285 explicit IntegerArrayTopic(NT_Topic handle) : Topic{handle} {}
286
287 /**
288 * Construct from a generic topic.
289 *
290 * @param topic Topic
291 */
292 explicit IntegerArrayTopic(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 IntegerArray entry.
Definition: IntegerArrayTopic.h:212
IntegerArrayEntry(NT_Entry handle, ParamType defaultValue)
Construct from an entry handle; recommended to use IntegerArrayTopic::GetEntry() instead.
TopicType GetTopic() const
Get the corresponding topic.
Definition: IntegerArrayTopic.inc:86
IntegerArrayTopic TopicType
Definition: IntegerArrayTopic.h:216
void Unpublish()
Stops publishing the entry if it's published.
Definition: IntegerArrayTopic.inc:90
NT_Entry GetHandle() const
Gets the native handle for the entry.
Definition: IntegerArrayTopic.h:248
IntegerArrayEntry()=default
NetworkTables IntegerArray publisher.
Definition: IntegerArrayTopic.h:160
TopicType GetTopic() const
Get the corresponding topic.
Definition: IntegerArrayTopic.inc:77
std::span< int64_t > SmallRetType
Definition: IntegerArrayTopic.h:166
int64_t SmallElemType
Definition: IntegerArrayTopic.h:167
void Set(ParamType value, int64_t time=0)
Publish a new value.
Definition: IntegerArrayTopic.inc:68
std::vector< int64_t > ValueType
Definition: IntegerArrayTopic.h:163
void SetDefault(ParamType value)
Publish a default value.
Definition: IntegerArrayTopic.inc:73
std::span< const int64_t > ParamType
Definition: IntegerArrayTopic.h:164
NetworkTables IntegerArray subscriber.
Definition: IntegerArrayTopic.h:32
std::vector< int64_t > ValueType
Definition: IntegerArrayTopic.h:35
std::span< int64_t > SmallRetType
Definition: IntegerArrayTopic.h:39
ValueType Get() const
Get the last published value.
Definition: IntegerArrayTopic.inc:22
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: IntegerArrayTopic.inc:39
TopicType GetTopic() const
Get the corresponding topic.
Definition: IntegerArrayTopic.inc:61
SmallRetType Get(wpi::SmallVectorImpl< SmallElemType > &buf, ParamType defaultValue) const
Get the last published value.
IntegerArraySubscriber(NT_Subscriber handle, ParamType defaultValue)
Construct from a subscriber handle; recommended to use IntegerArrayTopic::Subscribe() instead.
TimestampedValueViewType GetAtomic(wpi::SmallVectorImpl< SmallElemType > &buf, ParamType defaultValue) const
Get the last published value along with its timestamp.
std::vector< TimestampedValueType > ReadQueue()
Get an array of all value changes since the last call to ReadQueue.
Definition: IntegerArrayTopic.inc:57
int64_t SmallElemType
Definition: IntegerArrayTopic.h:40
TimestampedValueType GetAtomic(ParamType defaultValue) const
Get the last published value along with its timestamp.
std::span< const int64_t > ParamType
Definition: IntegerArrayTopic.h:36
NetworkTables IntegerArray topic.
Definition: IntegerArrayTopic.h:266
static constexpr std::string_view kTypeString
The default type string for this topic type.
Definition: IntegerArrayTopic.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: IntegerArrayTopic.inc:129
IntegerArrayTopic(NT_Topic handle)
Construct from a topic handle; recommended to use NetworkTableInstance::GetIntegerArrayTopic() instea...
Definition: IntegerArrayTopic.h:285
SubscriberType Subscribe(ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic.
Definition: IntegerArrayTopic.inc:94
SubscriberType SubscribeEx(std::string_view typeString, ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic, with specific type string.
Definition: IntegerArrayTopic.inc:101
IntegerArrayPublisher PublisherType
Definition: IntegerArrayTopic.h:269
std::vector< int64_t > ValueType
Definition: IntegerArrayTopic.h:271
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: IntegerArrayTopic.inc:115
EntryType GetEntry(ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new entry for the topic.
Definition: IntegerArrayTopic.inc:122
IntegerArrayTopic(Topic topic)
Construct from a generic topic.
Definition: IntegerArrayTopic.h:292
IntegerArrayEntry EntryType
Definition: IntegerArrayTopic.h:270
IntegerArrayTopic()=default
IntegerArraySubscriber SubscriberType
Definition: IntegerArrayTopic.h:268
std::span< const int64_t > ParamType
Definition: IntegerArrayTopic.h:272
PublisherType Publish(const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic.
Definition: IntegerArrayTopic.inc:109
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< int64_t > > TimestampedIntegerArray
Timestamped IntegerArray.
Definition: ntcore_cpp_types.h:647
Timestamped< std::span< int64_t > > TimestampedIntegerArrayView
Timestamped IntegerArray view (for SmallVector-taking functions).
Definition: ntcore_cpp_types.h:653
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