WPILibC++ 2024.3.2
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]] std::tuple<I...> m_info;
232};
233
234/**
235 * NetworkTables struct-encoded value array publisher.
236 */
237template <typename T, typename... I>
238 requires wpi::StructSerializable<T, I...>
240 using S = wpi::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) { ::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) { ::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),
346 [&](auto bytes) { ::nt::SetDefaultRaw(m_pubHandle, bytes); },
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,
367 [&](auto bytes) { ::nt::SetDefaultRaw(m_pubHandle, bytes); },
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::StructArrayBuffer<T, I...> m_buf;
389 std::atomic_bool m_schemaPublished{false};
390 [[no_unique_address]] std::tuple<I...> m_info;
391};
392
393/**
394 * NetworkTables struct-encoded value array entry.
395 *
396 * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed.
397 */
398template <typename T, typename... I>
399 requires wpi::StructSerializable<T, I...>
400class StructArrayEntry final : public StructArraySubscriber<T, I...>,
401 public StructArrayPublisher<T, I...> {
402 public:
405 using TopicType = StructArrayTopic<T, I...>;
406 using ValueType = std::vector<T>;
407 using ParamType = std::span<const T>;
408
410
411 StructArrayEntry() = default;
412
413 /**
414 * Construct from an entry handle; recommended to use
415 * StructTopic::GetEntry() instead.
416 *
417 * @param handle Native handle
418 * @param defaultValue Default value
419 * @param info optional struct type info
420 */
421 template <typename U>
422#if __cpp_lib_ranges >= 201911L
423 requires std::ranges::range<U> &&
424 std::convertible_to<std::ranges::range_value_t<U>, T>
425#endif
426 StructArrayEntry(NT_Entry handle, U&& defaultValue, const I&... info)
427 : StructArraySubscriber<T, I...>{handle, defaultValue, info...},
428 StructArrayPublisher<T, I...>{handle, info...} {
429 }
430
431 /**
432 * Determines if the native handle is valid.
433 *
434 * @return True if the native handle is valid, false otherwise.
435 */
436 explicit operator bool() const { return this->m_subHandle != 0; }
437
438 /**
439 * Gets the native handle for the entry.
440 *
441 * @return Native handle
442 */
443 NT_Entry GetHandle() const { return this->m_subHandle; }
444
445 /**
446 * Get the corresponding topic.
447 *
448 * @return Topic
449 */
452 }
453
454 /**
455 * Stops publishing the entry if it's published.
456 */
458};
459
460/**
461 * NetworkTables struct-encoded value array topic.
462 */
463template <typename T, typename... I>
464 requires wpi::StructSerializable<T, I...>
465class StructArrayTopic final : public Topic {
466 public:
469 using EntryType = StructArrayEntry<T, I...>;
470 using ValueType = std::vector<T>;
471 using ParamType = std::span<const T>;
473
474 StructArrayTopic() = default;
475
476 /**
477 * Construct from a topic handle; recommended to use
478 * NetworkTableInstance::GetStructTopic() instead.
479 *
480 * @param handle Native handle
481 * @param info optional struct type info
482 */
483 explicit StructArrayTopic(NT_Topic handle, I... info)
484 : Topic{handle}, m_info{std::move(info)...} {}
485
486 /**
487 * Construct from a generic topic.
488 *
489 * @param topic Topic
490 * @param info optional struct type info
491 */
492 explicit StructArrayTopic(Topic topic, I... info)
493 : Topic{topic}, m_info{std::move(info)...} {}
494
495 /**
496 * Create a new subscriber to the topic.
497 *
498 * <p>The subscriber is only active as long as the returned object
499 * is not destroyed.
500 *
501 * @note Subscribers that do not match the published data type do not return
502 * any values. To determine if the data type matches, use the appropriate
503 * Topic functions.
504 *
505 * @param defaultValue default value used when a default is not provided to a
506 * getter function
507 * @param options subscribe options
508 * @return subscriber
509 */
510 template <typename U>
511#if __cpp_lib_ranges >= 201911L
512 requires std::ranges::range<U> &&
513 std::convertible_to<std::ranges::range_value_t<U>, T>
514#endif
515 [[nodiscard]]
517 U&& defaultValue, const PubSubOptions& options = kDefaultPubSubOptions) {
518 return std::apply(
519 [&](const I&... info) {
520 return StructArraySubscriber<T, I...>{
523 wpi::MakeStructArrayTypeString<T, std::dynamic_extent>(
524 info...),
525 options),
526 defaultValue, info...};
527 },
528 m_info);
529 }
530
531 /**
532 * Create a new subscriber to the topic.
533 *
534 * <p>The subscriber is only active as long as the returned object
535 * is not destroyed.
536 *
537 * @note Subscribers that do not match the published data type do not return
538 * any values. To determine if the data type matches, use the appropriate
539 * Topic functions.
540 *
541 * @param defaultValue default value used when a default is not provided to a
542 * getter function
543 * @param options subscribe options
544 * @return subscriber
545 */
546 [[nodiscard]]
548 std::span<const T> defaultValue,
549 const PubSubOptions& options = kDefaultPubSubOptions) {
550 return std::apply(
551 [&](const I&... info) {
552 return StructArraySubscriber<T, I...>{
555 wpi::MakeStructArrayTypeString<T, std::dynamic_extent>(
556 info...),
557 options),
558 defaultValue, info...};
559 },
560 m_info);
561 }
562
563 /**
564 * Create a new publisher to the topic.
565 *
566 * The publisher is only active as long as the returned object
567 * is not destroyed.
568 *
569 * @note It is not possible to publish two different data types to the same
570 * topic. Conflicts between publishers are typically resolved by the
571 * server on a first-come, first-served basis. Any published values that
572 * do not match the topic's data type are dropped (ignored). To determine
573 * if the data type matches, use the appropriate Topic functions.
574 *
575 * @param options publish options
576 * @return publisher
577 */
578 [[nodiscard]]
580 return std::apply(
581 [&](const I&... info) {
582 return StructArrayPublisher<T, I...>{
585 wpi::MakeStructArrayTypeString<T, std::dynamic_extent>(
586 info...),
587 options),
588 info...};
589 },
590 m_info);
591 }
592
593 /**
594 * Create a new publisher to the topic, with type string and initial
595 * properties.
596 *
597 * The publisher is only active as long as the returned object
598 * is not destroyed.
599 *
600 * @note It is not possible to publish two different data types to the same
601 * topic. Conflicts between publishers are typically resolved by the
602 * server on a first-come, first-served basis. Any published values that
603 * do not match the topic's data type are dropped (ignored). To determine
604 * if the data type matches, use the appropriate Topic functions.
605 *
606 * @param properties JSON properties
607 * @param options publish options
608 * @return publisher
609 */
610 [[nodiscard]]
612 const wpi::json& properties,
613 const PubSubOptions& options = kDefaultPubSubOptions) {
614 return std::apply(
615 [&](const I&... info) {
616 return StructArrayPublisher<T, I...>{
619 wpi::MakeStructArrayTypeString<T, std::dynamic_extent>(
620 info...),
621 properties, options),
622 info...};
623 },
624 m_info);
625 }
626
627 /**
628 * Create a new entry for the topic.
629 *
630 * Entries act as a combination of a subscriber and a weak publisher. The
631 * subscriber is active as long as the entry is not destroyed. The publisher
632 * is created when the entry is first written to, and remains active until
633 * either Unpublish() is called or the entry is destroyed.
634 *
635 * @note It is not possible to use two different data types with the same
636 * topic. Conflicts between publishers are typically resolved by the
637 * server on a first-come, first-served basis. Any published values that
638 * do not match the topic's data type are dropped (ignored), and the entry
639 * will show no new values if the data type does not match. To determine
640 * if the data type matches, use the appropriate Topic functions.
641 *
642 * @param defaultValue default value used when a default is not provided to a
643 * getter function
644 * @param options publish and/or subscribe options
645 * @return entry
646 */
647 template <typename U>
648#if __cpp_lib_ranges >= 201911L
649 requires std::ranges::range<U> &&
650 std::convertible_to<std::ranges::range_value_t<U>, T>
651#endif
652 [[nodiscard]]
653 EntryType GetEntry(U&& defaultValue,
654 const PubSubOptions& options = kDefaultPubSubOptions) {
655 return std::apply(
656 [&](const I&... info) {
657 return StructArrayEntry<T, I...>{
660 wpi::MakeStructArrayTypeString<T, std::dynamic_extent>(
661 info...),
662 options),
663 defaultValue, info...};
664 },
665 m_info);
666 }
667
668 /**
669 * Create a new entry for the topic.
670 *
671 * Entries act as a combination of a subscriber and a weak publisher. The
672 * subscriber is active as long as the entry is not destroyed. The publisher
673 * is created when the entry is first written to, and remains active until
674 * either Unpublish() is called or the entry is destroyed.
675 *
676 * @note It is not possible to use two different data types with the same
677 * topic. Conflicts between publishers are typically resolved by the
678 * server on a first-come, first-served basis. Any published values that
679 * do not match the topic's data type are dropped (ignored), and the entry
680 * will show no new values if the data type does not match. To determine
681 * if the data type matches, use the appropriate Topic functions.
682 *
683 * @param defaultValue default value used when a default is not provided to a
684 * getter function
685 * @param options publish and/or subscribe options
686 * @return entry
687 */
688 [[nodiscard]]
689 EntryType GetEntry(std::span<const T> defaultValue,
690 const PubSubOptions& options = kDefaultPubSubOptions) {
691 return std::apply(
692 [&](const I&... info) {
693 return StructArrayEntry<T, I...>{
696 wpi::MakeStructArrayTypeString<T, std::dynamic_extent>(
697 info...),
698 options),
699 defaultValue, info...};
700 },
701 m_info);
702 }
703
704 private:
705 [[no_unique_address]] std::tuple<I...> m_info;
706};
707
708} // namespace nt
This file defines the SmallVector class.
Definition: format.h:4134
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:401
StructArrayEntry(NT_Entry handle, U &&defaultValue, const I &... info)
Construct from an entry handle; recommended to use StructTopic::GetEntry() instead.
Definition: StructArrayTopic.h:426
std::span< const T > ParamType
Definition: StructArrayTopic.h:407
TopicType GetTopic() const
Get the corresponding topic.
Definition: StructArrayTopic.h:450
std::vector< T > ValueType
Definition: StructArrayTopic.h:406
void Unpublish()
Stops publishing the entry if it's published.
Definition: StructArrayTopic.h:457
NT_Entry GetHandle() const
Gets the native handle for the entry.
Definition: StructArrayTopic.h:443
StructArrayEntry()=default
NetworkTables struct-encoded value array publisher.
Definition: StructArrayTopic.h:239
void Set(U &&value, int64_t time=0)
Publish a new value.
Definition: StructArrayTopic.h:292
StructArrayPublisher & operator=(const StructArrayPublisher &)=delete
void Set(std::span< const T > value, int64_t time=0)
Publish a new value.
Definition: StructArrayTopic.h:312
std::vector< T > ValueType
Definition: StructArrayTopic.h:244
void SetDefault(U &&value)
Publish a default value.
Definition: StructArrayTopic.h:338
StructArrayPublisher(NT_Publisher handle, I... info)
Construct from a publisher handle; recommended to use StructTopic::Publish() instead.
Definition: StructArrayTopic.h:258
StructArrayPublisher & operator=(StructArrayPublisher &&rhs)
Definition: StructArrayTopic.h:271
StructArrayPublisher(StructArrayPublisher &&rhs)
Definition: StructArrayTopic.h:264
void SetDefault(std::span< const T > value)
Publish a default value.
Definition: StructArrayTopic.h:359
StructArrayPublisher(const StructArrayPublisher &)=delete
std::span< const T > ParamType
Definition: StructArrayTopic.h:245
TopicType GetTopic() const
Get the corresponding topic.
Definition: StructArrayTopic.h:378
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:465
StructArrayTopic(NT_Topic handle, I... info)
Construct from a topic handle; recommended to use NetworkTableInstance::GetStructTopic() instead.
Definition: StructArrayTopic.h:483
SubscriberType Subscribe(std::span< const T > defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic.
Definition: StructArrayTopic.h:547
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:611
std::span< const T > ParamType
Definition: StructArrayTopic.h:471
PublisherType Publish(const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic.
Definition: StructArrayTopic.h:579
SubscriberType Subscribe(U &&defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic.
Definition: StructArrayTopic.h:516
EntryType GetEntry(std::span< const T > defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new entry for the topic.
Definition: StructArrayTopic.h:689
EntryType GetEntry(U &&defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new entry for the topic.
Definition: StructArrayTopic.h:653
StructArrayTopic(Topic topic, I... info)
Construct from a generic topic.
Definition: StructArrayTopic.h:492
StructArrayTopic()=default
std::vector< T > ValueType
Definition: StructArrayTopic.h:470
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:1202
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:40
NT_Handle NT_Subscriber
Definition: ntcore_c.h:41
NT_Handle NT_Publisher
Definition: ntcore_c.h:42
NT_Handle NT_Entry
Definition: ntcore_c.h:35
@ NT_RAW
Definition: ntcore_c.h:56
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: core.h:611
NetworkTables (ntcore) namespace.
Definition: ntcore_cpp.h:36
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