28template <
typename T,
typename... I>
35template <
typename T,
typename... I>
58 m_defaultValue{
std::move(defaultValue)},
59 m_info{
std::move(info)...} {}
93 if (view.
value.size() < std::apply(S::GetSize, m_info)) {
97 [&](
const I&... info) {
125 if (view.
value.size() < std::apply(S::GetSize, m_info)) {
126 return {0, 0, defaultValue};
131 [&](
const I&... info) {
return S::Unpack(view.
value, info...); },
149 std::vector<TimestampedValueType> rv;
150 rv.reserve(raw.size());
151 for (
auto&& r : raw) {
152 if (r.value.size() < std::apply(S::GetSize, m_info)) {
156 [&](
const I&... info) {
158 r.time, r.serverTime,
159 S::Unpack(std::span<const uint8_t>(r.value), info...));
174 [&](
const I&... info) {
183 [[no_unique_address]] std::tuple<I...> m_info;
189template <
typename T,
typename... I>
209 rhs.m_schemaPublished.load(
std::memory_order_relaxed)},
210 m_info{
std::move(rhs.m_info)} {}
214 m_schemaPublished.store(
215 rhs.m_schemaPublished.load(std::memory_order_relaxed),
216 std::memory_order_relaxed);
217 m_info = std::move(rhs.m_info);
237 void Set(
const T& value, int64_t time = 0) {
238 if (!m_schemaPublished.exchange(
true, std::memory_order_relaxed)) {
240 [&](
const I&... info) {
245 if constexpr (
sizeof...(I) == 0) {
247 uint8_t buf[S::GetSize()];
255 std::apply([&](
const I&... info) { S::Pack(buf, value, info...); }, m_info);
267 if (!m_schemaPublished.exchange(
true, std::memory_order_relaxed)) {
269 [&](
const I&... info) {
274 if constexpr (
sizeof...(I) == 0) {
276 uint8_t buf[S::GetSize()];
284 std::apply([&](
const I&... info) { S::Pack(buf, value, info...); }, m_info);
295 [&](
const I&... info) {
303 std::atomic_bool m_schemaPublished{
false};
304 [[no_unique_address]] std::tuple<I...> m_info;
312template <
typename T,
typename... I>
369template <
typename T,
typename... I>
390 :
Topic{handle}, m_info{
std::move(info)...} {}
399 :
Topic{topic}, m_info{
std::move(info)...} {}
420 [&](
const I&... info) {
423 wpi::GetStructTypeString<T, I...>(info...),
425 std::move(defaultValue), info...};
448 [&](
const I&... info) {
451 wpi::GetStructTypeString<T, I...>(info...),
477 const wpi::json& properties,
480 [&](
const I&... info) {
483 wpi::GetStructTypeString<T, I...>(info...),
484 properties, options),
514 [&](
const I&... info) {
517 wpi::GetStructTypeString<T, I...>(info...),
519 std::move(defaultValue), info...};
525 [[no_unique_address]] std::tuple<I...> m_info;
This file defines the SmallVector class.
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 entry.
Definition: StructTopic.h:315
T ValueType
Definition: StructTopic.h:320
TopicType GetTopic() const
Get the corresponding topic.
Definition: StructTopic.h:358
NT_Entry GetHandle() const
Gets the native handle for the entry.
Definition: StructTopic.h:351
StructEntry(NT_Entry handle, T defaultValue, const I &... info)
Construct from an entry handle; recommended to use StructTopic::GetEntry() instead.
Definition: StructTopic.h:335
const T & ParamType
Definition: StructTopic.h:321
void Unpublish()
Stops publishing the entry if it's published.
Definition: StructTopic.h:363
NetworkTables struct-encoded value publisher.
Definition: StructTopic.h:191
StructPublisher(StructPublisher &&rhs)
Definition: StructTopic.h:206
StructPublisher()=default
StructPublisher & operator=(const StructPublisher &)=delete
StructPublisher(const StructPublisher &)=delete
T ValueType
Definition: StructTopic.h:196
void Set(const T &value, int64_t time=0)
Publish a new value.
Definition: StructTopic.h:237
StructPublisher(NT_Publisher handle, I... info)
Construct from a publisher handle; recommended to use StructTopic::Publish() instead.
Definition: StructTopic.h:228
StructPublisher & operator=(StructPublisher &&rhs)
Definition: StructTopic.h:212
const T & ParamType
Definition: StructTopic.h:197
TopicType GetTopic() const
Get the corresponding topic.
Definition: StructTopic.h:293
void SetDefault(const T &value)
Publish a default value.
Definition: StructTopic.h:266
NetworkTables struct-encoded value subscriber.
Definition: StructTopic.h:37
TimestampedValueType GetAtomic(const T &defaultValue) const
Get the last published value along with its timestamp.
Definition: StructTopic.h:122
TimestampedValueType GetAtomic() const
Get the last published value along with its timestamp If no value has been published or the value can...
Definition: StructTopic.h:112
TopicType GetTopic() const
Get the corresponding topic.
Definition: StructTopic.h:172
StructSubscriber(NT_Subscriber handle, T defaultValue, I... info)
Construct from a subscriber handle; recommended to use StructTopic::Subscribe() instead.
Definition: StructTopic.h:56
bool GetInto(T *out)
Get the last published value, replacing the contents in place of an existing object.
Definition: StructTopic.h:90
std::vector< TimestampedValueType > ReadQueue()
Get an array of all valid value changes since the last call to ReadQueue.
Definition: StructTopic.h:147
StructSubscriber()=default
ValueType Get(const T &defaultValue) const
Get the last published value.
Definition: StructTopic.h:78
T ValueType
Definition: StructTopic.h:42
ValueType Get() const
Get the last published value.
Definition: StructTopic.h:68
const T & ParamType
Definition: StructTopic.h:43
NetworkTables struct-encoded value topic.
Definition: StructTopic.h:371
const T & ParamType
Definition: StructTopic.h:377
PublisherType PublishEx(const wpi::json &properties, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic, with type string and initial properties.
Definition: StructTopic.h:476
T ValueType
Definition: StructTopic.h:376
SubscriberType Subscribe(T defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic.
Definition: StructTopic.h:417
EntryType GetEntry(T defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new entry for the topic.
Definition: StructTopic.h:511
PublisherType Publish(const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic.
Definition: StructTopic.h:446
StructTopic(Topic topic, I... info)
Construct from a generic topic.
Definition: StructTopic.h:398
StructTopic(NT_Topic handle, I... info)
Construct from a topic handle; recommended to use NetworkTableInstance::GetStructTopic() instead.
Definition: StructTopic.h:389
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
NetworkTableInstance GetInstance() const
Gets the instance for the topic.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1202
void resize_for_overwrite(size_type N)
Like resize, but T is POD, the new values won't be initialized.
Definition: SmallVector.h:647
Specifies that a type is capable of raw struct serialization and deserialization.
Definition: Struct.h:68
bool SetDefaultRaw(NT_Handle pubentry, std::span< const uint8_t > defaultValue)
Publish a default value.
std::vector< TimestampedRaw > ReadQueueRaw(NT_Handle subentry)
Get an array of all value changes since the last call to ReadQueue.
bool SetRaw(NT_Handle pubentry, std::span< const uint8_t > value, int64_t time=0)
Publish a new value.
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.
NetworkTables (ntcore) namespace.
Definition: ntcore_cpp.h:36
void UnpackStructInto(T *out, std::span< const uint8_t > data, const I &... info)
Unpack a serialized struct into an existing object, overwriting its contents.
Definition: Struct.h:200
constexpr bool is_constexpr(Lambda)
Definition: type_traits.h:81
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