WPILibC++ 2025.0.0-alpha-1-14-g3b6f38d
StructArrayTopic.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 <stdint.h>
8
9#include <atomic>
10#include <functional>
11#include <memory>
12#include <ranges>
13#include <span>
14#include <tuple>
15#include <utility>
16#include <vector>
17
18#include <wpi/SmallVector.h>
19#include <wpi/json_fwd.h>
20#include <wpi/mutex.h>
21#include <wpi/struct/Struct.h>
22
24#include "networktables/Topic.h"
25#include "ntcore_cpp.h"
26
27namespace nt {
28
29template <typename T, typename... I>
30 requires wpi::StructSerializable<T, I...>
31class StructArrayTopic;
32
33/**
34 * NetworkTables struct-encoded value array subscriber.
35 */
36template <typename T, typename... I>
37 requires wpi::StructSerializable<T, I...>
39 using S = wpi::Struct<T, I...>;
40
41 public:
42 using TopicType = StructArrayTopic<T, I...>;
43 using ValueType = std::vector<T>;
44 using ParamType = std::span<const T>;
46
48
49 /**
50 * Construct from a subscriber handle; recommended to use
51 * StructTopic::Subscribe() instead.
52 *
53 * @param handle Native handle
54 * @param defaultValue Default value
55 * @param info optional struct type info
56 */
57 template <typename U>
58#if __cpp_lib_ranges >= 201911L
59 requires std::ranges::range<U> &&
60 std::convertible_to<std::ranges::range_value_t<U>, T>
61#endif
62 StructArraySubscriber(NT_Subscriber handle, U&& defaultValue, I... info)
63 : Subscriber{handle},
64 m_defaultValue{defaultValue.begin(), defaultValue.end()},
65 m_info{std::move(info)...} {
66 }
67
68 /**
69 * Get the last published value.
70 * If no value has been published or the value cannot be unpacked, returns the
71 * stored default value.
72 *
73 * @return value
74 */
75 ValueType Get() const { return Get(m_defaultValue); }
76
77 /**
78 * Get the last published value.
79 * If no value has been published or the value cannot be unpacked, returns the
80 * passed defaultValue.
81 *
82 * @param defaultValue default value to return if no value has been published
83 * @return value
84 */
85 template <typename U>
86#if __cpp_lib_ranges >= 201911L
87 requires std::ranges::range<U> &&
88 std::convertible_to<std::ranges::range_value_t<U>, T>
89#endif
90 ValueType Get(U&& defaultValue) const {
91 return GetAtomic(std::forward<U>(defaultValue)).value;
92 }
93
94 /**
95 * Get the last published value.
96 * If no value has been published or the value cannot be unpacked, returns the
97 * passed defaultValue.
98 *
99 * @param defaultValue default value to return if no value has been published
100 * @return value
101 */
102 ValueType Get(std::span<const T> defaultValue) const {
103 return GetAtomic(defaultValue).value;
104 }
105
106 /**
107 * Get the last published value along with its timestamp
108 * If no value has been published or the value cannot be unpacked, returns the
109 * stored default value and a timestamp of 0.
110 *
111 * @return timestamped value
112 */
113 TimestampedValueType GetAtomic() const { return GetAtomic(m_defaultValue); }
114
115 /**
116 * Get the last published value along with its timestamp.
117 * If no value has been published or the value cannot be unpacked, returns the
118 * passed defaultValue and a timestamp of 0.
119 *
120 * @param defaultValue default value to return if no value has been published
121 * @return timestamped value
122 */
123 template <typename U>
124#if __cpp_lib_ranges >= 201911L
125 requires std::ranges::range<U> &&
126 std::convertible_to<std::ranges::range_value_t<U>, T>
127#endif
128 TimestampedValueType GetAtomic(U&& defaultValue) const {
130 size_t size = std::apply(S::GetSize, m_info);
132 if (view.value.size() == 0 || (view.value.size() % size) != 0) {
133 return {0, 0, std::forward<U>(defaultValue)};
134 }
135 TimestampedValueType rv{view.time, view.serverTime, {}};
136 rv.value.reserve(view.value.size() / size);
137 for (auto in = view.value.begin(), end = view.value.end(); in != end;
138 in += size) {
139 std::apply(
140 [&](const I&... info) {
141 rv.value.emplace_back(S::Unpack(
142 std::span<const uint8_t>{std::to_address(in), size}, info...));
143 },
144 m_info);
145 }
146 return rv;
147 }
148
149 /**
150 * Get the last published value along with its timestamp.
151 * If no value has been published or the value cannot be unpacked, returns the
152 * passed defaultValue and a timestamp of 0.
153 *
154 * @param defaultValue default value to return if no value has been published
155 * @return timestamped value
156 */
157 TimestampedValueType GetAtomic(std::span<const T> defaultValue) const {
159 size_t size = std::apply(S::GetSize, m_info);
161 if (view.value.size() == 0 || (view.value.size() % size) != 0) {
162 return {0, 0, {defaultValue.begin(), defaultValue.end()}};
163 }
164 TimestampedValueType rv{view.time, view.serverTime, {}};
165 rv.value.reserve(view.value.size() / size);
166 for (auto in = view.value.begin(), end = view.value.end(); in != end;
167 in += size) {
168 std::apply(
169 [&](const I&... info) {
170 rv.value.emplace_back(S::Unpack(
171 std::span<const uint8_t>{std::to_address(in), size}, info...));
172 },
173 m_info);
174 }
175 return rv;
176 }
177
178 /**
179 * Get an array of all valid value changes since the last call to ReadQueue.
180 * Also provides a timestamp for each value. Values that cannot be unpacked
181 * are dropped.
182 *
183 * @note The "poll storage" subscribe option can be used to set the queue
184 * depth.
185 *
186 * @return Array of timestamped values; empty array if no valid new changes
187 * have been published since the previous call.
188 */
189 std::vector<TimestampedValueType> ReadQueue() {
191 std::vector<TimestampedValueType> rv;
192 rv.reserve(raw.size());
193 size_t size = std::apply(S::GetSize, m_info);
194 for (auto&& r : raw) {
195 if (r.value.size() == 0 || (r.value.size() % size) != 0) {
196 continue;
197 }
198 std::vector<T> values;
199 values.reserve(r.value.size() / size);
200 for (auto in = r.value.begin(), end = r.value.end(); in != end;
201 in += size) {
202 std::apply(
203 [&](const I&... info) {
204 values.emplace_back(
205 S::Unpack(std::span<const uint8_t>{std::to_address(in), size},
206 info...));
207 },
208 m_info);
209 }
210 rv.emplace_back(r.time, r.serverTime, std::move(values));
211 }
212 return rv;
213 }
214
215 /**
216 * Get the corresponding topic.
217 *
218 * @return Topic
219 */
221 return std::apply(
222 [&](const I&... info) {
223 return StructArrayTopic<T, I...>{
225 },
226 m_info);
227 }
228
229 private:
230 ValueType m_defaultValue;
231 [[no_unique_address]]
232 std::tuple<I...> m_info;
233};
234
235/**
236 * NetworkTables struct-encoded value array publisher.
237 */
238template <typename T, typename... I>
239 requires wpi::StructSerializable<T, I...>
241 using S = wpi::Struct<T, I...>;
242
243 public:
244 using TopicType = StructArrayTopic<T, I...>;
245 using ValueType = std::vector<T>;
246 using ParamType = std::span<const T>;
247
249
251
252 /**
253 * Construct from a publisher handle; recommended to use
254 * StructTopic::Publish() instead.
255 *
256 * @param handle Native handle
257 * @param info optional struct type info
258 */
259 explicit StructArrayPublisher(NT_Publisher handle, I... info)
260 : Publisher{handle}, m_info{std::move(info)...} {}
261
264
266 : Publisher{std::move(rhs)},
267 m_buf{std::move(rhs.m_buf)},
268 m_schemaPublished{
269 rhs.m_schemaPublished.load(std::memory_order_relaxed)},
270 m_info{std::move(rhs.m_info)} {}
271
273 Publisher::operator=(std::move(rhs));
274 m_buf = std::move(rhs.m_buf);
275 m_schemaPublished.store(
276 rhs.m_schemaPublished.load(std::memory_order_relaxed),
277 std::memory_order_relaxed);
278 m_info = std::move(rhs.m_info);
279 return *this;
280 }
281
282 /**
283 * Publish a new value.
284 *
285 * @param value value to publish
286 * @param time timestamp; 0 indicates current NT time should be used
287 */
288 template <typename U>
289#if __cpp_lib_ranges >= 201911L
290 requires std::ranges::range<U> &&
291 std::convertible_to<std::ranges::range_value_t<U>, T>
292#endif
293 void Set(U&& value, int64_t time = 0) {
294 std::apply(
295 [&](const I&... info) {
296 if (!m_schemaPublished.exchange(true, std::memory_order_relaxed)) {
297 GetTopic().GetInstance().template AddStructSchema<T>(info...);
298 }
299 m_buf.Write(
300 std::forward<U>(value),
301 [&](auto bytes) { ::nt::SetRaw(m_pubHandle, bytes, time); },
302 info...);
303 },
304 m_info);
305 }
306
307 /**
308 * Publish a new value.
309 *
310 * @param value value to publish
311 * @param time timestamp; 0 indicates current NT time should be used
312 */
313 void Set(std::span<const T> value, int64_t time = 0) {
314 std::apply(
315 [&](const I&... info) {
316 if (!m_schemaPublished.exchange(true, std::memory_order_relaxed)) {
317 GetTopic().GetInstance().template AddStructSchema<T>(info...);
318 }
319 m_buf.Write(
320 value,
321 [&](auto bytes) { ::nt::SetRaw(m_pubHandle, bytes, time); },
322 info...);
323 },
324 m_info);
325 }
326
327 /**
328 * Publish a default value.
329 * On reconnect, a default value will never be used in preference to a
330 * published value.
331 *
332 * @param value value
333 */
334 template <typename U>
335#if __cpp_lib_ranges >= 201911L
336 requires std::ranges::range<U> &&
337 std::convertible_to<std::ranges::range_value_t<U>, T>
338#endif
339 void SetDefault(U&& value) {
340 std::apply(
341 [&](const I&... info) {
342 if (!m_schemaPublished.exchange(true, std::memory_order_relaxed)) {
343 GetTopic().GetInstance().template AddStructSchema<T>(info...);
344 }
345 m_buf.Write(
346 std::forward<U>(value),
347 [&](auto bytes) { ::nt::SetDefaultRaw(m_pubHandle, bytes); },
348 info...);
349 },
350 m_info);
351 }
352
353 /**
354 * Publish a default value.
355 * On reconnect, a default value will never be used in preference to a
356 * published value.
357 *
358 * @param value value
359 */
360 void SetDefault(std::span<const T> value) {
361 std::apply(
362 [&](const I&... info) {
363 if (!m_schemaPublished.exchange(true, std::memory_order_relaxed)) {
364 GetTopic().GetInstance().template AddStructSchema<T>(info...);
365 }
366 m_buf.Write(
367 value,
368 [&](auto bytes) { ::nt::SetDefaultRaw(m_pubHandle, bytes); },
369 info...);
370 },
371 m_info);
372 }
373
374 /**
375 * Get the corresponding topic.
376 *
377 * @return Topic
378 */
380 return std::apply(
381 [&](const I&... info) {
382 return StructArrayTopic<T, I...>{
384 },
385 m_info);
386 }
387
388 private:
389 wpi::StructArrayBuffer<T, I...> m_buf;
390 std::atomic_bool m_schemaPublished{false};
391 [[no_unique_address]]
392 std::tuple<I...> m_info;
393};
394
395/**
396 * NetworkTables struct-encoded value array entry.
397 *
398 * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed.
399 */
400template <typename T, typename... I>
401 requires wpi::StructSerializable<T, I...>
402class StructArrayEntry final : public StructArraySubscriber<T, I...>,
403 public StructArrayPublisher<T, I...> {
404 public:
407 using TopicType = StructArrayTopic<T, I...>;
408 using ValueType = std::vector<T>;
409 using ParamType = std::span<const T>;
410
412
413 StructArrayEntry() = default;
414
415 /**
416 * Construct from an entry handle; recommended to use
417 * StructTopic::GetEntry() instead.
418 *
419 * @param handle Native handle
420 * @param defaultValue Default value
421 * @param info optional struct type info
422 */
423 template <typename U>
424#if __cpp_lib_ranges >= 201911L
425 requires std::ranges::range<U> &&
426 std::convertible_to<std::ranges::range_value_t<U>, T>
427#endif
428 StructArrayEntry(NT_Entry handle, U&& defaultValue, const I&... info)
429 : StructArraySubscriber<T, I...>{handle, defaultValue, info...},
430 StructArrayPublisher<T, I...>{handle, info...} {
431 }
432
433 /**
434 * Determines if the native handle is valid.
435 *
436 * @return True if the native handle is valid, false otherwise.
437 */
438 explicit operator bool() const { return this->m_subHandle != 0; }
439
440 /**
441 * Gets the native handle for the entry.
442 *
443 * @return Native handle
444 */
445 NT_Entry GetHandle() const { return this->m_subHandle; }
446
447 /**
448 * Get the corresponding topic.
449 *
450 * @return Topic
451 */
454 }
455
456 /**
457 * Stops publishing the entry if it's published.
458 */
460};
461
462/**
463 * NetworkTables struct-encoded value array topic.
464 */
465template <typename T, typename... I>
466 requires wpi::StructSerializable<T, I...>
467class StructArrayTopic final : public Topic {
468 public:
471 using EntryType = StructArrayEntry<T, I...>;
472 using ValueType = std::vector<T>;
473 using ParamType = std::span<const T>;
475
476 StructArrayTopic() = default;
477
478 /**
479 * Construct from a topic handle; recommended to use
480 * NetworkTableInstance::GetStructTopic() instead.
481 *
482 * @param handle Native handle
483 * @param info optional struct type info
484 */
485 explicit StructArrayTopic(NT_Topic handle, I... info)
486 : Topic{handle}, m_info{std::move(info)...} {}
487
488 /**
489 * Construct from a generic topic.
490 *
491 * @param topic Topic
492 * @param info optional struct type info
493 */
494 explicit StructArrayTopic(Topic topic, I... info)
495 : Topic{topic}, m_info{std::move(info)...} {}
496
497 /**
498 * Create a new subscriber to the topic.
499 *
500 * <p>The subscriber is only active as long as the returned object
501 * is not destroyed.
502 *
503 * @note Subscribers that do not match the published data type do not return
504 * any values. To determine if the data type matches, use the appropriate
505 * Topic functions.
506 *
507 * @param defaultValue default value used when a default is not provided to a
508 * getter function
509 * @param options subscribe options
510 * @return subscriber
511 */
512 template <typename U>
513#if __cpp_lib_ranges >= 201911L
514 requires std::ranges::range<U> &&
515 std::convertible_to<std::ranges::range_value_t<U>, T>
516#endif
517 [[nodiscard]]
519 U&& defaultValue, const PubSubOptions& options = kDefaultPubSubOptions) {
520 return std::apply(
521 [&](const I&... info) {
522 return StructArraySubscriber<T, I...>{
525 wpi::MakeStructArrayTypeString<T, std::dynamic_extent>(
526 info...),
527 options),
528 defaultValue, info...};
529 },
530 m_info);
531 }
532
533 /**
534 * Create a new subscriber to the topic.
535 *
536 * <p>The subscriber is only active as long as the returned object
537 * is not destroyed.
538 *
539 * @note Subscribers that do not match the published data type do not return
540 * any values. To determine if the data type matches, use the appropriate
541 * Topic functions.
542 *
543 * @param defaultValue default value used when a default is not provided to a
544 * getter function
545 * @param options subscribe options
546 * @return subscriber
547 */
548 [[nodiscard]]
550 std::span<const T> defaultValue,
551 const PubSubOptions& options = kDefaultPubSubOptions) {
552 return std::apply(
553 [&](const I&... info) {
554 return StructArraySubscriber<T, I...>{
557 wpi::MakeStructArrayTypeString<T, std::dynamic_extent>(
558 info...),
559 options),
560 defaultValue, info...};
561 },
562 m_info);
563 }
564
565 /**
566 * Create a new publisher to the topic.
567 *
568 * The publisher is only active as long as the returned object
569 * is not destroyed.
570 *
571 * @note It is not possible to publish two different data types to the same
572 * topic. Conflicts between publishers are typically resolved by the
573 * server on a first-come, first-served basis. Any published values that
574 * do not match the topic's data type are dropped (ignored). To determine
575 * if the data type matches, use the appropriate Topic functions.
576 *
577 * @param options publish options
578 * @return publisher
579 */
580 [[nodiscard]]
582 return std::apply(
583 [&](const I&... info) {
584 return StructArrayPublisher<T, I...>{
587 wpi::MakeStructArrayTypeString<T, std::dynamic_extent>(
588 info...),
589 options),
590 info...};
591 },
592 m_info);
593 }
594
595 /**
596 * Create a new publisher to the topic, with type string and initial
597 * properties.
598 *
599 * The publisher is only active as long as the returned object
600 * is not destroyed.
601 *
602 * @note It is not possible to publish two different data types to the same
603 * topic. Conflicts between publishers are typically resolved by the
604 * server on a first-come, first-served basis. Any published values that
605 * do not match the topic's data type are dropped (ignored). To determine
606 * if the data type matches, use the appropriate Topic functions.
607 *
608 * @param properties JSON properties
609 * @param options publish options
610 * @return publisher
611 */
612 [[nodiscard]]
614 const wpi::json& properties,
615 const PubSubOptions& options = kDefaultPubSubOptions) {
616 return std::apply(
617 [&](const I&... info) {
618 return StructArrayPublisher<T, I...>{
621 wpi::MakeStructArrayTypeString<T, std::dynamic_extent>(
622 info...),
623 properties, options),
624 info...};
625 },
626 m_info);
627 }
628
629 /**
630 * Create a new entry for the topic.
631 *
632 * Entries act as a combination of a subscriber and a weak publisher. The
633 * subscriber is active as long as the entry is not destroyed. The publisher
634 * is created when the entry is first written to, and remains active until
635 * either Unpublish() is called or the entry is destroyed.
636 *
637 * @note It is not possible to use two different data types with the same
638 * topic. Conflicts between publishers are typically resolved by the
639 * server on a first-come, first-served basis. Any published values that
640 * do not match the topic's data type are dropped (ignored), and the entry
641 * will show no new values if the data type does not match. To determine
642 * if the data type matches, use the appropriate Topic functions.
643 *
644 * @param defaultValue default value used when a default is not provided to a
645 * getter function
646 * @param options publish and/or subscribe options
647 * @return entry
648 */
649 template <typename U>
650#if __cpp_lib_ranges >= 201911L
651 requires std::ranges::range<U> &&
652 std::convertible_to<std::ranges::range_value_t<U>, T>
653#endif
654 [[nodiscard]]
655 EntryType GetEntry(U&& defaultValue,
656 const PubSubOptions& options = kDefaultPubSubOptions) {
657 return std::apply(
658 [&](const I&... info) {
659 return StructArrayEntry<T, I...>{
662 wpi::MakeStructArrayTypeString<T, std::dynamic_extent>(
663 info...),
664 options),
665 defaultValue, info...};
666 },
667 m_info);
668 }
669
670 /**
671 * Create a new entry for the topic.
672 *
673 * Entries act as a combination of a subscriber and a weak publisher. The
674 * subscriber is active as long as the entry is not destroyed. The publisher
675 * is created when the entry is first written to, and remains active until
676 * either Unpublish() is called or the entry is destroyed.
677 *
678 * @note It is not possible to use two different data types with the same
679 * topic. Conflicts between publishers are typically resolved by the
680 * server on a first-come, first-served basis. Any published values that
681 * do not match the topic's data type are dropped (ignored), and the entry
682 * will show no new values if the data type does not match. To determine
683 * if the data type matches, use the appropriate Topic functions.
684 *
685 * @param defaultValue default value used when a default is not provided to a
686 * getter function
687 * @param options publish and/or subscribe options
688 * @return entry
689 */
690 [[nodiscard]]
691 EntryType GetEntry(std::span<const T> defaultValue,
692 const PubSubOptions& options = kDefaultPubSubOptions) {
693 return std::apply(
694 [&](const I&... info) {
695 return StructArrayEntry<T, I...>{
698 wpi::MakeStructArrayTypeString<T, std::dynamic_extent>(
699 info...),
700 options),
701 defaultValue, info...};
702 },
703 m_info);
704 }
705
706 private:
707 [[no_unique_address]]
708 std::tuple<I...> m_info;
709};
710
711} // namespace nt
This file defines the SmallVector class.
Definition: format.h:4042
NetworkTables publisher.
Definition: Topic.h:364
Publisher & operator=(const Publisher &)=delete
NT_Publisher m_pubHandle
NetworkTables handle.
Definition: Topic.h:400
NetworkTables struct-encoded value array entry.
Definition: StructArrayTopic.h:403
StructArrayEntry(NT_Entry handle, U &&defaultValue, const I &... info)
Construct from an entry handle; recommended to use StructTopic::GetEntry() instead.
Definition: StructArrayTopic.h:428
std::span< const T > ParamType
Definition: StructArrayTopic.h:409
TopicType GetTopic() const
Get the corresponding topic.
Definition: StructArrayTopic.h:452
std::vector< T > ValueType
Definition: StructArrayTopic.h:408
void Unpublish()
Stops publishing the entry if it's published.
Definition: StructArrayTopic.h:459
NT_Entry GetHandle() const
Gets the native handle for the entry.
Definition: StructArrayTopic.h:445
StructArrayEntry()=default
NetworkTables struct-encoded value array publisher.
Definition: StructArrayTopic.h:240
void Set(U &&value, int64_t time=0)
Publish a new value.
Definition: StructArrayTopic.h:293
StructArrayPublisher & operator=(const StructArrayPublisher &)=delete
void Set(std::span< const T > value, int64_t time=0)
Publish a new value.
Definition: StructArrayTopic.h:313
std::vector< T > ValueType
Definition: StructArrayTopic.h:245
void SetDefault(U &&value)
Publish a default value.
Definition: StructArrayTopic.h:339
StructArrayPublisher(NT_Publisher handle, I... info)
Construct from a publisher handle; recommended to use StructTopic::Publish() instead.
Definition: StructArrayTopic.h:259
StructArrayPublisher & operator=(StructArrayPublisher &&rhs)
Definition: StructArrayTopic.h:272
StructArrayPublisher(StructArrayPublisher &&rhs)
Definition: StructArrayTopic.h:265
void SetDefault(std::span< const T > value)
Publish a default value.
Definition: StructArrayTopic.h:360
StructArrayPublisher(const StructArrayPublisher &)=delete
std::span< const T > ParamType
Definition: StructArrayTopic.h:246
TopicType GetTopic() const
Get the corresponding topic.
Definition: StructArrayTopic.h:379
NetworkTables struct-encoded value array subscriber.
Definition: StructArrayTopic.h:38
ValueType Get(std::span< const T > defaultValue) const
Get the last published value.
Definition: StructArrayTopic.h:102
ValueType Get() const
Get the last published value.
Definition: StructArrayTopic.h:75
TopicType GetTopic() const
Get the corresponding topic.
Definition: StructArrayTopic.h:220
TimestampedValueType GetAtomic(U &&defaultValue) const
Get the last published value along with its timestamp.
Definition: StructArrayTopic.h:128
StructArraySubscriber(NT_Subscriber handle, U &&defaultValue, I... info)
Construct from a subscriber handle; recommended to use StructTopic::Subscribe() instead.
Definition: StructArrayTopic.h:62
std::span< const T > ParamType
Definition: StructArrayTopic.h:44
ValueType Get(U &&defaultValue) const
Get the last published value.
Definition: StructArrayTopic.h:90
TimestampedValueType GetAtomic() const
Get the last published value along with its timestamp If no value has been published or the value can...
Definition: StructArrayTopic.h:113
TimestampedValueType GetAtomic(std::span< const T > defaultValue) const
Get the last published value along with its timestamp.
Definition: StructArrayTopic.h:157
std::vector< T > ValueType
Definition: StructArrayTopic.h:43
std::vector< TimestampedValueType > ReadQueue()
Get an array of all valid value changes since the last call to ReadQueue.
Definition: StructArrayTopic.h:189
NetworkTables struct-encoded value array topic.
Definition: StructArrayTopic.h:467
StructArrayTopic(NT_Topic handle, I... info)
Construct from a topic handle; recommended to use NetworkTableInstance::GetStructTopic() instead.
Definition: StructArrayTopic.h:485
SubscriberType Subscribe(std::span< const T > defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic.
Definition: StructArrayTopic.h:549
PublisherType PublishEx(const wpi::json &properties, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic, with type string and initial properties.
Definition: StructArrayTopic.h:613
std::span< const T > ParamType
Definition: StructArrayTopic.h:473
PublisherType Publish(const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic.
Definition: StructArrayTopic.h:581
SubscriberType Subscribe(U &&defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic.
Definition: StructArrayTopic.h:518
EntryType GetEntry(std::span< const T > defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new entry for the topic.
Definition: StructArrayTopic.h:691
EntryType GetEntry(U &&defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new entry for the topic.
Definition: StructArrayTopic.h:655
StructArrayTopic(Topic topic, I... info)
Construct from a generic topic.
Definition: StructArrayTopic.h:494
StructArrayTopic()=default
std::vector< T > ValueType
Definition: StructArrayTopic.h:472
NetworkTables subscriber.
Definition: Topic.h:309
NT_Subscriber m_subHandle
Definition: Topic.h:360
NetworkTables Topic.
Definition: Topic.h:28
NT_Topic m_handle
Definition: Topic.h:305
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1211
Definition: Struct.h:344
void Write(U &&data, F &&func, const I &... info)
Definition: Struct.h:364
Specifies that a type is capable of raw struct serialization and deserialization.
Definition: Struct.h:68
std::vector< TimestampedRaw > ReadQueueRaw(NT_Handle subentry)
Get an array of all value changes since the last call to ReadQueue.
TimestampedRaw GetAtomicRaw(NT_Handle subentry, std::span< const uint8_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_RAW
Definition: ntcore_c.h:58
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.
constexpr auto in(type t, int set) -> bool
Definition: base.h:701
NetworkTables (ntcore) namespace.
Definition: NetworkTableListener.inc:19
Implement std::hash so that hash_code can be used in STL containers.
Definition: array.h:89
NetworkTables publish/subscribe options.
Definition: ntcore_cpp.h:305
Timestamped value.
Definition: ntcore_cpp_types.h:30
int64_t time
Time in local time base.
Definition: ntcore_cpp_types.h:38
int64_t serverTime
Time in server time base.
Definition: ntcore_cpp_types.h:43
T value
Value.
Definition: ntcore_cpp_types.h:48
Struct serialization template.
Definition: Struct.h:38