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