WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
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
19#include "networktables/Topic.h"
20#include "ntcore_cpp.h"
21
22namespace wpi {
23template <typename T>
24class SmallVectorImpl;
25} // namespace wpi
26
27namespace nt {
28
29class IntegerArrayTopic;
30
31/**
32 * NetworkTables IntegerArray subscriber.
33 */
35 public:
37 using ValueType = std::vector<int64_t>;
38 using ParamType = std::span<const int64_t>;
40
41 using SmallRetType = std::span<int64_t>;
42 using SmallElemType = int64_t;
44
45
47
48 /**
49 * Construct from a subscriber handle; recommended to use
50 * IntegerArrayTopic::Subscribe() instead.
51 *
52 * @param handle Native handle
53 * @param defaultValue Default value
54 */
56 : Subscriber{handle},
57 m_defaultValue{defaultValue.begin(), defaultValue.end()} {}
58
59 /**
60 * Get the last published value.
61 * If no value has been published, returns the stored default value.
62 *
63 * @return value
64 */
65 ValueType Get() const {
66 return Get(m_defaultValue);
67 }
68
69 /**
70 * Get the last published value.
71 * If no value has been published, returns the passed defaultValue.
72 *
73 * @param defaultValue default value to return if no value has been published
74 * @return value
75 */
76 ValueType Get(ParamType defaultValue) const {
77 return ::nt::GetIntegerArray(m_subHandle, defaultValue);
78 }
79
80 /**
81 * Get the last published value.
82 * If no value has been published, returns the stored default value.
83 *
84 * @param buf storage for returned value
85 * @return value
86 */
88 return Get(buf, m_defaultValue);
89 }
90
91 /**
92 * Get the last published value.
93 * If no value has been published, returns the passed defaultValue.
94 *
95 * @param buf storage for returned value
96 * @param defaultValue default value to return if no value has been published
97 * @return value
98 */
100 return nt::GetIntegerArray(m_subHandle, buf, defaultValue);
101 }
102
103 /**
104 * Get the last published value along with its timestamp
105 * If no value has been published, returns the stored default value and a
106 * timestamp of 0.
107 *
108 * @return timestamped value
109 */
111 return GetAtomic(m_defaultValue);
112 }
113
114 /**
115 * Get the last published value along with its timestamp.
116 * If no value has been published, returns the passed defaultValue and a
117 * timestamp of 0.
118 *
119 * @param defaultValue default value to return if no value has been published
120 * @return timestamped value
121 */
123 return ::nt::GetAtomicIntegerArray(m_subHandle, defaultValue);
124 }
125
126 /**
127 * Get the last published value along with its timestamp.
128 * If no value has been published, returns the stored default value and a
129 * timestamp of 0.
130 *
131 * @param buf storage for returned value
132 * @return timestamped value
133 */
136 return GetAtomic(buf, m_defaultValue);
137 }
138
139 /**
140 * Get the last published value along with its timestamp.
141 * If no value has been published, returns the passed defaultValue and a
142 * timestamp of 0.
143 *
144 * @param buf storage for returned value
145 * @param defaultValue default value to return if no value has been published
146 * @return timestamped value
147 */
150 ParamType defaultValue) const {
151 return nt::GetAtomicIntegerArray(m_subHandle, buf, defaultValue);
152 }
153
154 /**
155 * Get an array of all value changes since the last call to ReadQueue.
156 * Also provides a timestamp for each value.
157 *
158 * @note The "poll storage" subscribe option can be used to set the queue
159 * depth.
160 *
161 * @return Array of timestamped values; empty array if no new changes have
162 * been published since the previous call.
163 */
164 std::vector<TimestampedValueType> ReadQueue() {
165 return ::nt::ReadQueueIntegerArray(m_subHandle);
166 }
167
168 /**
169 * Get the corresponding topic.
170 *
171 * @return Topic
172 */
173 TopicType GetTopic() const;
174
175 private:
176 ValueType m_defaultValue;
177};
178
179/**
180 * NetworkTables IntegerArray publisher.
181 */
183 public:
185 using ValueType = std::vector<int64_t>;
186 using ParamType = std::span<const int64_t>;
187
188 using SmallRetType = std::span<int64_t>;
189 using SmallElemType = int64_t;
190
192
194
195 /**
196 * Construct from a publisher handle; recommended to use
197 * IntegerArrayTopic::Publish() instead.
198 *
199 * @param handle Native handle
200 */
201 explicit IntegerArrayPublisher(NT_Publisher handle) : Publisher{handle} {}
202
203 /**
204 * Publish a new value.
205 *
206 * @param value value to publish
207 * @param time timestamp; 0 indicates current NT time should be used
208 */
209 void Set(ParamType value, int64_t time = 0) {
211 }
212
213 /**
214 * Publish a default value.
215 * On reconnect, a default value will never be used in preference to a
216 * published value.
217 *
218 * @param value value
219 */
223
224 /**
225 * Get the corresponding topic.
226 *
227 * @return Topic
228 */
229 TopicType GetTopic() const;
230};
231
232/**
233 * NetworkTables IntegerArray entry.
234 *
235 * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed.
236 */
238 public IntegerArrayPublisher {
239 public:
243 using ValueType = std::vector<int64_t>;
244 using ParamType = std::span<const int64_t>;
245
246 using SmallRetType = std::span<int64_t>;
247 using SmallElemType = int64_t;
248
250
251 IntegerArrayEntry() = default;
252
253 /**
254 * Construct from an entry handle; recommended to use
255 * IntegerArrayTopic::GetEntry() instead.
256 *
257 * @param handle Native handle
258 * @param defaultValue Default value
259 */
261 : IntegerArraySubscriber{handle, defaultValue},
262 IntegerArrayPublisher{handle} {}
263
264 /**
265 * Determines if the native handle is valid.
266 *
267 * @return True if the native handle is valid, false otherwise.
268 */
269 explicit operator bool() const { return m_subHandle != 0; }
270
271 /**
272 * Gets the native handle for the entry.
273 *
274 * @return Native handle
275 */
276 NT_Entry GetHandle() const { return m_subHandle; }
277
278 /**
279 * Get the corresponding topic.
280 *
281 * @return Topic
282 */
283 TopicType GetTopic() const;
284
285 /**
286 * Stops publishing the entry if it's published.
287 */
291};
292
293/**
294 * NetworkTables IntegerArray topic.
295 */
296class IntegerArrayTopic final : public Topic {
297 public:
301 using ValueType = std::vector<int64_t>;
302 using ParamType = std::span<const int64_t>;
304 /** The default type string for this topic type. */
305 static constexpr std::string_view kTypeString = "int[]";
306
307 IntegerArrayTopic() = default;
308
309 /**
310 * Construct from a topic handle; recommended to use
311 * NetworkTableInstance::GetIntegerArrayTopic() instead.
312 *
313 * @param handle Native handle
314 */
315 explicit IntegerArrayTopic(NT_Topic handle) : Topic{handle} {}
316
317 /**
318 * Construct from a generic topic.
319 *
320 * @param topic Topic
321 */
322 explicit IntegerArrayTopic(Topic topic) : Topic{topic} {}
323
324 /**
325 * Create a new subscriber to the topic.
326 *
327 * <p>The subscriber is only active as long as the returned object
328 * is not destroyed.
329 *
330 * @note Subscribers that do not match the published data type do not return
331 * any values. To determine if the data type matches, use the appropriate
332 * Topic functions.
333 *
334 * @param defaultValue default value used when a default is not provided to a
335 * getter function
336 * @param options subscribe options
337 * @return subscriber
338 */
339 [[nodiscard]]
341 ParamType defaultValue,
342 const PubSubOptions& options = kDefaultPubSubOptions) {
344 ::nt::Subscribe(m_handle, NT_INTEGER_ARRAY, "int[]", options),
345 defaultValue};
346 }
347 /**
348 * Create a new subscriber to the topic, with specific type string.
349 *
350 * <p>The subscriber is only active as long as the returned object
351 * is not destroyed.
352 *
353 * @note Subscribers that do not match the published data type do not return
354 * any values. To determine if the data type matches, use the appropriate
355 * Topic functions.
356 *
357 * @param typeString type string
358 * @param defaultValue default value used when a default is not provided to a
359 * getter function
360 * @param options subscribe options
361 * @return subscriber
362 */
363 [[nodiscard]]
365 std::string_view typeString, ParamType defaultValue,
366 const PubSubOptions& options = kDefaultPubSubOptions) {
368 ::nt::Subscribe(m_handle, NT_INTEGER_ARRAY, typeString, options),
369 defaultValue};
370 }
371
372 /**
373 * Create a new publisher to the topic.
374 *
375 * The publisher is only active as long as the returned object
376 * is not destroyed.
377 *
378 * @note It is not possible to publish two different data types to the same
379 * topic. Conflicts between publishers are typically resolved by the
380 * server on a first-come, first-served basis. Any published values that
381 * do not match the topic's data type are dropped (ignored). To determine
382 * if the data type matches, use the appropriate Topic functions.
383 *
384 * @param options publish options
385 * @return publisher
386 */
387 [[nodiscard]]
392
393 /**
394 * Create a new publisher to the topic, with type string and initial
395 * properties.
396 *
397 * The publisher is only active as long as the returned object
398 * is not destroyed.
399 *
400 * @note It is not possible to publish two different data types to the same
401 * topic. Conflicts between publishers are typically resolved by the
402 * server on a first-come, first-served basis. Any published values that
403 * do not match the topic's data type are dropped (ignored). To determine
404 * if the data type matches, use the appropriate Topic functions.
405 *
406 * @param typeString type string
407 * @param properties JSON properties
408 * @param options publish options
409 * @return publisher
410 */
411 [[nodiscard]]
412 PublisherType PublishEx(std::string_view typeString,
413 const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions) {
415 ::nt::PublishEx(m_handle, NT_INTEGER_ARRAY, typeString, properties, options)};
416 }
417
418 /**
419 * Create a new entry for the topic.
420 *
421 * Entries act as a combination of a subscriber and a weak publisher. The
422 * subscriber is active as long as the entry is not destroyed. The publisher
423 * is created when the entry is first written to, and remains active until
424 * either Unpublish() is called or the entry is destroyed.
425 *
426 * @note It is not possible to use two different data types with the same
427 * topic. Conflicts between publishers are typically resolved by the
428 * server on a first-come, first-served basis. Any published values that
429 * do not match the topic's data type are dropped (ignored), and the entry
430 * will show no new values if the data type does not match. To determine
431 * if the data type matches, use the appropriate Topic functions.
432 *
433 * @param defaultValue default value used when a default is not provided to a
434 * getter function
435 * @param options publish and/or subscribe options
436 * @return entry
437 */
438 [[nodiscard]]
440 const PubSubOptions& options = kDefaultPubSubOptions) {
441 return IntegerArrayEntry{
442 ::nt::GetEntry(m_handle, NT_INTEGER_ARRAY, "int[]", options),
443 defaultValue};
444 }
445 /**
446 * Create a new entry for the topic, with specific type string.
447 *
448 * Entries act as a combination of a subscriber and a weak publisher. The
449 * subscriber is active as long as the entry is not destroyed. The publisher
450 * is created when the entry is first written to, and remains active until
451 * either Unpublish() is called or the entry is destroyed.
452 *
453 * @note It is not possible to use two different data types with the same
454 * topic. Conflicts between publishers are typically resolved by the
455 * server on a first-come, first-served basis. Any published values that
456 * do not match the topic's data type are dropped (ignored), and the entry
457 * will show no new values if the data type does not match. To determine
458 * if the data type matches, use the appropriate Topic functions.
459 *
460 * @param typeString type string
461 * @param defaultValue default value used when a default is not provided to a
462 * getter function
463 * @param options publish and/or subscribe options
464 * @return entry
465 */
466 [[nodiscard]]
467 EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue,
468 const PubSubOptions& options = kDefaultPubSubOptions) {
469 return IntegerArrayEntry{
470 ::nt::GetEntry(m_handle, NT_INTEGER_ARRAY, typeString, options),
471 defaultValue};
472 }
473
474};
475
479
483
487
488} // namespace nt
NetworkTables IntegerArray entry.
Definition IntegerArrayTopic.h:238
std::span< int64_t > SmallRetType
Definition IntegerArrayTopic.h:246
IntegerArrayEntry(NT_Entry handle, ParamType defaultValue)
Construct from an entry handle; recommended to use IntegerArrayTopic::GetEntry() instead.
Definition IntegerArrayTopic.h:260
TopicType GetTopic() const
Get the corresponding topic.
Definition IntegerArrayTopic.h:484
IntegerArrayTopic TopicType
Definition IntegerArrayTopic.h:242
std::vector< int64_t > ValueType
Definition IntegerArrayTopic.h:243
void Unpublish()
Stops publishing the entry if it's published.
Definition IntegerArrayTopic.h:288
NT_Entry GetHandle() const
Gets the native handle for the entry.
Definition IntegerArrayTopic.h:276
std::span< const int64_t > ParamType
Definition IntegerArrayTopic.h:244
IntegerArrayEntry()=default
int64_t SmallElemType
Definition IntegerArrayTopic.h:247
NetworkTables IntegerArray publisher.
Definition IntegerArrayTopic.h:182
TopicType GetTopic() const
Get the corresponding topic.
Definition IntegerArrayTopic.h:480
std::span< int64_t > SmallRetType
Definition IntegerArrayTopic.h:188
int64_t SmallElemType
Definition IntegerArrayTopic.h:189
IntegerArrayTopic TopicType
Definition IntegerArrayTopic.h:184
void Set(ParamType value, int64_t time=0)
Publish a new value.
Definition IntegerArrayTopic.h:209
std::vector< int64_t > ValueType
Definition IntegerArrayTopic.h:185
void SetDefault(ParamType value)
Publish a default value.
Definition IntegerArrayTopic.h:220
IntegerArrayPublisher(NT_Publisher handle)
Construct from a publisher handle; recommended to use IntegerArrayTopic::Publish() instead.
Definition IntegerArrayTopic.h:201
std::span< const int64_t > ParamType
Definition IntegerArrayTopic.h:186
NetworkTables IntegerArray subscriber.
Definition IntegerArrayTopic.h:34
std::vector< int64_t > ValueType
Definition IntegerArrayTopic.h:37
SmallRetType Get(wpi::SmallVectorImpl< SmallElemType > &buf) const
Get the last published value.
Definition IntegerArrayTopic.h:87
std::span< int64_t > SmallRetType
Definition IntegerArrayTopic.h:41
IntegerArrayTopic TopicType
Definition IntegerArrayTopic.h:36
ValueType Get(ParamType defaultValue) const
Get the last published value.
Definition IntegerArrayTopic.h:76
TopicType GetTopic() const
Get the corresponding topic.
Definition IntegerArrayTopic.h:476
std::vector< TimestampedValueType > ReadQueue()
Get an array of all value changes since the last call to ReadQueue.
Definition IntegerArrayTopic.h:164
TimestampedValueViewType GetAtomic(wpi::SmallVectorImpl< SmallElemType > &buf) const
Get the last published value along with its timestamp.
Definition IntegerArrayTopic.h:134
SmallRetType Get(wpi::SmallVectorImpl< SmallElemType > &buf, ParamType defaultValue) const
Get the last published value.
Definition IntegerArrayTopic.h:99
IntegerArraySubscriber(NT_Subscriber handle, ParamType defaultValue)
Construct from a subscriber handle; recommended to use IntegerArrayTopic::Subscribe() instead.
Definition IntegerArrayTopic.h:55
ValueType Get() const
Get the last published value.
Definition IntegerArrayTopic.h:65
TimestampedValueViewType GetAtomic(wpi::SmallVectorImpl< SmallElemType > &buf, ParamType defaultValue) const
Get the last published value along with its timestamp.
Definition IntegerArrayTopic.h:148
int64_t SmallElemType
Definition IntegerArrayTopic.h:42
TimestampedValueType GetAtomic() const
Get the last published value along with its timestamp If no value has been published,...
Definition IntegerArrayTopic.h:110
TimestampedValueType GetAtomic(ParamType defaultValue) const
Get the last published value along with its timestamp.
Definition IntegerArrayTopic.h:122
std::span< const int64_t > ParamType
Definition IntegerArrayTopic.h:38
NetworkTables IntegerArray topic.
Definition IntegerArrayTopic.h:296
EntryType GetEntry(ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new entry for the topic.
Definition IntegerArrayTopic.h:439
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.h:467
static constexpr std::string_view kTypeString
The default type string for this topic type.
Definition IntegerArrayTopic.h:305
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.h:364
IntegerArrayTopic(NT_Topic handle)
Construct from a topic handle; recommended to use NetworkTableInstance::GetIntegerArrayTopic() instea...
Definition IntegerArrayTopic.h:315
SubscriberType Subscribe(ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic.
Definition IntegerArrayTopic.h:340
std::vector< int64_t > ValueType
Definition IntegerArrayTopic.h:301
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.h:412
IntegerArrayTopic(Topic topic)
Construct from a generic topic.
Definition IntegerArrayTopic.h:322
PublisherType Publish(const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic.
Definition IntegerArrayTopic.h:388
IntegerArrayTopic()=default
std::span< const int64_t > ParamType
Definition IntegerArrayTopic.h:302
NetworkTables publisher.
Definition Topic.h:393
NT_Publisher m_pubHandle
NetworkTables handle.
Definition Topic.h:441
NetworkTables subscriber.
Definition Topic.h:321
NT_Subscriber m_subHandle
Definition Topic.h:386
NetworkTables Topic.
Definition Topic.h:28
NT_Topic m_handle
Definition Topic.h:317
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition sha1.h:30
bool SetIntegerArray(NT_Handle pubentry, std::span< const int64_t > value, int64_t time=0)
Publish a new value.
std::vector< int64_t > GetIntegerArray(NT_Handle subentry, std::span< const int64_t > defaultValue)
Get the last published value.
bool SetDefaultIntegerArray(NT_Handle pubentry, std::span< const int64_t > defaultValue)
Publish a default value.
TimestampedIntegerArray GetAtomicIntegerArray(NT_Handle subentry, std::span< const int64_t > defaultValue)
Get the last published value along with its timestamp.
NT_Handle NT_Topic
Definition ntcore_c.h:42
NT_Handle NT_Subscriber
Definition ntcore_c.h:43
NT_Handle NT_Publisher
Definition ntcore_c.h:44
NT_Handle NT_Entry
Definition ntcore_c.h:37
@ NT_INTEGER_ARRAY
Definition ntcore_c.h:65
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
NT_Entry GetEntry(NT_Inst inst, std::string_view name)
Get Entry Handle.
NT_Topic GetTopicFromHandle(NT_Handle pubsubentry)
Gets the topic handle from an entry/subscriber/publisher handle.
NT_Publisher PublishEx(NT_Topic topic, NT_Type type, std::string_view typeStr, const wpi::json &properties, const PubSubOptions &options=kDefaultPubSubOptions)
Creates a new publisher to a topic.
NT_Publisher Publish(NT_Topic topic, NT_Type type, std::string_view typeStr, const PubSubOptions &options=kDefaultPubSubOptions)
Creates a new publisher to a topic.
void Unpublish(NT_Handle pubentry)
Stops publisher.
NT_Subscriber Subscribe(NT_Topic topic, NT_Type type, std::string_view typeStr, const PubSubOptions &options=kDefaultPubSubOptions)
Creates a new subscriber to value changes on a topic.
NetworkTables (ntcore) namespace.
Definition ntcore_cpp.h:36
Foonathan namespace.
Definition ntcore_cpp.h:26
NetworkTables publish/subscribe options.
Definition ntcore_cpp.h:305
Timestamped value.
Definition ntcore_cpp_types.h:30