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