diff --git a/ntcore/src/generate/main/native/include/networktables/Topic.h.jinja b/ntcore/src/generate/main/native/include/networktables/Topic.h.jinja index 93abc498713..19939c0b946 100644 --- a/ntcore/src/generate/main/native/include/networktables/Topic.h.jinja +++ b/ntcore/src/generate/main/native/include/networktables/Topic.h.jinja @@ -15,7 +15,9 @@ #include +#include "networktables/NetworkTableType.h" #include "networktables/Topic.h" +#include "ntcore_cpp.h" namespace wpi { template @@ -50,7 +52,9 @@ class {{ TypeName }}Subscriber : public Subscriber { * @param handle Native handle * @param defaultValue Default value */ - {{ TypeName }}Subscriber(NT_Subscriber handle, ParamType defaultValue); + {{ TypeName }}Subscriber(NT_Subscriber handle, ParamType defaultValue) + : Subscriber{handle}, + m_defaultValue{{ '{' }}{{ cpp.DefaultValueCopy|default('defaultValue') }}} {} /** * Get the last published value. @@ -58,7 +62,9 @@ class {{ TypeName }}Subscriber : public Subscriber { * * @return value */ - ValueType Get() const; + ValueType Get() const { + return Get(m_defaultValue); + } /** * Get the last published value. @@ -67,7 +73,9 @@ class {{ TypeName }}Subscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - ValueType Get(ParamType defaultValue) const; + ValueType Get(ParamType defaultValue) const { + return ::nt::Get{{ TypeName }}(m_subHandle, defaultValue); + } {% if cpp.SmallRetType and cpp.SmallElemType %} /** * Get the last published value. @@ -76,7 +84,9 @@ class {{ TypeName }}Subscriber : public Subscriber { * @param buf storage for returned value * @return value */ - SmallRetType Get(wpi::SmallVectorImpl& buf) const; + SmallRetType Get(wpi::SmallVectorImpl& buf) const { + return Get(buf, m_defaultValue); + } /** * Get the last published value. @@ -86,7 +96,9 @@ class {{ TypeName }}Subscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const; + SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { + return nt::Get{{ TypeName }}(m_subHandle, buf, defaultValue); + } {% endif %} /** * Get the last published value along with its timestamp @@ -95,7 +107,9 @@ class {{ TypeName }}Subscriber : public Subscriber { * * @return timestamped value */ - TimestampedValueType GetAtomic() const; + TimestampedValueType GetAtomic() const { + return GetAtomic(m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -105,7 +119,9 @@ class {{ TypeName }}Subscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return timestamped value */ - TimestampedValueType GetAtomic(ParamType defaultValue) const; + TimestampedValueType GetAtomic(ParamType defaultValue) const { + return ::nt::GetAtomic{{ TypeName }}(m_subHandle, defaultValue); + } {% if cpp.SmallRetType and cpp.SmallElemType %} /** * Get the last published value along with its timestamp. @@ -116,7 +132,9 @@ class {{ TypeName }}Subscriber : public Subscriber { * @return timestamped value */ TimestampedValueViewType GetAtomic( - wpi::SmallVectorImpl& buf) const; + wpi::SmallVectorImpl& buf) const { + return GetAtomic(buf, m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -129,7 +147,9 @@ class {{ TypeName }}Subscriber : public Subscriber { */ TimestampedValueViewType GetAtomic( wpi::SmallVectorImpl& buf, - ParamType defaultValue) const; + ParamType defaultValue) const { + return nt::GetAtomic{{ TypeName }}(m_subHandle, buf, defaultValue); + } {% endif %} /** * Get an array of all value changes since the last call to ReadQueue. @@ -141,7 +161,9 @@ class {{ TypeName }}Subscriber : public Subscriber { * @return Array of timestamped values; empty array if no new changes have * been published since the previous call. */ - std::vector ReadQueue(); + std::vector ReadQueue() { + return ::nt::ReadQueue{{ TypeName }}(m_subHandle); + } /** * Get the corresponding topic. @@ -176,7 +198,7 @@ class {{ TypeName }}Publisher : public Publisher { * * @param handle Native handle */ - explicit {{ TypeName }}Publisher(NT_Publisher handle); + explicit {{ TypeName }}Publisher(NT_Publisher handle) : Publisher{handle} {} /** * Publish a new value. @@ -184,7 +206,9 @@ class {{ TypeName }}Publisher : public Publisher { * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(ParamType value, int64_t time = 0); + void Set(ParamType value, int64_t time = 0) { + ::nt::Set{{ TypeName }}(m_pubHandle, value, time); + } /** * Publish a default value. @@ -193,7 +217,9 @@ class {{ TypeName }}Publisher : public Publisher { * * @param value value */ - void SetDefault(ParamType value); + void SetDefault(ParamType value) { + ::nt::SetDefault{{ TypeName }}(m_pubHandle, value); + } /** * Get the corresponding topic. @@ -231,7 +257,9 @@ class {{ TypeName }}Entry final : public {{ TypeName }}Subscriber, * @param handle Native handle * @param defaultValue Default value */ - {{ TypeName }}Entry(NT_Entry handle, ParamType defaultValue); + {{ TypeName }}Entry(NT_Entry handle, ParamType defaultValue) + : {{ TypeName }}Subscriber{handle, defaultValue}, + {{ TypeName }}Publisher{handle} {} /** * Determines if the native handle is valid. @@ -257,7 +285,9 @@ class {{ TypeName }}Entry final : public {{ TypeName }}Subscriber, /** * Stops publishing the entry if it's published. */ - void Unpublish(); + void Unpublish() { + ::nt::Unpublish(m_pubHandle); + } }; /** @@ -314,7 +344,11 @@ class {{ TypeName }}Topic final : public Topic { [[nodiscard]] SubscriberType Subscribe( {% if not TypeString %}std::string_view typeString, {% endif %}ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return {{ TypeName }}Subscriber{ + ::nt::Subscribe(m_handle, NT_{{ cpp.TYPE_NAME }}, {{ TypeString|default('typeString') }}, options), + defaultValue}; + } {%- if TypeString %} /** * Create a new subscriber to the topic, with specific type string. @@ -335,7 +369,11 @@ class {{ TypeName }}Topic final : public Topic { [[nodiscard]] SubscriberType SubscribeEx( std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return {{ TypeName }}Subscriber{ + ::nt::Subscribe(m_handle, NT_{{ cpp.TYPE_NAME }}, typeString, options), + defaultValue}; + } {% endif %} /** * Create a new publisher to the topic. @@ -356,7 +394,10 @@ class {{ TypeName }}Topic final : public Topic { * @return publisher */ [[nodiscard]] - PublisherType Publish({% if not TypeString %}std::string_view typeString, {% endif %}const PubSubOptions& options = kDefaultPubSubOptions); + PublisherType Publish({% if not TypeString %}std::string_view typeString, {% endif %}const PubSubOptions& options = kDefaultPubSubOptions) { + return {{ TypeName }}Publisher{ + ::nt::Publish(m_handle, NT_{{ cpp.TYPE_NAME }}, {{ TypeString|default('typeString') }}, options)}; + } /** * Create a new publisher to the topic, with type string and initial @@ -378,7 +419,10 @@ class {{ TypeName }}Topic final : public Topic { */ [[nodiscard]] PublisherType PublishEx(std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions) { + return {{ TypeName }}Publisher{ + ::nt::PublishEx(m_handle, NT_{{ cpp.TYPE_NAME }}, typeString, properties, options)}; + } /** * Create a new entry for the topic. @@ -405,7 +449,11 @@ class {{ TypeName }}Topic final : public Topic { */ [[nodiscard]] EntryType GetEntry({% if not TypeString %}std::string_view typeString, {% endif %}ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return {{ TypeName }}Entry{ + ::nt::GetEntry(m_handle, NT_{{ cpp.TYPE_NAME }}, {{ TypeString|default('typeString') }}, options), + defaultValue}; + } {%- if TypeString %} /** * Create a new entry for the topic, with specific type string. @@ -430,11 +478,25 @@ class {{ TypeName }}Topic final : public Topic { */ [[nodiscard]] EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return {{ TypeName }}Entry{ + ::nt::GetEntry(m_handle, NT_{{ cpp.TYPE_NAME }}, typeString, options), + defaultValue}; + } {% endif %} }; -} // namespace nt +inline {{ TypeName }}Topic {{ TypeName }}Subscriber::GetTopic() const { + return {{ TypeName }}Topic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline {{ TypeName }}Topic {{ TypeName }}Publisher::GetTopic() const { + return {{ TypeName }}Topic{::nt::GetTopicFromHandle(m_pubHandle)}; +} -#include "networktables/{{ TypeName }}Topic.inc" +inline {{ TypeName }}Topic {{ TypeName }}Entry::GetTopic() const { + return {{ TypeName }}Topic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +} // namespace nt diff --git a/ntcore/src/generate/main/native/include/networktables/Topic.inc.jinja b/ntcore/src/generate/main/native/include/networktables/Topic.inc.jinja deleted file mode 100644 index 7a5bc7693bf..00000000000 --- a/ntcore/src/generate/main/native/include/networktables/Topic.inc.jinja +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY - -#pragma once - -#include - -#include "networktables/{{ TypeName }}Topic.h" -#include "networktables/NetworkTableType.h" -#include "ntcore_cpp.h" - -namespace nt { - -inline {{ TypeName }}Subscriber::{{ TypeName }}Subscriber( - NT_Subscriber handle, ParamType defaultValue) - : Subscriber{handle}, - m_defaultValue{{ '{' }}{{ cpp.DefaultValueCopy|default('defaultValue') }}} {} - -inline {{ cpp.ValueType }} {{ TypeName }}Subscriber::Get() const { - return Get(m_defaultValue); -} - -inline {{ cpp.ValueType }} {{ TypeName }}Subscriber::Get( - ParamType defaultValue) const { - return ::nt::Get{{ TypeName }}(m_subHandle, defaultValue); -} -{% if cpp.SmallRetType and cpp.SmallElemType %} -inline {{ cpp.SmallRetType }} {{ TypeName }}Subscriber::Get(wpi::SmallVectorImpl<{{ cpp.SmallElemType }}>& buf) const { - return Get(buf, m_defaultValue); -} - -inline {{ cpp.SmallRetType }} {{ TypeName }}Subscriber::Get(wpi::SmallVectorImpl<{{ cpp.SmallElemType }}>& buf, ParamType defaultValue) const { - return nt::Get{{ TypeName }}(m_subHandle, buf, defaultValue); -} -{% endif %} -inline Timestamped{{ TypeName }} {{ TypeName }}Subscriber::GetAtomic() const { - return GetAtomic(m_defaultValue); -} - -inline Timestamped{{ TypeName }} {{ TypeName }}Subscriber::GetAtomic( - ParamType defaultValue) const { - return ::nt::GetAtomic{{ TypeName }}(m_subHandle, defaultValue); -} -{% if cpp.SmallRetType and cpp.SmallElemType %} -inline Timestamped{{ TypeName }}View {{ TypeName }}Subscriber::GetAtomic(wpi::SmallVectorImpl<{{ cpp.SmallElemType }}>& buf) const { - return GetAtomic(buf, m_defaultValue); -} - -inline Timestamped{{ TypeName }}View {{ TypeName }}Subscriber::GetAtomic(wpi::SmallVectorImpl<{{ cpp.SmallElemType }}>& buf, ParamType defaultValue) const { - return nt::GetAtomic{{ TypeName }}(m_subHandle, buf, defaultValue); -} -{% endif %} -inline std::vector -{{ TypeName }}Subscriber::ReadQueue() { - return ::nt::ReadQueue{{ TypeName }}(m_subHandle); -} - -inline {{ TypeName }}Topic {{ TypeName }}Subscriber::GetTopic() const { - return {{ TypeName }}Topic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline {{ TypeName }}Publisher::{{ TypeName }}Publisher(NT_Publisher handle) - : Publisher{handle} {} - -inline void {{ TypeName }}Publisher::Set(ParamType value, - int64_t time) { - ::nt::Set{{ TypeName }}(m_pubHandle, value, time); -} - -inline void {{ TypeName }}Publisher::SetDefault(ParamType value) { - ::nt::SetDefault{{ TypeName }}(m_pubHandle, value); -} - -inline {{ TypeName }}Topic {{ TypeName }}Publisher::GetTopic() const { - return {{ TypeName }}Topic{::nt::GetTopicFromHandle(m_pubHandle)}; -} - -inline {{ TypeName }}Entry::{{ TypeName }}Entry( - NT_Entry handle, ParamType defaultValue) - : {{ TypeName }}Subscriber{handle, defaultValue}, - {{ TypeName }}Publisher{handle} {} - -inline {{ TypeName }}Topic {{ TypeName }}Entry::GetTopic() const { - return {{ TypeName }}Topic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline void {{ TypeName }}Entry::Unpublish() { - ::nt::Unpublish(m_pubHandle); -} - -inline {{ TypeName }}Subscriber {{ TypeName }}Topic::Subscribe( - {% if not TypeString %}std::string_view typeString, {% endif %}{{ cpp.ParamType }} defaultValue, - const PubSubOptions& options) { - return {{ TypeName }}Subscriber{ - ::nt::Subscribe(m_handle, NT_{{ cpp.TYPE_NAME }}, {{ TypeString|default('typeString') }}, options), - defaultValue}; -} -{%- if TypeString %} -inline {{ TypeName }}Subscriber {{ TypeName }}Topic::SubscribeEx( - std::string_view typeString, {{ cpp.ParamType }} defaultValue, - const PubSubOptions& options) { - return {{ TypeName }}Subscriber{ - ::nt::Subscribe(m_handle, NT_{{ cpp.TYPE_NAME }}, typeString, options), - defaultValue}; -} -{% endif %} -inline {{ TypeName }}Publisher {{ TypeName }}Topic::Publish( - {% if not TypeString %}std::string_view typeString, {% endif %}const PubSubOptions& options) { - return {{ TypeName }}Publisher{ - ::nt::Publish(m_handle, NT_{{ cpp.TYPE_NAME }}, {{ TypeString|default('typeString') }}, options)}; -} - -inline {{ TypeName }}Publisher {{ TypeName }}Topic::PublishEx( - std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options) { - return {{ TypeName }}Publisher{ - ::nt::PublishEx(m_handle, NT_{{ cpp.TYPE_NAME }}, typeString, properties, options)}; -} - -inline {{ TypeName }}Entry {{ TypeName }}Topic::GetEntry( - {% if not TypeString %}std::string_view typeString, {% endif %}{{ cpp.ParamType }} defaultValue, - const PubSubOptions& options) { - return {{ TypeName }}Entry{ - ::nt::GetEntry(m_handle, NT_{{ cpp.TYPE_NAME }}, {{ TypeString|default('typeString') }}, options), - defaultValue}; -} -{%- if TypeString %} -inline {{ TypeName }}Entry {{ TypeName }}Topic::GetEntryEx( - std::string_view typeString, {{ cpp.ParamType }} defaultValue, - const PubSubOptions& options) { - return {{ TypeName }}Entry{ - ::nt::GetEntry(m_handle, NT_{{ cpp.TYPE_NAME }}, typeString, options), - defaultValue}; -} -{% endif %} -} // namespace nt - diff --git a/ntcore/src/generated/main/native/include/networktables/BooleanArrayTopic.h b/ntcore/src/generated/main/native/include/networktables/BooleanArrayTopic.h index de89f4b2b08..137c922c279 100644 --- a/ntcore/src/generated/main/native/include/networktables/BooleanArrayTopic.h +++ b/ntcore/src/generated/main/native/include/networktables/BooleanArrayTopic.h @@ -15,7 +15,9 @@ #include +#include "networktables/NetworkTableType.h" #include "networktables/Topic.h" +#include "ntcore_cpp.h" namespace wpi { template @@ -50,7 +52,9 @@ class BooleanArraySubscriber : public Subscriber { * @param handle Native handle * @param defaultValue Default value */ - BooleanArraySubscriber(NT_Subscriber handle, ParamType defaultValue); + BooleanArraySubscriber(NT_Subscriber handle, ParamType defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue.begin(), defaultValue.end()} {} /** * Get the last published value. @@ -58,7 +62,9 @@ class BooleanArraySubscriber : public Subscriber { * * @return value */ - ValueType Get() const; + ValueType Get() const { + return Get(m_defaultValue); + } /** * Get the last published value. @@ -67,7 +73,9 @@ class BooleanArraySubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - ValueType Get(ParamType defaultValue) const; + ValueType Get(ParamType defaultValue) const { + return ::nt::GetBooleanArray(m_subHandle, defaultValue); + } /** * Get the last published value. @@ -76,7 +84,9 @@ class BooleanArraySubscriber : public Subscriber { * @param buf storage for returned value * @return value */ - SmallRetType Get(wpi::SmallVectorImpl& buf) const; + SmallRetType Get(wpi::SmallVectorImpl& buf) const { + return Get(buf, m_defaultValue); + } /** * Get the last published value. @@ -86,7 +96,9 @@ class BooleanArraySubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const; + SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { + return nt::GetBooleanArray(m_subHandle, buf, defaultValue); + } /** * Get the last published value along with its timestamp @@ -95,7 +107,9 @@ class BooleanArraySubscriber : public Subscriber { * * @return timestamped value */ - TimestampedValueType GetAtomic() const; + TimestampedValueType GetAtomic() const { + return GetAtomic(m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -105,7 +119,9 @@ class BooleanArraySubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return timestamped value */ - TimestampedValueType GetAtomic(ParamType defaultValue) const; + TimestampedValueType GetAtomic(ParamType defaultValue) const { + return ::nt::GetAtomicBooleanArray(m_subHandle, defaultValue); + } /** * Get the last published value along with its timestamp. @@ -116,7 +132,9 @@ class BooleanArraySubscriber : public Subscriber { * @return timestamped value */ TimestampedValueViewType GetAtomic( - wpi::SmallVectorImpl& buf) const; + wpi::SmallVectorImpl& buf) const { + return GetAtomic(buf, m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -129,7 +147,9 @@ class BooleanArraySubscriber : public Subscriber { */ TimestampedValueViewType GetAtomic( wpi::SmallVectorImpl& buf, - ParamType defaultValue) const; + ParamType defaultValue) const { + return nt::GetAtomicBooleanArray(m_subHandle, buf, defaultValue); + } /** * Get an array of all value changes since the last call to ReadQueue. @@ -141,7 +161,9 @@ class BooleanArraySubscriber : public Subscriber { * @return Array of timestamped values; empty array if no new changes have * been published since the previous call. */ - std::vector ReadQueue(); + std::vector ReadQueue() { + return ::nt::ReadQueueBooleanArray(m_subHandle); + } /** * Get the corresponding topic. @@ -176,7 +198,7 @@ class BooleanArrayPublisher : public Publisher { * * @param handle Native handle */ - explicit BooleanArrayPublisher(NT_Publisher handle); + explicit BooleanArrayPublisher(NT_Publisher handle) : Publisher{handle} {} /** * Publish a new value. @@ -184,7 +206,9 @@ class BooleanArrayPublisher : public Publisher { * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(ParamType value, int64_t time = 0); + void Set(ParamType value, int64_t time = 0) { + ::nt::SetBooleanArray(m_pubHandle, value, time); + } /** * Publish a default value. @@ -193,7 +217,9 @@ class BooleanArrayPublisher : public Publisher { * * @param value value */ - void SetDefault(ParamType value); + void SetDefault(ParamType value) { + ::nt::SetDefaultBooleanArray(m_pubHandle, value); + } /** * Get the corresponding topic. @@ -231,7 +257,9 @@ class BooleanArrayEntry final : public BooleanArraySubscriber, * @param handle Native handle * @param defaultValue Default value */ - BooleanArrayEntry(NT_Entry handle, ParamType defaultValue); + BooleanArrayEntry(NT_Entry handle, ParamType defaultValue) + : BooleanArraySubscriber{handle, defaultValue}, + BooleanArrayPublisher{handle} {} /** * Determines if the native handle is valid. @@ -257,7 +285,9 @@ class BooleanArrayEntry final : public BooleanArraySubscriber, /** * Stops publishing the entry if it's published. */ - void Unpublish(); + void Unpublish() { + ::nt::Unpublish(m_pubHandle); + } }; /** @@ -309,7 +339,11 @@ class BooleanArrayTopic final : public Topic { [[nodiscard]] SubscriberType Subscribe( ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return BooleanArraySubscriber{ + ::nt::Subscribe(m_handle, NT_BOOLEAN_ARRAY, "boolean[]", options), + defaultValue}; + } /** * Create a new subscriber to the topic, with specific type string. * @@ -329,7 +363,11 @@ class BooleanArrayTopic final : public Topic { [[nodiscard]] SubscriberType SubscribeEx( std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return BooleanArraySubscriber{ + ::nt::Subscribe(m_handle, NT_BOOLEAN_ARRAY, typeString, options), + defaultValue}; + } /** * Create a new publisher to the topic. @@ -347,7 +385,10 @@ class BooleanArrayTopic final : public Topic { * @return publisher */ [[nodiscard]] - PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions) { + return BooleanArrayPublisher{ + ::nt::Publish(m_handle, NT_BOOLEAN_ARRAY, "boolean[]", options)}; + } /** * Create a new publisher to the topic, with type string and initial @@ -369,7 +410,10 @@ class BooleanArrayTopic final : public Topic { */ [[nodiscard]] PublisherType PublishEx(std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions) { + return BooleanArrayPublisher{ + ::nt::PublishEx(m_handle, NT_BOOLEAN_ARRAY, typeString, properties, options)}; + } /** * Create a new entry for the topic. @@ -393,7 +437,11 @@ class BooleanArrayTopic final : public Topic { */ [[nodiscard]] EntryType GetEntry(ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return BooleanArrayEntry{ + ::nt::GetEntry(m_handle, NT_BOOLEAN_ARRAY, "boolean[]", options), + defaultValue}; + } /** * Create a new entry for the topic, with specific type string. * @@ -417,10 +465,24 @@ class BooleanArrayTopic final : public Topic { */ [[nodiscard]] EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return BooleanArrayEntry{ + ::nt::GetEntry(m_handle, NT_BOOLEAN_ARRAY, typeString, options), + defaultValue}; + } }; -} // namespace nt +inline BooleanArrayTopic BooleanArraySubscriber::GetTopic() const { + return BooleanArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline BooleanArrayTopic BooleanArrayPublisher::GetTopic() const { + return BooleanArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} -#include "networktables/BooleanArrayTopic.inc" +inline BooleanArrayTopic BooleanArrayEntry::GetTopic() const { + return BooleanArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/BooleanArrayTopic.inc b/ntcore/src/generated/main/native/include/networktables/BooleanArrayTopic.inc deleted file mode 100644 index 53bd5e4d23c..00000000000 --- a/ntcore/src/generated/main/native/include/networktables/BooleanArrayTopic.inc +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY - -#pragma once - -#include - -#include "networktables/BooleanArrayTopic.h" -#include "networktables/NetworkTableType.h" -#include "ntcore_cpp.h" - -namespace nt { - -inline BooleanArraySubscriber::BooleanArraySubscriber( - NT_Subscriber handle, ParamType defaultValue) - : Subscriber{handle}, - m_defaultValue{defaultValue.begin(), defaultValue.end()} {} - -inline std::vector BooleanArraySubscriber::Get() const { - return Get(m_defaultValue); -} - -inline std::vector BooleanArraySubscriber::Get( - ParamType defaultValue) const { - return ::nt::GetBooleanArray(m_subHandle, defaultValue); -} - -inline std::span BooleanArraySubscriber::Get(wpi::SmallVectorImpl& buf) const { - return Get(buf, m_defaultValue); -} - -inline std::span BooleanArraySubscriber::Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { - return nt::GetBooleanArray(m_subHandle, buf, defaultValue); -} - -inline TimestampedBooleanArray BooleanArraySubscriber::GetAtomic() const { - return GetAtomic(m_defaultValue); -} - -inline TimestampedBooleanArray BooleanArraySubscriber::GetAtomic( - ParamType defaultValue) const { - return ::nt::GetAtomicBooleanArray(m_subHandle, defaultValue); -} - -inline TimestampedBooleanArrayView BooleanArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf) const { - return GetAtomic(buf, m_defaultValue); -} - -inline TimestampedBooleanArrayView BooleanArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { - return nt::GetAtomicBooleanArray(m_subHandle, buf, defaultValue); -} - -inline std::vector -BooleanArraySubscriber::ReadQueue() { - return ::nt::ReadQueueBooleanArray(m_subHandle); -} - -inline BooleanArrayTopic BooleanArraySubscriber::GetTopic() const { - return BooleanArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline BooleanArrayPublisher::BooleanArrayPublisher(NT_Publisher handle) - : Publisher{handle} {} - -inline void BooleanArrayPublisher::Set(ParamType value, - int64_t time) { - ::nt::SetBooleanArray(m_pubHandle, value, time); -} - -inline void BooleanArrayPublisher::SetDefault(ParamType value) { - ::nt::SetDefaultBooleanArray(m_pubHandle, value); -} - -inline BooleanArrayTopic BooleanArrayPublisher::GetTopic() const { - return BooleanArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)}; -} - -inline BooleanArrayEntry::BooleanArrayEntry( - NT_Entry handle, ParamType defaultValue) - : BooleanArraySubscriber{handle, defaultValue}, - BooleanArrayPublisher{handle} {} - -inline BooleanArrayTopic BooleanArrayEntry::GetTopic() const { - return BooleanArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline void BooleanArrayEntry::Unpublish() { - ::nt::Unpublish(m_pubHandle); -} - -inline BooleanArraySubscriber BooleanArrayTopic::Subscribe( - std::span defaultValue, - const PubSubOptions& options) { - return BooleanArraySubscriber{ - ::nt::Subscribe(m_handle, NT_BOOLEAN_ARRAY, "boolean[]", options), - defaultValue}; -} -inline BooleanArraySubscriber BooleanArrayTopic::SubscribeEx( - std::string_view typeString, std::span defaultValue, - const PubSubOptions& options) { - return BooleanArraySubscriber{ - ::nt::Subscribe(m_handle, NT_BOOLEAN_ARRAY, typeString, options), - defaultValue}; -} - -inline BooleanArrayPublisher BooleanArrayTopic::Publish( - const PubSubOptions& options) { - return BooleanArrayPublisher{ - ::nt::Publish(m_handle, NT_BOOLEAN_ARRAY, "boolean[]", options)}; -} - -inline BooleanArrayPublisher BooleanArrayTopic::PublishEx( - std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options) { - return BooleanArrayPublisher{ - ::nt::PublishEx(m_handle, NT_BOOLEAN_ARRAY, typeString, properties, options)}; -} - -inline BooleanArrayEntry BooleanArrayTopic::GetEntry( - std::span defaultValue, - const PubSubOptions& options) { - return BooleanArrayEntry{ - ::nt::GetEntry(m_handle, NT_BOOLEAN_ARRAY, "boolean[]", options), - defaultValue}; -} -inline BooleanArrayEntry BooleanArrayTopic::GetEntryEx( - std::string_view typeString, std::span defaultValue, - const PubSubOptions& options) { - return BooleanArrayEntry{ - ::nt::GetEntry(m_handle, NT_BOOLEAN_ARRAY, typeString, options), - defaultValue}; -} - -} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/BooleanTopic.h b/ntcore/src/generated/main/native/include/networktables/BooleanTopic.h index 22db06b9e1d..6da5b2943e4 100644 --- a/ntcore/src/generated/main/native/include/networktables/BooleanTopic.h +++ b/ntcore/src/generated/main/native/include/networktables/BooleanTopic.h @@ -15,7 +15,9 @@ #include +#include "networktables/NetworkTableType.h" #include "networktables/Topic.h" +#include "ntcore_cpp.h" namespace wpi { template @@ -46,7 +48,9 @@ class BooleanSubscriber : public Subscriber { * @param handle Native handle * @param defaultValue Default value */ - BooleanSubscriber(NT_Subscriber handle, ParamType defaultValue); + BooleanSubscriber(NT_Subscriber handle, ParamType defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue} {} /** * Get the last published value. @@ -54,7 +58,9 @@ class BooleanSubscriber : public Subscriber { * * @return value */ - ValueType Get() const; + ValueType Get() const { + return Get(m_defaultValue); + } /** * Get the last published value. @@ -63,7 +69,9 @@ class BooleanSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - ValueType Get(ParamType defaultValue) const; + ValueType Get(ParamType defaultValue) const { + return ::nt::GetBoolean(m_subHandle, defaultValue); + } /** * Get the last published value along with its timestamp @@ -72,7 +80,9 @@ class BooleanSubscriber : public Subscriber { * * @return timestamped value */ - TimestampedValueType GetAtomic() const; + TimestampedValueType GetAtomic() const { + return GetAtomic(m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -82,7 +92,9 @@ class BooleanSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return timestamped value */ - TimestampedValueType GetAtomic(ParamType defaultValue) const; + TimestampedValueType GetAtomic(ParamType defaultValue) const { + return ::nt::GetAtomicBoolean(m_subHandle, defaultValue); + } /** * Get an array of all value changes since the last call to ReadQueue. @@ -94,7 +106,9 @@ class BooleanSubscriber : public Subscriber { * @return Array of timestamped values; empty array if no new changes have * been published since the previous call. */ - std::vector ReadQueue(); + std::vector ReadQueue() { + return ::nt::ReadQueueBoolean(m_subHandle); + } /** * Get the corresponding topic. @@ -126,7 +140,7 @@ class BooleanPublisher : public Publisher { * * @param handle Native handle */ - explicit BooleanPublisher(NT_Publisher handle); + explicit BooleanPublisher(NT_Publisher handle) : Publisher{handle} {} /** * Publish a new value. @@ -134,7 +148,9 @@ class BooleanPublisher : public Publisher { * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(ParamType value, int64_t time = 0); + void Set(ParamType value, int64_t time = 0) { + ::nt::SetBoolean(m_pubHandle, value, time); + } /** * Publish a default value. @@ -143,7 +159,9 @@ class BooleanPublisher : public Publisher { * * @param value value */ - void SetDefault(ParamType value); + void SetDefault(ParamType value) { + ::nt::SetDefaultBoolean(m_pubHandle, value); + } /** * Get the corresponding topic. @@ -178,7 +196,9 @@ class BooleanEntry final : public BooleanSubscriber, * @param handle Native handle * @param defaultValue Default value */ - BooleanEntry(NT_Entry handle, ParamType defaultValue); + BooleanEntry(NT_Entry handle, ParamType defaultValue) + : BooleanSubscriber{handle, defaultValue}, + BooleanPublisher{handle} {} /** * Determines if the native handle is valid. @@ -204,7 +224,9 @@ class BooleanEntry final : public BooleanSubscriber, /** * Stops publishing the entry if it's published. */ - void Unpublish(); + void Unpublish() { + ::nt::Unpublish(m_pubHandle); + } }; /** @@ -256,7 +278,11 @@ class BooleanTopic final : public Topic { [[nodiscard]] SubscriberType Subscribe( ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return BooleanSubscriber{ + ::nt::Subscribe(m_handle, NT_BOOLEAN, "boolean", options), + defaultValue}; + } /** * Create a new subscriber to the topic, with specific type string. * @@ -276,7 +302,11 @@ class BooleanTopic final : public Topic { [[nodiscard]] SubscriberType SubscribeEx( std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return BooleanSubscriber{ + ::nt::Subscribe(m_handle, NT_BOOLEAN, typeString, options), + defaultValue}; + } /** * Create a new publisher to the topic. @@ -294,7 +324,10 @@ class BooleanTopic final : public Topic { * @return publisher */ [[nodiscard]] - PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions) { + return BooleanPublisher{ + ::nt::Publish(m_handle, NT_BOOLEAN, "boolean", options)}; + } /** * Create a new publisher to the topic, with type string and initial @@ -316,7 +349,10 @@ class BooleanTopic final : public Topic { */ [[nodiscard]] PublisherType PublishEx(std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions) { + return BooleanPublisher{ + ::nt::PublishEx(m_handle, NT_BOOLEAN, typeString, properties, options)}; + } /** * Create a new entry for the topic. @@ -340,7 +376,11 @@ class BooleanTopic final : public Topic { */ [[nodiscard]] EntryType GetEntry(ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return BooleanEntry{ + ::nt::GetEntry(m_handle, NT_BOOLEAN, "boolean", options), + defaultValue}; + } /** * Create a new entry for the topic, with specific type string. * @@ -364,10 +404,24 @@ class BooleanTopic final : public Topic { */ [[nodiscard]] EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return BooleanEntry{ + ::nt::GetEntry(m_handle, NT_BOOLEAN, typeString, options), + defaultValue}; + } }; -} // namespace nt +inline BooleanTopic BooleanSubscriber::GetTopic() const { + return BooleanTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline BooleanTopic BooleanPublisher::GetTopic() const { + return BooleanTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} -#include "networktables/BooleanTopic.inc" +inline BooleanTopic BooleanEntry::GetTopic() const { + return BooleanTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/BooleanTopic.inc b/ntcore/src/generated/main/native/include/networktables/BooleanTopic.inc deleted file mode 100644 index 5b7d0999571..00000000000 --- a/ntcore/src/generated/main/native/include/networktables/BooleanTopic.inc +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY - -#pragma once - -#include - -#include "networktables/BooleanTopic.h" -#include "networktables/NetworkTableType.h" -#include "ntcore_cpp.h" - -namespace nt { - -inline BooleanSubscriber::BooleanSubscriber( - NT_Subscriber handle, ParamType defaultValue) - : Subscriber{handle}, - m_defaultValue{defaultValue} {} - -inline bool BooleanSubscriber::Get() const { - return Get(m_defaultValue); -} - -inline bool BooleanSubscriber::Get( - ParamType defaultValue) const { - return ::nt::GetBoolean(m_subHandle, defaultValue); -} - -inline TimestampedBoolean BooleanSubscriber::GetAtomic() const { - return GetAtomic(m_defaultValue); -} - -inline TimestampedBoolean BooleanSubscriber::GetAtomic( - ParamType defaultValue) const { - return ::nt::GetAtomicBoolean(m_subHandle, defaultValue); -} - -inline std::vector -BooleanSubscriber::ReadQueue() { - return ::nt::ReadQueueBoolean(m_subHandle); -} - -inline BooleanTopic BooleanSubscriber::GetTopic() const { - return BooleanTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline BooleanPublisher::BooleanPublisher(NT_Publisher handle) - : Publisher{handle} {} - -inline void BooleanPublisher::Set(ParamType value, - int64_t time) { - ::nt::SetBoolean(m_pubHandle, value, time); -} - -inline void BooleanPublisher::SetDefault(ParamType value) { - ::nt::SetDefaultBoolean(m_pubHandle, value); -} - -inline BooleanTopic BooleanPublisher::GetTopic() const { - return BooleanTopic{::nt::GetTopicFromHandle(m_pubHandle)}; -} - -inline BooleanEntry::BooleanEntry( - NT_Entry handle, ParamType defaultValue) - : BooleanSubscriber{handle, defaultValue}, - BooleanPublisher{handle} {} - -inline BooleanTopic BooleanEntry::GetTopic() const { - return BooleanTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline void BooleanEntry::Unpublish() { - ::nt::Unpublish(m_pubHandle); -} - -inline BooleanSubscriber BooleanTopic::Subscribe( - bool defaultValue, - const PubSubOptions& options) { - return BooleanSubscriber{ - ::nt::Subscribe(m_handle, NT_BOOLEAN, "boolean", options), - defaultValue}; -} -inline BooleanSubscriber BooleanTopic::SubscribeEx( - std::string_view typeString, bool defaultValue, - const PubSubOptions& options) { - return BooleanSubscriber{ - ::nt::Subscribe(m_handle, NT_BOOLEAN, typeString, options), - defaultValue}; -} - -inline BooleanPublisher BooleanTopic::Publish( - const PubSubOptions& options) { - return BooleanPublisher{ - ::nt::Publish(m_handle, NT_BOOLEAN, "boolean", options)}; -} - -inline BooleanPublisher BooleanTopic::PublishEx( - std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options) { - return BooleanPublisher{ - ::nt::PublishEx(m_handle, NT_BOOLEAN, typeString, properties, options)}; -} - -inline BooleanEntry BooleanTopic::GetEntry( - bool defaultValue, - const PubSubOptions& options) { - return BooleanEntry{ - ::nt::GetEntry(m_handle, NT_BOOLEAN, "boolean", options), - defaultValue}; -} -inline BooleanEntry BooleanTopic::GetEntryEx( - std::string_view typeString, bool defaultValue, - const PubSubOptions& options) { - return BooleanEntry{ - ::nt::GetEntry(m_handle, NT_BOOLEAN, typeString, options), - defaultValue}; -} - -} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/DoubleArrayTopic.h b/ntcore/src/generated/main/native/include/networktables/DoubleArrayTopic.h index 6f64d367f2c..79aba1ddbac 100644 --- a/ntcore/src/generated/main/native/include/networktables/DoubleArrayTopic.h +++ b/ntcore/src/generated/main/native/include/networktables/DoubleArrayTopic.h @@ -15,7 +15,9 @@ #include +#include "networktables/NetworkTableType.h" #include "networktables/Topic.h" +#include "ntcore_cpp.h" namespace wpi { template @@ -50,7 +52,9 @@ class DoubleArraySubscriber : public Subscriber { * @param handle Native handle * @param defaultValue Default value */ - DoubleArraySubscriber(NT_Subscriber handle, ParamType defaultValue); + DoubleArraySubscriber(NT_Subscriber handle, ParamType defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue.begin(), defaultValue.end()} {} /** * Get the last published value. @@ -58,7 +62,9 @@ class DoubleArraySubscriber : public Subscriber { * * @return value */ - ValueType Get() const; + ValueType Get() const { + return Get(m_defaultValue); + } /** * Get the last published value. @@ -67,7 +73,9 @@ class DoubleArraySubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - ValueType Get(ParamType defaultValue) const; + ValueType Get(ParamType defaultValue) const { + return ::nt::GetDoubleArray(m_subHandle, defaultValue); + } /** * Get the last published value. @@ -76,7 +84,9 @@ class DoubleArraySubscriber : public Subscriber { * @param buf storage for returned value * @return value */ - SmallRetType Get(wpi::SmallVectorImpl& buf) const; + SmallRetType Get(wpi::SmallVectorImpl& buf) const { + return Get(buf, m_defaultValue); + } /** * Get the last published value. @@ -86,7 +96,9 @@ class DoubleArraySubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const; + SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { + return nt::GetDoubleArray(m_subHandle, buf, defaultValue); + } /** * Get the last published value along with its timestamp @@ -95,7 +107,9 @@ class DoubleArraySubscriber : public Subscriber { * * @return timestamped value */ - TimestampedValueType GetAtomic() const; + TimestampedValueType GetAtomic() const { + return GetAtomic(m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -105,7 +119,9 @@ class DoubleArraySubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return timestamped value */ - TimestampedValueType GetAtomic(ParamType defaultValue) const; + TimestampedValueType GetAtomic(ParamType defaultValue) const { + return ::nt::GetAtomicDoubleArray(m_subHandle, defaultValue); + } /** * Get the last published value along with its timestamp. @@ -116,7 +132,9 @@ class DoubleArraySubscriber : public Subscriber { * @return timestamped value */ TimestampedValueViewType GetAtomic( - wpi::SmallVectorImpl& buf) const; + wpi::SmallVectorImpl& buf) const { + return GetAtomic(buf, m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -129,7 +147,9 @@ class DoubleArraySubscriber : public Subscriber { */ TimestampedValueViewType GetAtomic( wpi::SmallVectorImpl& buf, - ParamType defaultValue) const; + ParamType defaultValue) const { + return nt::GetAtomicDoubleArray(m_subHandle, buf, defaultValue); + } /** * Get an array of all value changes since the last call to ReadQueue. @@ -141,7 +161,9 @@ class DoubleArraySubscriber : public Subscriber { * @return Array of timestamped values; empty array if no new changes have * been published since the previous call. */ - std::vector ReadQueue(); + std::vector ReadQueue() { + return ::nt::ReadQueueDoubleArray(m_subHandle); + } /** * Get the corresponding topic. @@ -176,7 +198,7 @@ class DoubleArrayPublisher : public Publisher { * * @param handle Native handle */ - explicit DoubleArrayPublisher(NT_Publisher handle); + explicit DoubleArrayPublisher(NT_Publisher handle) : Publisher{handle} {} /** * Publish a new value. @@ -184,7 +206,9 @@ class DoubleArrayPublisher : public Publisher { * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(ParamType value, int64_t time = 0); + void Set(ParamType value, int64_t time = 0) { + ::nt::SetDoubleArray(m_pubHandle, value, time); + } /** * Publish a default value. @@ -193,7 +217,9 @@ class DoubleArrayPublisher : public Publisher { * * @param value value */ - void SetDefault(ParamType value); + void SetDefault(ParamType value) { + ::nt::SetDefaultDoubleArray(m_pubHandle, value); + } /** * Get the corresponding topic. @@ -231,7 +257,9 @@ class DoubleArrayEntry final : public DoubleArraySubscriber, * @param handle Native handle * @param defaultValue Default value */ - DoubleArrayEntry(NT_Entry handle, ParamType defaultValue); + DoubleArrayEntry(NT_Entry handle, ParamType defaultValue) + : DoubleArraySubscriber{handle, defaultValue}, + DoubleArrayPublisher{handle} {} /** * Determines if the native handle is valid. @@ -257,7 +285,9 @@ class DoubleArrayEntry final : public DoubleArraySubscriber, /** * Stops publishing the entry if it's published. */ - void Unpublish(); + void Unpublish() { + ::nt::Unpublish(m_pubHandle); + } }; /** @@ -309,7 +339,11 @@ class DoubleArrayTopic final : public Topic { [[nodiscard]] SubscriberType Subscribe( ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return DoubleArraySubscriber{ + ::nt::Subscribe(m_handle, NT_DOUBLE_ARRAY, "double[]", options), + defaultValue}; + } /** * Create a new subscriber to the topic, with specific type string. * @@ -329,7 +363,11 @@ class DoubleArrayTopic final : public Topic { [[nodiscard]] SubscriberType SubscribeEx( std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return DoubleArraySubscriber{ + ::nt::Subscribe(m_handle, NT_DOUBLE_ARRAY, typeString, options), + defaultValue}; + } /** * Create a new publisher to the topic. @@ -347,7 +385,10 @@ class DoubleArrayTopic final : public Topic { * @return publisher */ [[nodiscard]] - PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions) { + return DoubleArrayPublisher{ + ::nt::Publish(m_handle, NT_DOUBLE_ARRAY, "double[]", options)}; + } /** * Create a new publisher to the topic, with type string and initial @@ -369,7 +410,10 @@ class DoubleArrayTopic final : public Topic { */ [[nodiscard]] PublisherType PublishEx(std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions) { + return DoubleArrayPublisher{ + ::nt::PublishEx(m_handle, NT_DOUBLE_ARRAY, typeString, properties, options)}; + } /** * Create a new entry for the topic. @@ -393,7 +437,11 @@ class DoubleArrayTopic final : public Topic { */ [[nodiscard]] EntryType GetEntry(ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return DoubleArrayEntry{ + ::nt::GetEntry(m_handle, NT_DOUBLE_ARRAY, "double[]", options), + defaultValue}; + } /** * Create a new entry for the topic, with specific type string. * @@ -417,10 +465,24 @@ class DoubleArrayTopic final : public Topic { */ [[nodiscard]] EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return DoubleArrayEntry{ + ::nt::GetEntry(m_handle, NT_DOUBLE_ARRAY, typeString, options), + defaultValue}; + } }; -} // namespace nt +inline DoubleArrayTopic DoubleArraySubscriber::GetTopic() const { + return DoubleArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline DoubleArrayTopic DoubleArrayPublisher::GetTopic() const { + return DoubleArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} -#include "networktables/DoubleArrayTopic.inc" +inline DoubleArrayTopic DoubleArrayEntry::GetTopic() const { + return DoubleArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/DoubleArrayTopic.inc b/ntcore/src/generated/main/native/include/networktables/DoubleArrayTopic.inc deleted file mode 100644 index f6cb74219a3..00000000000 --- a/ntcore/src/generated/main/native/include/networktables/DoubleArrayTopic.inc +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY - -#pragma once - -#include - -#include "networktables/DoubleArrayTopic.h" -#include "networktables/NetworkTableType.h" -#include "ntcore_cpp.h" - -namespace nt { - -inline DoubleArraySubscriber::DoubleArraySubscriber( - NT_Subscriber handle, ParamType defaultValue) - : Subscriber{handle}, - m_defaultValue{defaultValue.begin(), defaultValue.end()} {} - -inline std::vector DoubleArraySubscriber::Get() const { - return Get(m_defaultValue); -} - -inline std::vector DoubleArraySubscriber::Get( - ParamType defaultValue) const { - return ::nt::GetDoubleArray(m_subHandle, defaultValue); -} - -inline std::span DoubleArraySubscriber::Get(wpi::SmallVectorImpl& buf) const { - return Get(buf, m_defaultValue); -} - -inline std::span DoubleArraySubscriber::Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { - return nt::GetDoubleArray(m_subHandle, buf, defaultValue); -} - -inline TimestampedDoubleArray DoubleArraySubscriber::GetAtomic() const { - return GetAtomic(m_defaultValue); -} - -inline TimestampedDoubleArray DoubleArraySubscriber::GetAtomic( - ParamType defaultValue) const { - return ::nt::GetAtomicDoubleArray(m_subHandle, defaultValue); -} - -inline TimestampedDoubleArrayView DoubleArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf) const { - return GetAtomic(buf, m_defaultValue); -} - -inline TimestampedDoubleArrayView DoubleArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { - return nt::GetAtomicDoubleArray(m_subHandle, buf, defaultValue); -} - -inline std::vector -DoubleArraySubscriber::ReadQueue() { - return ::nt::ReadQueueDoubleArray(m_subHandle); -} - -inline DoubleArrayTopic DoubleArraySubscriber::GetTopic() const { - return DoubleArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline DoubleArrayPublisher::DoubleArrayPublisher(NT_Publisher handle) - : Publisher{handle} {} - -inline void DoubleArrayPublisher::Set(ParamType value, - int64_t time) { - ::nt::SetDoubleArray(m_pubHandle, value, time); -} - -inline void DoubleArrayPublisher::SetDefault(ParamType value) { - ::nt::SetDefaultDoubleArray(m_pubHandle, value); -} - -inline DoubleArrayTopic DoubleArrayPublisher::GetTopic() const { - return DoubleArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)}; -} - -inline DoubleArrayEntry::DoubleArrayEntry( - NT_Entry handle, ParamType defaultValue) - : DoubleArraySubscriber{handle, defaultValue}, - DoubleArrayPublisher{handle} {} - -inline DoubleArrayTopic DoubleArrayEntry::GetTopic() const { - return DoubleArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline void DoubleArrayEntry::Unpublish() { - ::nt::Unpublish(m_pubHandle); -} - -inline DoubleArraySubscriber DoubleArrayTopic::Subscribe( - std::span defaultValue, - const PubSubOptions& options) { - return DoubleArraySubscriber{ - ::nt::Subscribe(m_handle, NT_DOUBLE_ARRAY, "double[]", options), - defaultValue}; -} -inline DoubleArraySubscriber DoubleArrayTopic::SubscribeEx( - std::string_view typeString, std::span defaultValue, - const PubSubOptions& options) { - return DoubleArraySubscriber{ - ::nt::Subscribe(m_handle, NT_DOUBLE_ARRAY, typeString, options), - defaultValue}; -} - -inline DoubleArrayPublisher DoubleArrayTopic::Publish( - const PubSubOptions& options) { - return DoubleArrayPublisher{ - ::nt::Publish(m_handle, NT_DOUBLE_ARRAY, "double[]", options)}; -} - -inline DoubleArrayPublisher DoubleArrayTopic::PublishEx( - std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options) { - return DoubleArrayPublisher{ - ::nt::PublishEx(m_handle, NT_DOUBLE_ARRAY, typeString, properties, options)}; -} - -inline DoubleArrayEntry DoubleArrayTopic::GetEntry( - std::span defaultValue, - const PubSubOptions& options) { - return DoubleArrayEntry{ - ::nt::GetEntry(m_handle, NT_DOUBLE_ARRAY, "double[]", options), - defaultValue}; -} -inline DoubleArrayEntry DoubleArrayTopic::GetEntryEx( - std::string_view typeString, std::span defaultValue, - const PubSubOptions& options) { - return DoubleArrayEntry{ - ::nt::GetEntry(m_handle, NT_DOUBLE_ARRAY, typeString, options), - defaultValue}; -} - -} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/DoubleTopic.h b/ntcore/src/generated/main/native/include/networktables/DoubleTopic.h index bcb1751b404..5601354a2bc 100644 --- a/ntcore/src/generated/main/native/include/networktables/DoubleTopic.h +++ b/ntcore/src/generated/main/native/include/networktables/DoubleTopic.h @@ -15,7 +15,9 @@ #include +#include "networktables/NetworkTableType.h" #include "networktables/Topic.h" +#include "ntcore_cpp.h" namespace wpi { template @@ -46,7 +48,9 @@ class DoubleSubscriber : public Subscriber { * @param handle Native handle * @param defaultValue Default value */ - DoubleSubscriber(NT_Subscriber handle, ParamType defaultValue); + DoubleSubscriber(NT_Subscriber handle, ParamType defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue} {} /** * Get the last published value. @@ -54,7 +58,9 @@ class DoubleSubscriber : public Subscriber { * * @return value */ - ValueType Get() const; + ValueType Get() const { + return Get(m_defaultValue); + } /** * Get the last published value. @@ -63,7 +69,9 @@ class DoubleSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - ValueType Get(ParamType defaultValue) const; + ValueType Get(ParamType defaultValue) const { + return ::nt::GetDouble(m_subHandle, defaultValue); + } /** * Get the last published value along with its timestamp @@ -72,7 +80,9 @@ class DoubleSubscriber : public Subscriber { * * @return timestamped value */ - TimestampedValueType GetAtomic() const; + TimestampedValueType GetAtomic() const { + return GetAtomic(m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -82,7 +92,9 @@ class DoubleSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return timestamped value */ - TimestampedValueType GetAtomic(ParamType defaultValue) const; + TimestampedValueType GetAtomic(ParamType defaultValue) const { + return ::nt::GetAtomicDouble(m_subHandle, defaultValue); + } /** * Get an array of all value changes since the last call to ReadQueue. @@ -94,7 +106,9 @@ class DoubleSubscriber : public Subscriber { * @return Array of timestamped values; empty array if no new changes have * been published since the previous call. */ - std::vector ReadQueue(); + std::vector ReadQueue() { + return ::nt::ReadQueueDouble(m_subHandle); + } /** * Get the corresponding topic. @@ -126,7 +140,7 @@ class DoublePublisher : public Publisher { * * @param handle Native handle */ - explicit DoublePublisher(NT_Publisher handle); + explicit DoublePublisher(NT_Publisher handle) : Publisher{handle} {} /** * Publish a new value. @@ -134,7 +148,9 @@ class DoublePublisher : public Publisher { * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(ParamType value, int64_t time = 0); + void Set(ParamType value, int64_t time = 0) { + ::nt::SetDouble(m_pubHandle, value, time); + } /** * Publish a default value. @@ -143,7 +159,9 @@ class DoublePublisher : public Publisher { * * @param value value */ - void SetDefault(ParamType value); + void SetDefault(ParamType value) { + ::nt::SetDefaultDouble(m_pubHandle, value); + } /** * Get the corresponding topic. @@ -178,7 +196,9 @@ class DoubleEntry final : public DoubleSubscriber, * @param handle Native handle * @param defaultValue Default value */ - DoubleEntry(NT_Entry handle, ParamType defaultValue); + DoubleEntry(NT_Entry handle, ParamType defaultValue) + : DoubleSubscriber{handle, defaultValue}, + DoublePublisher{handle} {} /** * Determines if the native handle is valid. @@ -204,7 +224,9 @@ class DoubleEntry final : public DoubleSubscriber, /** * Stops publishing the entry if it's published. */ - void Unpublish(); + void Unpublish() { + ::nt::Unpublish(m_pubHandle); + } }; /** @@ -256,7 +278,11 @@ class DoubleTopic final : public Topic { [[nodiscard]] SubscriberType Subscribe( ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return DoubleSubscriber{ + ::nt::Subscribe(m_handle, NT_DOUBLE, "double", options), + defaultValue}; + } /** * Create a new subscriber to the topic, with specific type string. * @@ -276,7 +302,11 @@ class DoubleTopic final : public Topic { [[nodiscard]] SubscriberType SubscribeEx( std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return DoubleSubscriber{ + ::nt::Subscribe(m_handle, NT_DOUBLE, typeString, options), + defaultValue}; + } /** * Create a new publisher to the topic. @@ -294,7 +324,10 @@ class DoubleTopic final : public Topic { * @return publisher */ [[nodiscard]] - PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions) { + return DoublePublisher{ + ::nt::Publish(m_handle, NT_DOUBLE, "double", options)}; + } /** * Create a new publisher to the topic, with type string and initial @@ -316,7 +349,10 @@ class DoubleTopic final : public Topic { */ [[nodiscard]] PublisherType PublishEx(std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions) { + return DoublePublisher{ + ::nt::PublishEx(m_handle, NT_DOUBLE, typeString, properties, options)}; + } /** * Create a new entry for the topic. @@ -340,7 +376,11 @@ class DoubleTopic final : public Topic { */ [[nodiscard]] EntryType GetEntry(ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return DoubleEntry{ + ::nt::GetEntry(m_handle, NT_DOUBLE, "double", options), + defaultValue}; + } /** * Create a new entry for the topic, with specific type string. * @@ -364,10 +404,24 @@ class DoubleTopic final : public Topic { */ [[nodiscard]] EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return DoubleEntry{ + ::nt::GetEntry(m_handle, NT_DOUBLE, typeString, options), + defaultValue}; + } }; -} // namespace nt +inline DoubleTopic DoubleSubscriber::GetTopic() const { + return DoubleTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline DoubleTopic DoublePublisher::GetTopic() const { + return DoubleTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} -#include "networktables/DoubleTopic.inc" +inline DoubleTopic DoubleEntry::GetTopic() const { + return DoubleTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/DoubleTopic.inc b/ntcore/src/generated/main/native/include/networktables/DoubleTopic.inc deleted file mode 100644 index 1ca4ec4b93b..00000000000 --- a/ntcore/src/generated/main/native/include/networktables/DoubleTopic.inc +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY - -#pragma once - -#include - -#include "networktables/DoubleTopic.h" -#include "networktables/NetworkTableType.h" -#include "ntcore_cpp.h" - -namespace nt { - -inline DoubleSubscriber::DoubleSubscriber( - NT_Subscriber handle, ParamType defaultValue) - : Subscriber{handle}, - m_defaultValue{defaultValue} {} - -inline double DoubleSubscriber::Get() const { - return Get(m_defaultValue); -} - -inline double DoubleSubscriber::Get( - ParamType defaultValue) const { - return ::nt::GetDouble(m_subHandle, defaultValue); -} - -inline TimestampedDouble DoubleSubscriber::GetAtomic() const { - return GetAtomic(m_defaultValue); -} - -inline TimestampedDouble DoubleSubscriber::GetAtomic( - ParamType defaultValue) const { - return ::nt::GetAtomicDouble(m_subHandle, defaultValue); -} - -inline std::vector -DoubleSubscriber::ReadQueue() { - return ::nt::ReadQueueDouble(m_subHandle); -} - -inline DoubleTopic DoubleSubscriber::GetTopic() const { - return DoubleTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline DoublePublisher::DoublePublisher(NT_Publisher handle) - : Publisher{handle} {} - -inline void DoublePublisher::Set(ParamType value, - int64_t time) { - ::nt::SetDouble(m_pubHandle, value, time); -} - -inline void DoublePublisher::SetDefault(ParamType value) { - ::nt::SetDefaultDouble(m_pubHandle, value); -} - -inline DoubleTopic DoublePublisher::GetTopic() const { - return DoubleTopic{::nt::GetTopicFromHandle(m_pubHandle)}; -} - -inline DoubleEntry::DoubleEntry( - NT_Entry handle, ParamType defaultValue) - : DoubleSubscriber{handle, defaultValue}, - DoublePublisher{handle} {} - -inline DoubleTopic DoubleEntry::GetTopic() const { - return DoubleTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline void DoubleEntry::Unpublish() { - ::nt::Unpublish(m_pubHandle); -} - -inline DoubleSubscriber DoubleTopic::Subscribe( - double defaultValue, - const PubSubOptions& options) { - return DoubleSubscriber{ - ::nt::Subscribe(m_handle, NT_DOUBLE, "double", options), - defaultValue}; -} -inline DoubleSubscriber DoubleTopic::SubscribeEx( - std::string_view typeString, double defaultValue, - const PubSubOptions& options) { - return DoubleSubscriber{ - ::nt::Subscribe(m_handle, NT_DOUBLE, typeString, options), - defaultValue}; -} - -inline DoublePublisher DoubleTopic::Publish( - const PubSubOptions& options) { - return DoublePublisher{ - ::nt::Publish(m_handle, NT_DOUBLE, "double", options)}; -} - -inline DoublePublisher DoubleTopic::PublishEx( - std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options) { - return DoublePublisher{ - ::nt::PublishEx(m_handle, NT_DOUBLE, typeString, properties, options)}; -} - -inline DoubleEntry DoubleTopic::GetEntry( - double defaultValue, - const PubSubOptions& options) { - return DoubleEntry{ - ::nt::GetEntry(m_handle, NT_DOUBLE, "double", options), - defaultValue}; -} -inline DoubleEntry DoubleTopic::GetEntryEx( - std::string_view typeString, double defaultValue, - const PubSubOptions& options) { - return DoubleEntry{ - ::nt::GetEntry(m_handle, NT_DOUBLE, typeString, options), - defaultValue}; -} - -} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/FloatArrayTopic.h b/ntcore/src/generated/main/native/include/networktables/FloatArrayTopic.h index a0d2b66b33e..c54425250d1 100644 --- a/ntcore/src/generated/main/native/include/networktables/FloatArrayTopic.h +++ b/ntcore/src/generated/main/native/include/networktables/FloatArrayTopic.h @@ -15,7 +15,9 @@ #include +#include "networktables/NetworkTableType.h" #include "networktables/Topic.h" +#include "ntcore_cpp.h" namespace wpi { template @@ -50,7 +52,9 @@ class FloatArraySubscriber : public Subscriber { * @param handle Native handle * @param defaultValue Default value */ - FloatArraySubscriber(NT_Subscriber handle, ParamType defaultValue); + FloatArraySubscriber(NT_Subscriber handle, ParamType defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue.begin(), defaultValue.end()} {} /** * Get the last published value. @@ -58,7 +62,9 @@ class FloatArraySubscriber : public Subscriber { * * @return value */ - ValueType Get() const; + ValueType Get() const { + return Get(m_defaultValue); + } /** * Get the last published value. @@ -67,7 +73,9 @@ class FloatArraySubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - ValueType Get(ParamType defaultValue) const; + ValueType Get(ParamType defaultValue) const { + return ::nt::GetFloatArray(m_subHandle, defaultValue); + } /** * Get the last published value. @@ -76,7 +84,9 @@ class FloatArraySubscriber : public Subscriber { * @param buf storage for returned value * @return value */ - SmallRetType Get(wpi::SmallVectorImpl& buf) const; + SmallRetType Get(wpi::SmallVectorImpl& buf) const { + return Get(buf, m_defaultValue); + } /** * Get the last published value. @@ -86,7 +96,9 @@ class FloatArraySubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const; + SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { + return nt::GetFloatArray(m_subHandle, buf, defaultValue); + } /** * Get the last published value along with its timestamp @@ -95,7 +107,9 @@ class FloatArraySubscriber : public Subscriber { * * @return timestamped value */ - TimestampedValueType GetAtomic() const; + TimestampedValueType GetAtomic() const { + return GetAtomic(m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -105,7 +119,9 @@ class FloatArraySubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return timestamped value */ - TimestampedValueType GetAtomic(ParamType defaultValue) const; + TimestampedValueType GetAtomic(ParamType defaultValue) const { + return ::nt::GetAtomicFloatArray(m_subHandle, defaultValue); + } /** * Get the last published value along with its timestamp. @@ -116,7 +132,9 @@ class FloatArraySubscriber : public Subscriber { * @return timestamped value */ TimestampedValueViewType GetAtomic( - wpi::SmallVectorImpl& buf) const; + wpi::SmallVectorImpl& buf) const { + return GetAtomic(buf, m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -129,7 +147,9 @@ class FloatArraySubscriber : public Subscriber { */ TimestampedValueViewType GetAtomic( wpi::SmallVectorImpl& buf, - ParamType defaultValue) const; + ParamType defaultValue) const { + return nt::GetAtomicFloatArray(m_subHandle, buf, defaultValue); + } /** * Get an array of all value changes since the last call to ReadQueue. @@ -141,7 +161,9 @@ class FloatArraySubscriber : public Subscriber { * @return Array of timestamped values; empty array if no new changes have * been published since the previous call. */ - std::vector ReadQueue(); + std::vector ReadQueue() { + return ::nt::ReadQueueFloatArray(m_subHandle); + } /** * Get the corresponding topic. @@ -176,7 +198,7 @@ class FloatArrayPublisher : public Publisher { * * @param handle Native handle */ - explicit FloatArrayPublisher(NT_Publisher handle); + explicit FloatArrayPublisher(NT_Publisher handle) : Publisher{handle} {} /** * Publish a new value. @@ -184,7 +206,9 @@ class FloatArrayPublisher : public Publisher { * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(ParamType value, int64_t time = 0); + void Set(ParamType value, int64_t time = 0) { + ::nt::SetFloatArray(m_pubHandle, value, time); + } /** * Publish a default value. @@ -193,7 +217,9 @@ class FloatArrayPublisher : public Publisher { * * @param value value */ - void SetDefault(ParamType value); + void SetDefault(ParamType value) { + ::nt::SetDefaultFloatArray(m_pubHandle, value); + } /** * Get the corresponding topic. @@ -231,7 +257,9 @@ class FloatArrayEntry final : public FloatArraySubscriber, * @param handle Native handle * @param defaultValue Default value */ - FloatArrayEntry(NT_Entry handle, ParamType defaultValue); + FloatArrayEntry(NT_Entry handle, ParamType defaultValue) + : FloatArraySubscriber{handle, defaultValue}, + FloatArrayPublisher{handle} {} /** * Determines if the native handle is valid. @@ -257,7 +285,9 @@ class FloatArrayEntry final : public FloatArraySubscriber, /** * Stops publishing the entry if it's published. */ - void Unpublish(); + void Unpublish() { + ::nt::Unpublish(m_pubHandle); + } }; /** @@ -309,7 +339,11 @@ class FloatArrayTopic final : public Topic { [[nodiscard]] SubscriberType Subscribe( ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return FloatArraySubscriber{ + ::nt::Subscribe(m_handle, NT_FLOAT_ARRAY, "float[]", options), + defaultValue}; + } /** * Create a new subscriber to the topic, with specific type string. * @@ -329,7 +363,11 @@ class FloatArrayTopic final : public Topic { [[nodiscard]] SubscriberType SubscribeEx( std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return FloatArraySubscriber{ + ::nt::Subscribe(m_handle, NT_FLOAT_ARRAY, typeString, options), + defaultValue}; + } /** * Create a new publisher to the topic. @@ -347,7 +385,10 @@ class FloatArrayTopic final : public Topic { * @return publisher */ [[nodiscard]] - PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions) { + return FloatArrayPublisher{ + ::nt::Publish(m_handle, NT_FLOAT_ARRAY, "float[]", options)}; + } /** * Create a new publisher to the topic, with type string and initial @@ -369,7 +410,10 @@ class FloatArrayTopic final : public Topic { */ [[nodiscard]] PublisherType PublishEx(std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions) { + return FloatArrayPublisher{ + ::nt::PublishEx(m_handle, NT_FLOAT_ARRAY, typeString, properties, options)}; + } /** * Create a new entry for the topic. @@ -393,7 +437,11 @@ class FloatArrayTopic final : public Topic { */ [[nodiscard]] EntryType GetEntry(ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return FloatArrayEntry{ + ::nt::GetEntry(m_handle, NT_FLOAT_ARRAY, "float[]", options), + defaultValue}; + } /** * Create a new entry for the topic, with specific type string. * @@ -417,10 +465,24 @@ class FloatArrayTopic final : public Topic { */ [[nodiscard]] EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return FloatArrayEntry{ + ::nt::GetEntry(m_handle, NT_FLOAT_ARRAY, typeString, options), + defaultValue}; + } }; -} // namespace nt +inline FloatArrayTopic FloatArraySubscriber::GetTopic() const { + return FloatArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline FloatArrayTopic FloatArrayPublisher::GetTopic() const { + return FloatArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} -#include "networktables/FloatArrayTopic.inc" +inline FloatArrayTopic FloatArrayEntry::GetTopic() const { + return FloatArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/FloatArrayTopic.inc b/ntcore/src/generated/main/native/include/networktables/FloatArrayTopic.inc deleted file mode 100644 index 3eeb112d6da..00000000000 --- a/ntcore/src/generated/main/native/include/networktables/FloatArrayTopic.inc +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY - -#pragma once - -#include - -#include "networktables/FloatArrayTopic.h" -#include "networktables/NetworkTableType.h" -#include "ntcore_cpp.h" - -namespace nt { - -inline FloatArraySubscriber::FloatArraySubscriber( - NT_Subscriber handle, ParamType defaultValue) - : Subscriber{handle}, - m_defaultValue{defaultValue.begin(), defaultValue.end()} {} - -inline std::vector FloatArraySubscriber::Get() const { - return Get(m_defaultValue); -} - -inline std::vector FloatArraySubscriber::Get( - ParamType defaultValue) const { - return ::nt::GetFloatArray(m_subHandle, defaultValue); -} - -inline std::span FloatArraySubscriber::Get(wpi::SmallVectorImpl& buf) const { - return Get(buf, m_defaultValue); -} - -inline std::span FloatArraySubscriber::Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { - return nt::GetFloatArray(m_subHandle, buf, defaultValue); -} - -inline TimestampedFloatArray FloatArraySubscriber::GetAtomic() const { - return GetAtomic(m_defaultValue); -} - -inline TimestampedFloatArray FloatArraySubscriber::GetAtomic( - ParamType defaultValue) const { - return ::nt::GetAtomicFloatArray(m_subHandle, defaultValue); -} - -inline TimestampedFloatArrayView FloatArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf) const { - return GetAtomic(buf, m_defaultValue); -} - -inline TimestampedFloatArrayView FloatArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { - return nt::GetAtomicFloatArray(m_subHandle, buf, defaultValue); -} - -inline std::vector -FloatArraySubscriber::ReadQueue() { - return ::nt::ReadQueueFloatArray(m_subHandle); -} - -inline FloatArrayTopic FloatArraySubscriber::GetTopic() const { - return FloatArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline FloatArrayPublisher::FloatArrayPublisher(NT_Publisher handle) - : Publisher{handle} {} - -inline void FloatArrayPublisher::Set(ParamType value, - int64_t time) { - ::nt::SetFloatArray(m_pubHandle, value, time); -} - -inline void FloatArrayPublisher::SetDefault(ParamType value) { - ::nt::SetDefaultFloatArray(m_pubHandle, value); -} - -inline FloatArrayTopic FloatArrayPublisher::GetTopic() const { - return FloatArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)}; -} - -inline FloatArrayEntry::FloatArrayEntry( - NT_Entry handle, ParamType defaultValue) - : FloatArraySubscriber{handle, defaultValue}, - FloatArrayPublisher{handle} {} - -inline FloatArrayTopic FloatArrayEntry::GetTopic() const { - return FloatArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline void FloatArrayEntry::Unpublish() { - ::nt::Unpublish(m_pubHandle); -} - -inline FloatArraySubscriber FloatArrayTopic::Subscribe( - std::span defaultValue, - const PubSubOptions& options) { - return FloatArraySubscriber{ - ::nt::Subscribe(m_handle, NT_FLOAT_ARRAY, "float[]", options), - defaultValue}; -} -inline FloatArraySubscriber FloatArrayTopic::SubscribeEx( - std::string_view typeString, std::span defaultValue, - const PubSubOptions& options) { - return FloatArraySubscriber{ - ::nt::Subscribe(m_handle, NT_FLOAT_ARRAY, typeString, options), - defaultValue}; -} - -inline FloatArrayPublisher FloatArrayTopic::Publish( - const PubSubOptions& options) { - return FloatArrayPublisher{ - ::nt::Publish(m_handle, NT_FLOAT_ARRAY, "float[]", options)}; -} - -inline FloatArrayPublisher FloatArrayTopic::PublishEx( - std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options) { - return FloatArrayPublisher{ - ::nt::PublishEx(m_handle, NT_FLOAT_ARRAY, typeString, properties, options)}; -} - -inline FloatArrayEntry FloatArrayTopic::GetEntry( - std::span defaultValue, - const PubSubOptions& options) { - return FloatArrayEntry{ - ::nt::GetEntry(m_handle, NT_FLOAT_ARRAY, "float[]", options), - defaultValue}; -} -inline FloatArrayEntry FloatArrayTopic::GetEntryEx( - std::string_view typeString, std::span defaultValue, - const PubSubOptions& options) { - return FloatArrayEntry{ - ::nt::GetEntry(m_handle, NT_FLOAT_ARRAY, typeString, options), - defaultValue}; -} - -} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/FloatTopic.h b/ntcore/src/generated/main/native/include/networktables/FloatTopic.h index 9a838348765..1e402837dd4 100644 --- a/ntcore/src/generated/main/native/include/networktables/FloatTopic.h +++ b/ntcore/src/generated/main/native/include/networktables/FloatTopic.h @@ -15,7 +15,9 @@ #include +#include "networktables/NetworkTableType.h" #include "networktables/Topic.h" +#include "ntcore_cpp.h" namespace wpi { template @@ -46,7 +48,9 @@ class FloatSubscriber : public Subscriber { * @param handle Native handle * @param defaultValue Default value */ - FloatSubscriber(NT_Subscriber handle, ParamType defaultValue); + FloatSubscriber(NT_Subscriber handle, ParamType defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue} {} /** * Get the last published value. @@ -54,7 +58,9 @@ class FloatSubscriber : public Subscriber { * * @return value */ - ValueType Get() const; + ValueType Get() const { + return Get(m_defaultValue); + } /** * Get the last published value. @@ -63,7 +69,9 @@ class FloatSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - ValueType Get(ParamType defaultValue) const; + ValueType Get(ParamType defaultValue) const { + return ::nt::GetFloat(m_subHandle, defaultValue); + } /** * Get the last published value along with its timestamp @@ -72,7 +80,9 @@ class FloatSubscriber : public Subscriber { * * @return timestamped value */ - TimestampedValueType GetAtomic() const; + TimestampedValueType GetAtomic() const { + return GetAtomic(m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -82,7 +92,9 @@ class FloatSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return timestamped value */ - TimestampedValueType GetAtomic(ParamType defaultValue) const; + TimestampedValueType GetAtomic(ParamType defaultValue) const { + return ::nt::GetAtomicFloat(m_subHandle, defaultValue); + } /** * Get an array of all value changes since the last call to ReadQueue. @@ -94,7 +106,9 @@ class FloatSubscriber : public Subscriber { * @return Array of timestamped values; empty array if no new changes have * been published since the previous call. */ - std::vector ReadQueue(); + std::vector ReadQueue() { + return ::nt::ReadQueueFloat(m_subHandle); + } /** * Get the corresponding topic. @@ -126,7 +140,7 @@ class FloatPublisher : public Publisher { * * @param handle Native handle */ - explicit FloatPublisher(NT_Publisher handle); + explicit FloatPublisher(NT_Publisher handle) : Publisher{handle} {} /** * Publish a new value. @@ -134,7 +148,9 @@ class FloatPublisher : public Publisher { * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(ParamType value, int64_t time = 0); + void Set(ParamType value, int64_t time = 0) { + ::nt::SetFloat(m_pubHandle, value, time); + } /** * Publish a default value. @@ -143,7 +159,9 @@ class FloatPublisher : public Publisher { * * @param value value */ - void SetDefault(ParamType value); + void SetDefault(ParamType value) { + ::nt::SetDefaultFloat(m_pubHandle, value); + } /** * Get the corresponding topic. @@ -178,7 +196,9 @@ class FloatEntry final : public FloatSubscriber, * @param handle Native handle * @param defaultValue Default value */ - FloatEntry(NT_Entry handle, ParamType defaultValue); + FloatEntry(NT_Entry handle, ParamType defaultValue) + : FloatSubscriber{handle, defaultValue}, + FloatPublisher{handle} {} /** * Determines if the native handle is valid. @@ -204,7 +224,9 @@ class FloatEntry final : public FloatSubscriber, /** * Stops publishing the entry if it's published. */ - void Unpublish(); + void Unpublish() { + ::nt::Unpublish(m_pubHandle); + } }; /** @@ -256,7 +278,11 @@ class FloatTopic final : public Topic { [[nodiscard]] SubscriberType Subscribe( ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return FloatSubscriber{ + ::nt::Subscribe(m_handle, NT_FLOAT, "float", options), + defaultValue}; + } /** * Create a new subscriber to the topic, with specific type string. * @@ -276,7 +302,11 @@ class FloatTopic final : public Topic { [[nodiscard]] SubscriberType SubscribeEx( std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return FloatSubscriber{ + ::nt::Subscribe(m_handle, NT_FLOAT, typeString, options), + defaultValue}; + } /** * Create a new publisher to the topic. @@ -294,7 +324,10 @@ class FloatTopic final : public Topic { * @return publisher */ [[nodiscard]] - PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions) { + return FloatPublisher{ + ::nt::Publish(m_handle, NT_FLOAT, "float", options)}; + } /** * Create a new publisher to the topic, with type string and initial @@ -316,7 +349,10 @@ class FloatTopic final : public Topic { */ [[nodiscard]] PublisherType PublishEx(std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions) { + return FloatPublisher{ + ::nt::PublishEx(m_handle, NT_FLOAT, typeString, properties, options)}; + } /** * Create a new entry for the topic. @@ -340,7 +376,11 @@ class FloatTopic final : public Topic { */ [[nodiscard]] EntryType GetEntry(ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return FloatEntry{ + ::nt::GetEntry(m_handle, NT_FLOAT, "float", options), + defaultValue}; + } /** * Create a new entry for the topic, with specific type string. * @@ -364,10 +404,24 @@ class FloatTopic final : public Topic { */ [[nodiscard]] EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return FloatEntry{ + ::nt::GetEntry(m_handle, NT_FLOAT, typeString, options), + defaultValue}; + } }; -} // namespace nt +inline FloatTopic FloatSubscriber::GetTopic() const { + return FloatTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline FloatTopic FloatPublisher::GetTopic() const { + return FloatTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} -#include "networktables/FloatTopic.inc" +inline FloatTopic FloatEntry::GetTopic() const { + return FloatTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/FloatTopic.inc b/ntcore/src/generated/main/native/include/networktables/FloatTopic.inc deleted file mode 100644 index 3f8f4484865..00000000000 --- a/ntcore/src/generated/main/native/include/networktables/FloatTopic.inc +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY - -#pragma once - -#include - -#include "networktables/FloatTopic.h" -#include "networktables/NetworkTableType.h" -#include "ntcore_cpp.h" - -namespace nt { - -inline FloatSubscriber::FloatSubscriber( - NT_Subscriber handle, ParamType defaultValue) - : Subscriber{handle}, - m_defaultValue{defaultValue} {} - -inline float FloatSubscriber::Get() const { - return Get(m_defaultValue); -} - -inline float FloatSubscriber::Get( - ParamType defaultValue) const { - return ::nt::GetFloat(m_subHandle, defaultValue); -} - -inline TimestampedFloat FloatSubscriber::GetAtomic() const { - return GetAtomic(m_defaultValue); -} - -inline TimestampedFloat FloatSubscriber::GetAtomic( - ParamType defaultValue) const { - return ::nt::GetAtomicFloat(m_subHandle, defaultValue); -} - -inline std::vector -FloatSubscriber::ReadQueue() { - return ::nt::ReadQueueFloat(m_subHandle); -} - -inline FloatTopic FloatSubscriber::GetTopic() const { - return FloatTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline FloatPublisher::FloatPublisher(NT_Publisher handle) - : Publisher{handle} {} - -inline void FloatPublisher::Set(ParamType value, - int64_t time) { - ::nt::SetFloat(m_pubHandle, value, time); -} - -inline void FloatPublisher::SetDefault(ParamType value) { - ::nt::SetDefaultFloat(m_pubHandle, value); -} - -inline FloatTopic FloatPublisher::GetTopic() const { - return FloatTopic{::nt::GetTopicFromHandle(m_pubHandle)}; -} - -inline FloatEntry::FloatEntry( - NT_Entry handle, ParamType defaultValue) - : FloatSubscriber{handle, defaultValue}, - FloatPublisher{handle} {} - -inline FloatTopic FloatEntry::GetTopic() const { - return FloatTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline void FloatEntry::Unpublish() { - ::nt::Unpublish(m_pubHandle); -} - -inline FloatSubscriber FloatTopic::Subscribe( - float defaultValue, - const PubSubOptions& options) { - return FloatSubscriber{ - ::nt::Subscribe(m_handle, NT_FLOAT, "float", options), - defaultValue}; -} -inline FloatSubscriber FloatTopic::SubscribeEx( - std::string_view typeString, float defaultValue, - const PubSubOptions& options) { - return FloatSubscriber{ - ::nt::Subscribe(m_handle, NT_FLOAT, typeString, options), - defaultValue}; -} - -inline FloatPublisher FloatTopic::Publish( - const PubSubOptions& options) { - return FloatPublisher{ - ::nt::Publish(m_handle, NT_FLOAT, "float", options)}; -} - -inline FloatPublisher FloatTopic::PublishEx( - std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options) { - return FloatPublisher{ - ::nt::PublishEx(m_handle, NT_FLOAT, typeString, properties, options)}; -} - -inline FloatEntry FloatTopic::GetEntry( - float defaultValue, - const PubSubOptions& options) { - return FloatEntry{ - ::nt::GetEntry(m_handle, NT_FLOAT, "float", options), - defaultValue}; -} -inline FloatEntry FloatTopic::GetEntryEx( - std::string_view typeString, float defaultValue, - const PubSubOptions& options) { - return FloatEntry{ - ::nt::GetEntry(m_handle, NT_FLOAT, typeString, options), - defaultValue}; -} - -} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/IntegerArrayTopic.h b/ntcore/src/generated/main/native/include/networktables/IntegerArrayTopic.h index a99823acd8c..3063d4cc44b 100644 --- a/ntcore/src/generated/main/native/include/networktables/IntegerArrayTopic.h +++ b/ntcore/src/generated/main/native/include/networktables/IntegerArrayTopic.h @@ -15,7 +15,9 @@ #include +#include "networktables/NetworkTableType.h" #include "networktables/Topic.h" +#include "ntcore_cpp.h" namespace wpi { template @@ -50,7 +52,9 @@ class IntegerArraySubscriber : public Subscriber { * @param handle Native handle * @param defaultValue Default value */ - IntegerArraySubscriber(NT_Subscriber handle, ParamType defaultValue); + IntegerArraySubscriber(NT_Subscriber handle, ParamType defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue.begin(), defaultValue.end()} {} /** * Get the last published value. @@ -58,7 +62,9 @@ class IntegerArraySubscriber : public Subscriber { * * @return value */ - ValueType Get() const; + ValueType Get() const { + return Get(m_defaultValue); + } /** * Get the last published value. @@ -67,7 +73,9 @@ class IntegerArraySubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - ValueType Get(ParamType defaultValue) const; + ValueType Get(ParamType defaultValue) const { + return ::nt::GetIntegerArray(m_subHandle, defaultValue); + } /** * Get the last published value. @@ -76,7 +84,9 @@ class IntegerArraySubscriber : public Subscriber { * @param buf storage for returned value * @return value */ - SmallRetType Get(wpi::SmallVectorImpl& buf) const; + SmallRetType Get(wpi::SmallVectorImpl& buf) const { + return Get(buf, m_defaultValue); + } /** * Get the last published value. @@ -86,7 +96,9 @@ class IntegerArraySubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const; + SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { + return nt::GetIntegerArray(m_subHandle, buf, defaultValue); + } /** * Get the last published value along with its timestamp @@ -95,7 +107,9 @@ class IntegerArraySubscriber : public Subscriber { * * @return timestamped value */ - TimestampedValueType GetAtomic() const; + TimestampedValueType GetAtomic() const { + return GetAtomic(m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -105,7 +119,9 @@ class IntegerArraySubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return timestamped value */ - TimestampedValueType GetAtomic(ParamType defaultValue) const; + TimestampedValueType GetAtomic(ParamType defaultValue) const { + return ::nt::GetAtomicIntegerArray(m_subHandle, defaultValue); + } /** * Get the last published value along with its timestamp. @@ -116,7 +132,9 @@ class IntegerArraySubscriber : public Subscriber { * @return timestamped value */ TimestampedValueViewType GetAtomic( - wpi::SmallVectorImpl& buf) const; + wpi::SmallVectorImpl& buf) const { + return GetAtomic(buf, m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -129,7 +147,9 @@ class IntegerArraySubscriber : public Subscriber { */ TimestampedValueViewType GetAtomic( wpi::SmallVectorImpl& buf, - ParamType defaultValue) const; + ParamType defaultValue) const { + return nt::GetAtomicIntegerArray(m_subHandle, buf, defaultValue); + } /** * Get an array of all value changes since the last call to ReadQueue. @@ -141,7 +161,9 @@ class IntegerArraySubscriber : public Subscriber { * @return Array of timestamped values; empty array if no new changes have * been published since the previous call. */ - std::vector ReadQueue(); + std::vector ReadQueue() { + return ::nt::ReadQueueIntegerArray(m_subHandle); + } /** * Get the corresponding topic. @@ -176,7 +198,7 @@ class IntegerArrayPublisher : public Publisher { * * @param handle Native handle */ - explicit IntegerArrayPublisher(NT_Publisher handle); + explicit IntegerArrayPublisher(NT_Publisher handle) : Publisher{handle} {} /** * Publish a new value. @@ -184,7 +206,9 @@ class IntegerArrayPublisher : public Publisher { * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(ParamType value, int64_t time = 0); + void Set(ParamType value, int64_t time = 0) { + ::nt::SetIntegerArray(m_pubHandle, value, time); + } /** * Publish a default value. @@ -193,7 +217,9 @@ class IntegerArrayPublisher : public Publisher { * * @param value value */ - void SetDefault(ParamType value); + void SetDefault(ParamType value) { + ::nt::SetDefaultIntegerArray(m_pubHandle, value); + } /** * Get the corresponding topic. @@ -231,7 +257,9 @@ class IntegerArrayEntry final : public IntegerArraySubscriber, * @param handle Native handle * @param defaultValue Default value */ - IntegerArrayEntry(NT_Entry handle, ParamType defaultValue); + IntegerArrayEntry(NT_Entry handle, ParamType defaultValue) + : IntegerArraySubscriber{handle, defaultValue}, + IntegerArrayPublisher{handle} {} /** * Determines if the native handle is valid. @@ -257,7 +285,9 @@ class IntegerArrayEntry final : public IntegerArraySubscriber, /** * Stops publishing the entry if it's published. */ - void Unpublish(); + void Unpublish() { + ::nt::Unpublish(m_pubHandle); + } }; /** @@ -309,7 +339,11 @@ class IntegerArrayTopic final : public Topic { [[nodiscard]] SubscriberType Subscribe( ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return IntegerArraySubscriber{ + ::nt::Subscribe(m_handle, NT_INTEGER_ARRAY, "int[]", options), + defaultValue}; + } /** * Create a new subscriber to the topic, with specific type string. * @@ -329,7 +363,11 @@ class IntegerArrayTopic final : public Topic { [[nodiscard]] SubscriberType SubscribeEx( std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return IntegerArraySubscriber{ + ::nt::Subscribe(m_handle, NT_INTEGER_ARRAY, typeString, options), + defaultValue}; + } /** * Create a new publisher to the topic. @@ -347,7 +385,10 @@ class IntegerArrayTopic final : public Topic { * @return publisher */ [[nodiscard]] - PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions) { + return IntegerArrayPublisher{ + ::nt::Publish(m_handle, NT_INTEGER_ARRAY, "int[]", options)}; + } /** * Create a new publisher to the topic, with type string and initial @@ -369,7 +410,10 @@ class IntegerArrayTopic final : public Topic { */ [[nodiscard]] PublisherType PublishEx(std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions) { + return IntegerArrayPublisher{ + ::nt::PublishEx(m_handle, NT_INTEGER_ARRAY, typeString, properties, options)}; + } /** * Create a new entry for the topic. @@ -393,7 +437,11 @@ class IntegerArrayTopic final : public Topic { */ [[nodiscard]] EntryType GetEntry(ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return IntegerArrayEntry{ + ::nt::GetEntry(m_handle, NT_INTEGER_ARRAY, "int[]", options), + defaultValue}; + } /** * Create a new entry for the topic, with specific type string. * @@ -417,10 +465,24 @@ class IntegerArrayTopic final : public Topic { */ [[nodiscard]] EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return IntegerArrayEntry{ + ::nt::GetEntry(m_handle, NT_INTEGER_ARRAY, typeString, options), + defaultValue}; + } }; -} // namespace nt +inline IntegerArrayTopic IntegerArraySubscriber::GetTopic() const { + return IntegerArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline IntegerArrayTopic IntegerArrayPublisher::GetTopic() const { + return IntegerArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} -#include "networktables/IntegerArrayTopic.inc" +inline IntegerArrayTopic IntegerArrayEntry::GetTopic() const { + return IntegerArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/IntegerArrayTopic.inc b/ntcore/src/generated/main/native/include/networktables/IntegerArrayTopic.inc deleted file mode 100644 index f4156a49433..00000000000 --- a/ntcore/src/generated/main/native/include/networktables/IntegerArrayTopic.inc +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY - -#pragma once - -#include - -#include "networktables/IntegerArrayTopic.h" -#include "networktables/NetworkTableType.h" -#include "ntcore_cpp.h" - -namespace nt { - -inline IntegerArraySubscriber::IntegerArraySubscriber( - NT_Subscriber handle, ParamType defaultValue) - : Subscriber{handle}, - m_defaultValue{defaultValue.begin(), defaultValue.end()} {} - -inline std::vector IntegerArraySubscriber::Get() const { - return Get(m_defaultValue); -} - -inline std::vector IntegerArraySubscriber::Get( - ParamType defaultValue) const { - return ::nt::GetIntegerArray(m_subHandle, defaultValue); -} - -inline std::span IntegerArraySubscriber::Get(wpi::SmallVectorImpl& buf) const { - return Get(buf, m_defaultValue); -} - -inline std::span IntegerArraySubscriber::Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { - return nt::GetIntegerArray(m_subHandle, buf, defaultValue); -} - -inline TimestampedIntegerArray IntegerArraySubscriber::GetAtomic() const { - return GetAtomic(m_defaultValue); -} - -inline TimestampedIntegerArray IntegerArraySubscriber::GetAtomic( - ParamType defaultValue) const { - return ::nt::GetAtomicIntegerArray(m_subHandle, defaultValue); -} - -inline TimestampedIntegerArrayView IntegerArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf) const { - return GetAtomic(buf, m_defaultValue); -} - -inline TimestampedIntegerArrayView IntegerArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { - return nt::GetAtomicIntegerArray(m_subHandle, buf, defaultValue); -} - -inline std::vector -IntegerArraySubscriber::ReadQueue() { - return ::nt::ReadQueueIntegerArray(m_subHandle); -} - -inline IntegerArrayTopic IntegerArraySubscriber::GetTopic() const { - return IntegerArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline IntegerArrayPublisher::IntegerArrayPublisher(NT_Publisher handle) - : Publisher{handle} {} - -inline void IntegerArrayPublisher::Set(ParamType value, - int64_t time) { - ::nt::SetIntegerArray(m_pubHandle, value, time); -} - -inline void IntegerArrayPublisher::SetDefault(ParamType value) { - ::nt::SetDefaultIntegerArray(m_pubHandle, value); -} - -inline IntegerArrayTopic IntegerArrayPublisher::GetTopic() const { - return IntegerArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)}; -} - -inline IntegerArrayEntry::IntegerArrayEntry( - NT_Entry handle, ParamType defaultValue) - : IntegerArraySubscriber{handle, defaultValue}, - IntegerArrayPublisher{handle} {} - -inline IntegerArrayTopic IntegerArrayEntry::GetTopic() const { - return IntegerArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline void IntegerArrayEntry::Unpublish() { - ::nt::Unpublish(m_pubHandle); -} - -inline IntegerArraySubscriber IntegerArrayTopic::Subscribe( - std::span defaultValue, - const PubSubOptions& options) { - return IntegerArraySubscriber{ - ::nt::Subscribe(m_handle, NT_INTEGER_ARRAY, "int[]", options), - defaultValue}; -} -inline IntegerArraySubscriber IntegerArrayTopic::SubscribeEx( - std::string_view typeString, std::span defaultValue, - const PubSubOptions& options) { - return IntegerArraySubscriber{ - ::nt::Subscribe(m_handle, NT_INTEGER_ARRAY, typeString, options), - defaultValue}; -} - -inline IntegerArrayPublisher IntegerArrayTopic::Publish( - const PubSubOptions& options) { - return IntegerArrayPublisher{ - ::nt::Publish(m_handle, NT_INTEGER_ARRAY, "int[]", options)}; -} - -inline IntegerArrayPublisher IntegerArrayTopic::PublishEx( - std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options) { - return IntegerArrayPublisher{ - ::nt::PublishEx(m_handle, NT_INTEGER_ARRAY, typeString, properties, options)}; -} - -inline IntegerArrayEntry IntegerArrayTopic::GetEntry( - std::span defaultValue, - const PubSubOptions& options) { - return IntegerArrayEntry{ - ::nt::GetEntry(m_handle, NT_INTEGER_ARRAY, "int[]", options), - defaultValue}; -} -inline IntegerArrayEntry IntegerArrayTopic::GetEntryEx( - std::string_view typeString, std::span defaultValue, - const PubSubOptions& options) { - return IntegerArrayEntry{ - ::nt::GetEntry(m_handle, NT_INTEGER_ARRAY, typeString, options), - defaultValue}; -} - -} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/IntegerTopic.h b/ntcore/src/generated/main/native/include/networktables/IntegerTopic.h index 0d5ab21492c..f0576e9ddeb 100644 --- a/ntcore/src/generated/main/native/include/networktables/IntegerTopic.h +++ b/ntcore/src/generated/main/native/include/networktables/IntegerTopic.h @@ -15,7 +15,9 @@ #include +#include "networktables/NetworkTableType.h" #include "networktables/Topic.h" +#include "ntcore_cpp.h" namespace wpi { template @@ -46,7 +48,9 @@ class IntegerSubscriber : public Subscriber { * @param handle Native handle * @param defaultValue Default value */ - IntegerSubscriber(NT_Subscriber handle, ParamType defaultValue); + IntegerSubscriber(NT_Subscriber handle, ParamType defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue} {} /** * Get the last published value. @@ -54,7 +58,9 @@ class IntegerSubscriber : public Subscriber { * * @return value */ - ValueType Get() const; + ValueType Get() const { + return Get(m_defaultValue); + } /** * Get the last published value. @@ -63,7 +69,9 @@ class IntegerSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - ValueType Get(ParamType defaultValue) const; + ValueType Get(ParamType defaultValue) const { + return ::nt::GetInteger(m_subHandle, defaultValue); + } /** * Get the last published value along with its timestamp @@ -72,7 +80,9 @@ class IntegerSubscriber : public Subscriber { * * @return timestamped value */ - TimestampedValueType GetAtomic() const; + TimestampedValueType GetAtomic() const { + return GetAtomic(m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -82,7 +92,9 @@ class IntegerSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return timestamped value */ - TimestampedValueType GetAtomic(ParamType defaultValue) const; + TimestampedValueType GetAtomic(ParamType defaultValue) const { + return ::nt::GetAtomicInteger(m_subHandle, defaultValue); + } /** * Get an array of all value changes since the last call to ReadQueue. @@ -94,7 +106,9 @@ class IntegerSubscriber : public Subscriber { * @return Array of timestamped values; empty array if no new changes have * been published since the previous call. */ - std::vector ReadQueue(); + std::vector ReadQueue() { + return ::nt::ReadQueueInteger(m_subHandle); + } /** * Get the corresponding topic. @@ -126,7 +140,7 @@ class IntegerPublisher : public Publisher { * * @param handle Native handle */ - explicit IntegerPublisher(NT_Publisher handle); + explicit IntegerPublisher(NT_Publisher handle) : Publisher{handle} {} /** * Publish a new value. @@ -134,7 +148,9 @@ class IntegerPublisher : public Publisher { * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(ParamType value, int64_t time = 0); + void Set(ParamType value, int64_t time = 0) { + ::nt::SetInteger(m_pubHandle, value, time); + } /** * Publish a default value. @@ -143,7 +159,9 @@ class IntegerPublisher : public Publisher { * * @param value value */ - void SetDefault(ParamType value); + void SetDefault(ParamType value) { + ::nt::SetDefaultInteger(m_pubHandle, value); + } /** * Get the corresponding topic. @@ -178,7 +196,9 @@ class IntegerEntry final : public IntegerSubscriber, * @param handle Native handle * @param defaultValue Default value */ - IntegerEntry(NT_Entry handle, ParamType defaultValue); + IntegerEntry(NT_Entry handle, ParamType defaultValue) + : IntegerSubscriber{handle, defaultValue}, + IntegerPublisher{handle} {} /** * Determines if the native handle is valid. @@ -204,7 +224,9 @@ class IntegerEntry final : public IntegerSubscriber, /** * Stops publishing the entry if it's published. */ - void Unpublish(); + void Unpublish() { + ::nt::Unpublish(m_pubHandle); + } }; /** @@ -256,7 +278,11 @@ class IntegerTopic final : public Topic { [[nodiscard]] SubscriberType Subscribe( ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return IntegerSubscriber{ + ::nt::Subscribe(m_handle, NT_INTEGER, "int", options), + defaultValue}; + } /** * Create a new subscriber to the topic, with specific type string. * @@ -276,7 +302,11 @@ class IntegerTopic final : public Topic { [[nodiscard]] SubscriberType SubscribeEx( std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return IntegerSubscriber{ + ::nt::Subscribe(m_handle, NT_INTEGER, typeString, options), + defaultValue}; + } /** * Create a new publisher to the topic. @@ -294,7 +324,10 @@ class IntegerTopic final : public Topic { * @return publisher */ [[nodiscard]] - PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions) { + return IntegerPublisher{ + ::nt::Publish(m_handle, NT_INTEGER, "int", options)}; + } /** * Create a new publisher to the topic, with type string and initial @@ -316,7 +349,10 @@ class IntegerTopic final : public Topic { */ [[nodiscard]] PublisherType PublishEx(std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions) { + return IntegerPublisher{ + ::nt::PublishEx(m_handle, NT_INTEGER, typeString, properties, options)}; + } /** * Create a new entry for the topic. @@ -340,7 +376,11 @@ class IntegerTopic final : public Topic { */ [[nodiscard]] EntryType GetEntry(ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return IntegerEntry{ + ::nt::GetEntry(m_handle, NT_INTEGER, "int", options), + defaultValue}; + } /** * Create a new entry for the topic, with specific type string. * @@ -364,10 +404,24 @@ class IntegerTopic final : public Topic { */ [[nodiscard]] EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return IntegerEntry{ + ::nt::GetEntry(m_handle, NT_INTEGER, typeString, options), + defaultValue}; + } }; -} // namespace nt +inline IntegerTopic IntegerSubscriber::GetTopic() const { + return IntegerTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline IntegerTopic IntegerPublisher::GetTopic() const { + return IntegerTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} -#include "networktables/IntegerTopic.inc" +inline IntegerTopic IntegerEntry::GetTopic() const { + return IntegerTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/IntegerTopic.inc b/ntcore/src/generated/main/native/include/networktables/IntegerTopic.inc deleted file mode 100644 index 2d58adc1633..00000000000 --- a/ntcore/src/generated/main/native/include/networktables/IntegerTopic.inc +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY - -#pragma once - -#include - -#include "networktables/IntegerTopic.h" -#include "networktables/NetworkTableType.h" -#include "ntcore_cpp.h" - -namespace nt { - -inline IntegerSubscriber::IntegerSubscriber( - NT_Subscriber handle, ParamType defaultValue) - : Subscriber{handle}, - m_defaultValue{defaultValue} {} - -inline int64_t IntegerSubscriber::Get() const { - return Get(m_defaultValue); -} - -inline int64_t IntegerSubscriber::Get( - ParamType defaultValue) const { - return ::nt::GetInteger(m_subHandle, defaultValue); -} - -inline TimestampedInteger IntegerSubscriber::GetAtomic() const { - return GetAtomic(m_defaultValue); -} - -inline TimestampedInteger IntegerSubscriber::GetAtomic( - ParamType defaultValue) const { - return ::nt::GetAtomicInteger(m_subHandle, defaultValue); -} - -inline std::vector -IntegerSubscriber::ReadQueue() { - return ::nt::ReadQueueInteger(m_subHandle); -} - -inline IntegerTopic IntegerSubscriber::GetTopic() const { - return IntegerTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline IntegerPublisher::IntegerPublisher(NT_Publisher handle) - : Publisher{handle} {} - -inline void IntegerPublisher::Set(ParamType value, - int64_t time) { - ::nt::SetInteger(m_pubHandle, value, time); -} - -inline void IntegerPublisher::SetDefault(ParamType value) { - ::nt::SetDefaultInteger(m_pubHandle, value); -} - -inline IntegerTopic IntegerPublisher::GetTopic() const { - return IntegerTopic{::nt::GetTopicFromHandle(m_pubHandle)}; -} - -inline IntegerEntry::IntegerEntry( - NT_Entry handle, ParamType defaultValue) - : IntegerSubscriber{handle, defaultValue}, - IntegerPublisher{handle} {} - -inline IntegerTopic IntegerEntry::GetTopic() const { - return IntegerTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline void IntegerEntry::Unpublish() { - ::nt::Unpublish(m_pubHandle); -} - -inline IntegerSubscriber IntegerTopic::Subscribe( - int64_t defaultValue, - const PubSubOptions& options) { - return IntegerSubscriber{ - ::nt::Subscribe(m_handle, NT_INTEGER, "int", options), - defaultValue}; -} -inline IntegerSubscriber IntegerTopic::SubscribeEx( - std::string_view typeString, int64_t defaultValue, - const PubSubOptions& options) { - return IntegerSubscriber{ - ::nt::Subscribe(m_handle, NT_INTEGER, typeString, options), - defaultValue}; -} - -inline IntegerPublisher IntegerTopic::Publish( - const PubSubOptions& options) { - return IntegerPublisher{ - ::nt::Publish(m_handle, NT_INTEGER, "int", options)}; -} - -inline IntegerPublisher IntegerTopic::PublishEx( - std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options) { - return IntegerPublisher{ - ::nt::PublishEx(m_handle, NT_INTEGER, typeString, properties, options)}; -} - -inline IntegerEntry IntegerTopic::GetEntry( - int64_t defaultValue, - const PubSubOptions& options) { - return IntegerEntry{ - ::nt::GetEntry(m_handle, NT_INTEGER, "int", options), - defaultValue}; -} -inline IntegerEntry IntegerTopic::GetEntryEx( - std::string_view typeString, int64_t defaultValue, - const PubSubOptions& options) { - return IntegerEntry{ - ::nt::GetEntry(m_handle, NT_INTEGER, typeString, options), - defaultValue}; -} - -} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/RawTopic.h b/ntcore/src/generated/main/native/include/networktables/RawTopic.h index e124fe1db68..b42dfe58db7 100644 --- a/ntcore/src/generated/main/native/include/networktables/RawTopic.h +++ b/ntcore/src/generated/main/native/include/networktables/RawTopic.h @@ -15,7 +15,9 @@ #include +#include "networktables/NetworkTableType.h" #include "networktables/Topic.h" +#include "ntcore_cpp.h" namespace wpi { template @@ -50,7 +52,9 @@ class RawSubscriber : public Subscriber { * @param handle Native handle * @param defaultValue Default value */ - RawSubscriber(NT_Subscriber handle, ParamType defaultValue); + RawSubscriber(NT_Subscriber handle, ParamType defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue.begin(), defaultValue.end()} {} /** * Get the last published value. @@ -58,7 +62,9 @@ class RawSubscriber : public Subscriber { * * @return value */ - ValueType Get() const; + ValueType Get() const { + return Get(m_defaultValue); + } /** * Get the last published value. @@ -67,7 +73,9 @@ class RawSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - ValueType Get(ParamType defaultValue) const; + ValueType Get(ParamType defaultValue) const { + return ::nt::GetRaw(m_subHandle, defaultValue); + } /** * Get the last published value. @@ -76,7 +84,9 @@ class RawSubscriber : public Subscriber { * @param buf storage for returned value * @return value */ - SmallRetType Get(wpi::SmallVectorImpl& buf) const; + SmallRetType Get(wpi::SmallVectorImpl& buf) const { + return Get(buf, m_defaultValue); + } /** * Get the last published value. @@ -86,7 +96,9 @@ class RawSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const; + SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { + return nt::GetRaw(m_subHandle, buf, defaultValue); + } /** * Get the last published value along with its timestamp @@ -95,7 +107,9 @@ class RawSubscriber : public Subscriber { * * @return timestamped value */ - TimestampedValueType GetAtomic() const; + TimestampedValueType GetAtomic() const { + return GetAtomic(m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -105,7 +119,9 @@ class RawSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return timestamped value */ - TimestampedValueType GetAtomic(ParamType defaultValue) const; + TimestampedValueType GetAtomic(ParamType defaultValue) const { + return ::nt::GetAtomicRaw(m_subHandle, defaultValue); + } /** * Get the last published value along with its timestamp. @@ -116,7 +132,9 @@ class RawSubscriber : public Subscriber { * @return timestamped value */ TimestampedValueViewType GetAtomic( - wpi::SmallVectorImpl& buf) const; + wpi::SmallVectorImpl& buf) const { + return GetAtomic(buf, m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -129,7 +147,9 @@ class RawSubscriber : public Subscriber { */ TimestampedValueViewType GetAtomic( wpi::SmallVectorImpl& buf, - ParamType defaultValue) const; + ParamType defaultValue) const { + return nt::GetAtomicRaw(m_subHandle, buf, defaultValue); + } /** * Get an array of all value changes since the last call to ReadQueue. @@ -141,7 +161,9 @@ class RawSubscriber : public Subscriber { * @return Array of timestamped values; empty array if no new changes have * been published since the previous call. */ - std::vector ReadQueue(); + std::vector ReadQueue() { + return ::nt::ReadQueueRaw(m_subHandle); + } /** * Get the corresponding topic. @@ -176,7 +198,7 @@ class RawPublisher : public Publisher { * * @param handle Native handle */ - explicit RawPublisher(NT_Publisher handle); + explicit RawPublisher(NT_Publisher handle) : Publisher{handle} {} /** * Publish a new value. @@ -184,7 +206,9 @@ class RawPublisher : public Publisher { * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(ParamType value, int64_t time = 0); + void Set(ParamType value, int64_t time = 0) { + ::nt::SetRaw(m_pubHandle, value, time); + } /** * Publish a default value. @@ -193,7 +217,9 @@ class RawPublisher : public Publisher { * * @param value value */ - void SetDefault(ParamType value); + void SetDefault(ParamType value) { + ::nt::SetDefaultRaw(m_pubHandle, value); + } /** * Get the corresponding topic. @@ -231,7 +257,9 @@ class RawEntry final : public RawSubscriber, * @param handle Native handle * @param defaultValue Default value */ - RawEntry(NT_Entry handle, ParamType defaultValue); + RawEntry(NT_Entry handle, ParamType defaultValue) + : RawSubscriber{handle, defaultValue}, + RawPublisher{handle} {} /** * Determines if the native handle is valid. @@ -257,7 +285,9 @@ class RawEntry final : public RawSubscriber, /** * Stops publishing the entry if it's published. */ - void Unpublish(); + void Unpublish() { + ::nt::Unpublish(m_pubHandle); + } }; /** @@ -309,7 +339,11 @@ class RawTopic final : public Topic { [[nodiscard]] SubscriberType Subscribe( std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return RawSubscriber{ + ::nt::Subscribe(m_handle, NT_RAW, typeString, options), + defaultValue}; + } /** * Create a new publisher to the topic. * @@ -328,7 +362,10 @@ class RawTopic final : public Topic { * @return publisher */ [[nodiscard]] - PublisherType Publish(std::string_view typeString, const PubSubOptions& options = kDefaultPubSubOptions); + PublisherType Publish(std::string_view typeString, const PubSubOptions& options = kDefaultPubSubOptions) { + return RawPublisher{ + ::nt::Publish(m_handle, NT_RAW, typeString, options)}; + } /** * Create a new publisher to the topic, with type string and initial @@ -350,7 +387,10 @@ class RawTopic final : public Topic { */ [[nodiscard]] PublisherType PublishEx(std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions) { + return RawPublisher{ + ::nt::PublishEx(m_handle, NT_RAW, typeString, properties, options)}; + } /** * Create a new entry for the topic. @@ -376,9 +416,23 @@ class RawTopic final : public Topic { */ [[nodiscard]] EntryType GetEntry(std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return RawEntry{ + ::nt::GetEntry(m_handle, NT_RAW, typeString, options), + defaultValue}; + } }; -} // namespace nt +inline RawTopic RawSubscriber::GetTopic() const { + return RawTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline RawTopic RawPublisher::GetTopic() const { + return RawTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} -#include "networktables/RawTopic.inc" +inline RawTopic RawEntry::GetTopic() const { + return RawTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/RawTopic.inc b/ntcore/src/generated/main/native/include/networktables/RawTopic.inc deleted file mode 100644 index e0c7e61abc4..00000000000 --- a/ntcore/src/generated/main/native/include/networktables/RawTopic.inc +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY - -#pragma once - -#include - -#include "networktables/RawTopic.h" -#include "networktables/NetworkTableType.h" -#include "ntcore_cpp.h" - -namespace nt { - -inline RawSubscriber::RawSubscriber( - NT_Subscriber handle, ParamType defaultValue) - : Subscriber{handle}, - m_defaultValue{defaultValue.begin(), defaultValue.end()} {} - -inline std::vector RawSubscriber::Get() const { - return Get(m_defaultValue); -} - -inline std::vector RawSubscriber::Get( - ParamType defaultValue) const { - return ::nt::GetRaw(m_subHandle, defaultValue); -} - -inline std::span RawSubscriber::Get(wpi::SmallVectorImpl& buf) const { - return Get(buf, m_defaultValue); -} - -inline std::span RawSubscriber::Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { - return nt::GetRaw(m_subHandle, buf, defaultValue); -} - -inline TimestampedRaw RawSubscriber::GetAtomic() const { - return GetAtomic(m_defaultValue); -} - -inline TimestampedRaw RawSubscriber::GetAtomic( - ParamType defaultValue) const { - return ::nt::GetAtomicRaw(m_subHandle, defaultValue); -} - -inline TimestampedRawView RawSubscriber::GetAtomic(wpi::SmallVectorImpl& buf) const { - return GetAtomic(buf, m_defaultValue); -} - -inline TimestampedRawView RawSubscriber::GetAtomic(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { - return nt::GetAtomicRaw(m_subHandle, buf, defaultValue); -} - -inline std::vector -RawSubscriber::ReadQueue() { - return ::nt::ReadQueueRaw(m_subHandle); -} - -inline RawTopic RawSubscriber::GetTopic() const { - return RawTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline RawPublisher::RawPublisher(NT_Publisher handle) - : Publisher{handle} {} - -inline void RawPublisher::Set(ParamType value, - int64_t time) { - ::nt::SetRaw(m_pubHandle, value, time); -} - -inline void RawPublisher::SetDefault(ParamType value) { - ::nt::SetDefaultRaw(m_pubHandle, value); -} - -inline RawTopic RawPublisher::GetTopic() const { - return RawTopic{::nt::GetTopicFromHandle(m_pubHandle)}; -} - -inline RawEntry::RawEntry( - NT_Entry handle, ParamType defaultValue) - : RawSubscriber{handle, defaultValue}, - RawPublisher{handle} {} - -inline RawTopic RawEntry::GetTopic() const { - return RawTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline void RawEntry::Unpublish() { - ::nt::Unpublish(m_pubHandle); -} - -inline RawSubscriber RawTopic::Subscribe( - std::string_view typeString, std::span defaultValue, - const PubSubOptions& options) { - return RawSubscriber{ - ::nt::Subscribe(m_handle, NT_RAW, typeString, options), - defaultValue}; -} -inline RawPublisher RawTopic::Publish( - std::string_view typeString, const PubSubOptions& options) { - return RawPublisher{ - ::nt::Publish(m_handle, NT_RAW, typeString, options)}; -} - -inline RawPublisher RawTopic::PublishEx( - std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options) { - return RawPublisher{ - ::nt::PublishEx(m_handle, NT_RAW, typeString, properties, options)}; -} - -inline RawEntry RawTopic::GetEntry( - std::string_view typeString, std::span defaultValue, - const PubSubOptions& options) { - return RawEntry{ - ::nt::GetEntry(m_handle, NT_RAW, typeString, options), - defaultValue}; -} -} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/StringArrayTopic.h b/ntcore/src/generated/main/native/include/networktables/StringArrayTopic.h index 9339521002c..9c36bac3f36 100644 --- a/ntcore/src/generated/main/native/include/networktables/StringArrayTopic.h +++ b/ntcore/src/generated/main/native/include/networktables/StringArrayTopic.h @@ -15,7 +15,9 @@ #include +#include "networktables/NetworkTableType.h" #include "networktables/Topic.h" +#include "ntcore_cpp.h" namespace wpi { template @@ -46,7 +48,9 @@ class StringArraySubscriber : public Subscriber { * @param handle Native handle * @param defaultValue Default value */ - StringArraySubscriber(NT_Subscriber handle, ParamType defaultValue); + StringArraySubscriber(NT_Subscriber handle, ParamType defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue.begin(), defaultValue.end()} {} /** * Get the last published value. @@ -54,7 +58,9 @@ class StringArraySubscriber : public Subscriber { * * @return value */ - ValueType Get() const; + ValueType Get() const { + return Get(m_defaultValue); + } /** * Get the last published value. @@ -63,7 +69,9 @@ class StringArraySubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - ValueType Get(ParamType defaultValue) const; + ValueType Get(ParamType defaultValue) const { + return ::nt::GetStringArray(m_subHandle, defaultValue); + } /** * Get the last published value along with its timestamp @@ -72,7 +80,9 @@ class StringArraySubscriber : public Subscriber { * * @return timestamped value */ - TimestampedValueType GetAtomic() const; + TimestampedValueType GetAtomic() const { + return GetAtomic(m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -82,7 +92,9 @@ class StringArraySubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return timestamped value */ - TimestampedValueType GetAtomic(ParamType defaultValue) const; + TimestampedValueType GetAtomic(ParamType defaultValue) const { + return ::nt::GetAtomicStringArray(m_subHandle, defaultValue); + } /** * Get an array of all value changes since the last call to ReadQueue. @@ -94,7 +106,9 @@ class StringArraySubscriber : public Subscriber { * @return Array of timestamped values; empty array if no new changes have * been published since the previous call. */ - std::vector ReadQueue(); + std::vector ReadQueue() { + return ::nt::ReadQueueStringArray(m_subHandle); + } /** * Get the corresponding topic. @@ -126,7 +140,7 @@ class StringArrayPublisher : public Publisher { * * @param handle Native handle */ - explicit StringArrayPublisher(NT_Publisher handle); + explicit StringArrayPublisher(NT_Publisher handle) : Publisher{handle} {} /** * Publish a new value. @@ -134,7 +148,9 @@ class StringArrayPublisher : public Publisher { * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(ParamType value, int64_t time = 0); + void Set(ParamType value, int64_t time = 0) { + ::nt::SetStringArray(m_pubHandle, value, time); + } /** * Publish a default value. @@ -143,7 +159,9 @@ class StringArrayPublisher : public Publisher { * * @param value value */ - void SetDefault(ParamType value); + void SetDefault(ParamType value) { + ::nt::SetDefaultStringArray(m_pubHandle, value); + } /** * Get the corresponding topic. @@ -178,7 +196,9 @@ class StringArrayEntry final : public StringArraySubscriber, * @param handle Native handle * @param defaultValue Default value */ - StringArrayEntry(NT_Entry handle, ParamType defaultValue); + StringArrayEntry(NT_Entry handle, ParamType defaultValue) + : StringArraySubscriber{handle, defaultValue}, + StringArrayPublisher{handle} {} /** * Determines if the native handle is valid. @@ -204,7 +224,9 @@ class StringArrayEntry final : public StringArraySubscriber, /** * Stops publishing the entry if it's published. */ - void Unpublish(); + void Unpublish() { + ::nt::Unpublish(m_pubHandle); + } }; /** @@ -256,7 +278,11 @@ class StringArrayTopic final : public Topic { [[nodiscard]] SubscriberType Subscribe( ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return StringArraySubscriber{ + ::nt::Subscribe(m_handle, NT_STRING_ARRAY, "string[]", options), + defaultValue}; + } /** * Create a new subscriber to the topic, with specific type string. * @@ -276,7 +302,11 @@ class StringArrayTopic final : public Topic { [[nodiscard]] SubscriberType SubscribeEx( std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return StringArraySubscriber{ + ::nt::Subscribe(m_handle, NT_STRING_ARRAY, typeString, options), + defaultValue}; + } /** * Create a new publisher to the topic. @@ -294,7 +324,10 @@ class StringArrayTopic final : public Topic { * @return publisher */ [[nodiscard]] - PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions) { + return StringArrayPublisher{ + ::nt::Publish(m_handle, NT_STRING_ARRAY, "string[]", options)}; + } /** * Create a new publisher to the topic, with type string and initial @@ -316,7 +349,10 @@ class StringArrayTopic final : public Topic { */ [[nodiscard]] PublisherType PublishEx(std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions) { + return StringArrayPublisher{ + ::nt::PublishEx(m_handle, NT_STRING_ARRAY, typeString, properties, options)}; + } /** * Create a new entry for the topic. @@ -340,7 +376,11 @@ class StringArrayTopic final : public Topic { */ [[nodiscard]] EntryType GetEntry(ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return StringArrayEntry{ + ::nt::GetEntry(m_handle, NT_STRING_ARRAY, "string[]", options), + defaultValue}; + } /** * Create a new entry for the topic, with specific type string. * @@ -364,10 +404,24 @@ class StringArrayTopic final : public Topic { */ [[nodiscard]] EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return StringArrayEntry{ + ::nt::GetEntry(m_handle, NT_STRING_ARRAY, typeString, options), + defaultValue}; + } }; -} // namespace nt +inline StringArrayTopic StringArraySubscriber::GetTopic() const { + return StringArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline StringArrayTopic StringArrayPublisher::GetTopic() const { + return StringArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} -#include "networktables/StringArrayTopic.inc" +inline StringArrayTopic StringArrayEntry::GetTopic() const { + return StringArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/StringArrayTopic.inc b/ntcore/src/generated/main/native/include/networktables/StringArrayTopic.inc deleted file mode 100644 index d6b20a2ca60..00000000000 --- a/ntcore/src/generated/main/native/include/networktables/StringArrayTopic.inc +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY - -#pragma once - -#include - -#include "networktables/StringArrayTopic.h" -#include "networktables/NetworkTableType.h" -#include "ntcore_cpp.h" - -namespace nt { - -inline StringArraySubscriber::StringArraySubscriber( - NT_Subscriber handle, ParamType defaultValue) - : Subscriber{handle}, - m_defaultValue{defaultValue.begin(), defaultValue.end()} {} - -inline std::vector StringArraySubscriber::Get() const { - return Get(m_defaultValue); -} - -inline std::vector StringArraySubscriber::Get( - ParamType defaultValue) const { - return ::nt::GetStringArray(m_subHandle, defaultValue); -} - -inline TimestampedStringArray StringArraySubscriber::GetAtomic() const { - return GetAtomic(m_defaultValue); -} - -inline TimestampedStringArray StringArraySubscriber::GetAtomic( - ParamType defaultValue) const { - return ::nt::GetAtomicStringArray(m_subHandle, defaultValue); -} - -inline std::vector -StringArraySubscriber::ReadQueue() { - return ::nt::ReadQueueStringArray(m_subHandle); -} - -inline StringArrayTopic StringArraySubscriber::GetTopic() const { - return StringArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline StringArrayPublisher::StringArrayPublisher(NT_Publisher handle) - : Publisher{handle} {} - -inline void StringArrayPublisher::Set(ParamType value, - int64_t time) { - ::nt::SetStringArray(m_pubHandle, value, time); -} - -inline void StringArrayPublisher::SetDefault(ParamType value) { - ::nt::SetDefaultStringArray(m_pubHandle, value); -} - -inline StringArrayTopic StringArrayPublisher::GetTopic() const { - return StringArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)}; -} - -inline StringArrayEntry::StringArrayEntry( - NT_Entry handle, ParamType defaultValue) - : StringArraySubscriber{handle, defaultValue}, - StringArrayPublisher{handle} {} - -inline StringArrayTopic StringArrayEntry::GetTopic() const { - return StringArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline void StringArrayEntry::Unpublish() { - ::nt::Unpublish(m_pubHandle); -} - -inline StringArraySubscriber StringArrayTopic::Subscribe( - std::span defaultValue, - const PubSubOptions& options) { - return StringArraySubscriber{ - ::nt::Subscribe(m_handle, NT_STRING_ARRAY, "string[]", options), - defaultValue}; -} -inline StringArraySubscriber StringArrayTopic::SubscribeEx( - std::string_view typeString, std::span defaultValue, - const PubSubOptions& options) { - return StringArraySubscriber{ - ::nt::Subscribe(m_handle, NT_STRING_ARRAY, typeString, options), - defaultValue}; -} - -inline StringArrayPublisher StringArrayTopic::Publish( - const PubSubOptions& options) { - return StringArrayPublisher{ - ::nt::Publish(m_handle, NT_STRING_ARRAY, "string[]", options)}; -} - -inline StringArrayPublisher StringArrayTopic::PublishEx( - std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options) { - return StringArrayPublisher{ - ::nt::PublishEx(m_handle, NT_STRING_ARRAY, typeString, properties, options)}; -} - -inline StringArrayEntry StringArrayTopic::GetEntry( - std::span defaultValue, - const PubSubOptions& options) { - return StringArrayEntry{ - ::nt::GetEntry(m_handle, NT_STRING_ARRAY, "string[]", options), - defaultValue}; -} -inline StringArrayEntry StringArrayTopic::GetEntryEx( - std::string_view typeString, std::span defaultValue, - const PubSubOptions& options) { - return StringArrayEntry{ - ::nt::GetEntry(m_handle, NT_STRING_ARRAY, typeString, options), - defaultValue}; -} - -} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/StringTopic.h b/ntcore/src/generated/main/native/include/networktables/StringTopic.h index 3e0ff87545b..2e65a1bbb78 100644 --- a/ntcore/src/generated/main/native/include/networktables/StringTopic.h +++ b/ntcore/src/generated/main/native/include/networktables/StringTopic.h @@ -17,7 +17,9 @@ #include +#include "networktables/NetworkTableType.h" #include "networktables/Topic.h" +#include "ntcore_cpp.h" namespace wpi { template @@ -52,7 +54,9 @@ class StringSubscriber : public Subscriber { * @param handle Native handle * @param defaultValue Default value */ - StringSubscriber(NT_Subscriber handle, ParamType defaultValue); + StringSubscriber(NT_Subscriber handle, ParamType defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue} {} /** * Get the last published value. @@ -60,7 +64,9 @@ class StringSubscriber : public Subscriber { * * @return value */ - ValueType Get() const; + ValueType Get() const { + return Get(m_defaultValue); + } /** * Get the last published value. @@ -69,7 +75,9 @@ class StringSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - ValueType Get(ParamType defaultValue) const; + ValueType Get(ParamType defaultValue) const { + return ::nt::GetString(m_subHandle, defaultValue); + } /** * Get the last published value. @@ -78,7 +86,9 @@ class StringSubscriber : public Subscriber { * @param buf storage for returned value * @return value */ - SmallRetType Get(wpi::SmallVectorImpl& buf) const; + SmallRetType Get(wpi::SmallVectorImpl& buf) const { + return Get(buf, m_defaultValue); + } /** * Get the last published value. @@ -88,7 +98,9 @@ class StringSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const; + SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { + return nt::GetString(m_subHandle, buf, defaultValue); + } /** * Get the last published value along with its timestamp @@ -97,7 +109,9 @@ class StringSubscriber : public Subscriber { * * @return timestamped value */ - TimestampedValueType GetAtomic() const; + TimestampedValueType GetAtomic() const { + return GetAtomic(m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -107,7 +121,9 @@ class StringSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return timestamped value */ - TimestampedValueType GetAtomic(ParamType defaultValue) const; + TimestampedValueType GetAtomic(ParamType defaultValue) const { + return ::nt::GetAtomicString(m_subHandle, defaultValue); + } /** * Get the last published value along with its timestamp. @@ -118,7 +134,9 @@ class StringSubscriber : public Subscriber { * @return timestamped value */ TimestampedValueViewType GetAtomic( - wpi::SmallVectorImpl& buf) const; + wpi::SmallVectorImpl& buf) const { + return GetAtomic(buf, m_defaultValue); + } /** * Get the last published value along with its timestamp. @@ -131,7 +149,9 @@ class StringSubscriber : public Subscriber { */ TimestampedValueViewType GetAtomic( wpi::SmallVectorImpl& buf, - ParamType defaultValue) const; + ParamType defaultValue) const { + return nt::GetAtomicString(m_subHandle, buf, defaultValue); + } /** * Get an array of all value changes since the last call to ReadQueue. @@ -143,7 +163,9 @@ class StringSubscriber : public Subscriber { * @return Array of timestamped values; empty array if no new changes have * been published since the previous call. */ - std::vector ReadQueue(); + std::vector ReadQueue() { + return ::nt::ReadQueueString(m_subHandle); + } /** * Get the corresponding topic. @@ -178,7 +200,7 @@ class StringPublisher : public Publisher { * * @param handle Native handle */ - explicit StringPublisher(NT_Publisher handle); + explicit StringPublisher(NT_Publisher handle) : Publisher{handle} {} /** * Publish a new value. @@ -186,7 +208,9 @@ class StringPublisher : public Publisher { * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(ParamType value, int64_t time = 0); + void Set(ParamType value, int64_t time = 0) { + ::nt::SetString(m_pubHandle, value, time); + } /** * Publish a default value. @@ -195,7 +219,9 @@ class StringPublisher : public Publisher { * * @param value value */ - void SetDefault(ParamType value); + void SetDefault(ParamType value) { + ::nt::SetDefaultString(m_pubHandle, value); + } /** * Get the corresponding topic. @@ -233,7 +259,9 @@ class StringEntry final : public StringSubscriber, * @param handle Native handle * @param defaultValue Default value */ - StringEntry(NT_Entry handle, ParamType defaultValue); + StringEntry(NT_Entry handle, ParamType defaultValue) + : StringSubscriber{handle, defaultValue}, + StringPublisher{handle} {} /** * Determines if the native handle is valid. @@ -259,7 +287,9 @@ class StringEntry final : public StringSubscriber, /** * Stops publishing the entry if it's published. */ - void Unpublish(); + void Unpublish() { + ::nt::Unpublish(m_pubHandle); + } }; /** @@ -311,7 +341,11 @@ class StringTopic final : public Topic { [[nodiscard]] SubscriberType Subscribe( ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return StringSubscriber{ + ::nt::Subscribe(m_handle, NT_STRING, "string", options), + defaultValue}; + } /** * Create a new subscriber to the topic, with specific type string. * @@ -331,7 +365,11 @@ class StringTopic final : public Topic { [[nodiscard]] SubscriberType SubscribeEx( std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return StringSubscriber{ + ::nt::Subscribe(m_handle, NT_STRING, typeString, options), + defaultValue}; + } /** * Create a new publisher to the topic. @@ -349,7 +387,10 @@ class StringTopic final : public Topic { * @return publisher */ [[nodiscard]] - PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions) { + return StringPublisher{ + ::nt::Publish(m_handle, NT_STRING, "string", options)}; + } /** * Create a new publisher to the topic, with type string and initial @@ -371,7 +412,10 @@ class StringTopic final : public Topic { */ [[nodiscard]] PublisherType PublishEx(std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions) { + return StringPublisher{ + ::nt::PublishEx(m_handle, NT_STRING, typeString, properties, options)}; + } /** * Create a new entry for the topic. @@ -395,7 +439,11 @@ class StringTopic final : public Topic { */ [[nodiscard]] EntryType GetEntry(ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return StringEntry{ + ::nt::GetEntry(m_handle, NT_STRING, "string", options), + defaultValue}; + } /** * Create a new entry for the topic, with specific type string. * @@ -419,10 +467,24 @@ class StringTopic final : public Topic { */ [[nodiscard]] EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return StringEntry{ + ::nt::GetEntry(m_handle, NT_STRING, typeString, options), + defaultValue}; + } }; -} // namespace nt +inline StringTopic StringSubscriber::GetTopic() const { + return StringTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline StringTopic StringPublisher::GetTopic() const { + return StringTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} -#include "networktables/StringTopic.inc" +inline StringTopic StringEntry::GetTopic() const { + return StringTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/StringTopic.inc b/ntcore/src/generated/main/native/include/networktables/StringTopic.inc deleted file mode 100644 index 39428852af7..00000000000 --- a/ntcore/src/generated/main/native/include/networktables/StringTopic.inc +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY - -#pragma once - -#include - -#include "networktables/StringTopic.h" -#include "networktables/NetworkTableType.h" -#include "ntcore_cpp.h" - -namespace nt { - -inline StringSubscriber::StringSubscriber( - NT_Subscriber handle, ParamType defaultValue) - : Subscriber{handle}, - m_defaultValue{defaultValue} {} - -inline std::string StringSubscriber::Get() const { - return Get(m_defaultValue); -} - -inline std::string StringSubscriber::Get( - ParamType defaultValue) const { - return ::nt::GetString(m_subHandle, defaultValue); -} - -inline std::string_view StringSubscriber::Get(wpi::SmallVectorImpl& buf) const { - return Get(buf, m_defaultValue); -} - -inline std::string_view StringSubscriber::Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { - return nt::GetString(m_subHandle, buf, defaultValue); -} - -inline TimestampedString StringSubscriber::GetAtomic() const { - return GetAtomic(m_defaultValue); -} - -inline TimestampedString StringSubscriber::GetAtomic( - ParamType defaultValue) const { - return ::nt::GetAtomicString(m_subHandle, defaultValue); -} - -inline TimestampedStringView StringSubscriber::GetAtomic(wpi::SmallVectorImpl& buf) const { - return GetAtomic(buf, m_defaultValue); -} - -inline TimestampedStringView StringSubscriber::GetAtomic(wpi::SmallVectorImpl& buf, ParamType defaultValue) const { - return nt::GetAtomicString(m_subHandle, buf, defaultValue); -} - -inline std::vector -StringSubscriber::ReadQueue() { - return ::nt::ReadQueueString(m_subHandle); -} - -inline StringTopic StringSubscriber::GetTopic() const { - return StringTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline StringPublisher::StringPublisher(NT_Publisher handle) - : Publisher{handle} {} - -inline void StringPublisher::Set(ParamType value, - int64_t time) { - ::nt::SetString(m_pubHandle, value, time); -} - -inline void StringPublisher::SetDefault(ParamType value) { - ::nt::SetDefaultString(m_pubHandle, value); -} - -inline StringTopic StringPublisher::GetTopic() const { - return StringTopic{::nt::GetTopicFromHandle(m_pubHandle)}; -} - -inline StringEntry::StringEntry( - NT_Entry handle, ParamType defaultValue) - : StringSubscriber{handle, defaultValue}, - StringPublisher{handle} {} - -inline StringTopic StringEntry::GetTopic() const { - return StringTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline void StringEntry::Unpublish() { - ::nt::Unpublish(m_pubHandle); -} - -inline StringSubscriber StringTopic::Subscribe( - std::string_view defaultValue, - const PubSubOptions& options) { - return StringSubscriber{ - ::nt::Subscribe(m_handle, NT_STRING, "string", options), - defaultValue}; -} -inline StringSubscriber StringTopic::SubscribeEx( - std::string_view typeString, std::string_view defaultValue, - const PubSubOptions& options) { - return StringSubscriber{ - ::nt::Subscribe(m_handle, NT_STRING, typeString, options), - defaultValue}; -} - -inline StringPublisher StringTopic::Publish( - const PubSubOptions& options) { - return StringPublisher{ - ::nt::Publish(m_handle, NT_STRING, "string", options)}; -} - -inline StringPublisher StringTopic::PublishEx( - std::string_view typeString, - const wpi::json& properties, const PubSubOptions& options) { - return StringPublisher{ - ::nt::PublishEx(m_handle, NT_STRING, typeString, properties, options)}; -} - -inline StringEntry StringTopic::GetEntry( - std::string_view defaultValue, - const PubSubOptions& options) { - return StringEntry{ - ::nt::GetEntry(m_handle, NT_STRING, "string", options), - defaultValue}; -} -inline StringEntry StringTopic::GetEntryEx( - std::string_view typeString, std::string_view defaultValue, - const PubSubOptions& options) { - return StringEntry{ - ::nt::GetEntry(m_handle, NT_STRING, typeString, options), - defaultValue}; -} - -} // namespace nt diff --git a/ntcore/src/main/native/cpp/net/ClientMessageQueue.h b/ntcore/src/main/native/cpp/net/ClientMessageQueue.h index c2e6f950a8a..b4baeef2330 100644 --- a/ntcore/src/main/native/cpp/net/ClientMessageQueue.h +++ b/ntcore/src/main/native/cpp/net/ClientMessageQueue.h @@ -8,6 +8,7 @@ #include #include +#include #include #include "Message.h" @@ -40,20 +41,81 @@ class ClientMessageQueueImpl final : public ClientMessageHandler, bool empty() const { return m_queue.empty(); } // ClientMessageQueue - calls to these read the queue - std::span ReadQueue(std::span out) final; - void ClearQueue() final; + std::span ReadQueue(std::span out) final { + std::scoped_lock lock{m_mutex}; + size_t count = 0; + for (auto&& msg : out) { + if (!m_queue.try_dequeue(msg)) { + break; + } + if constexpr (MaxValueSize != 0) { + if (auto* val = std::get_if(&msg.contents)) { + m_valueSize.size -= sizeof(ClientMessage) + val->value.size(); + m_valueSize.errored = false; + } + } + ++count; + } + return out.subspan(0, count); + } + + void ClearQueue() final { + std::scoped_lock lock{m_mutex}; + ClientMessage msg; + while (m_queue.try_dequeue(msg)) { + } + if constexpr (MaxValueSize != 0) { + m_valueSize.size = 0; + m_valueSize.errored = false; + } + } // ClientMessageHandler - calls to these append to the queue void ClientPublish(int pubuid, std::string_view name, std::string_view typeStr, const wpi::json& properties, - const PubSubOptionsImpl& options) final; - void ClientUnpublish(int pubuid) final; + const PubSubOptionsImpl& options) final { + std::scoped_lock lock{m_mutex}; + m_queue.enqueue(ClientMessage{PublishMsg{ + pubuid, std::string{name}, std::string{typeStr}, properties, options}}); + } + + void ClientUnpublish(int pubuid) final { + std::scoped_lock lock{m_mutex}; + m_queue.enqueue(ClientMessage{UnpublishMsg{pubuid}}); + } + void ClientSetProperties(std::string_view name, - const wpi::json& update) final; + const wpi::json& update) final { + std::scoped_lock lock{m_mutex}; + m_queue.enqueue(ClientMessage{SetPropertiesMsg{std::string{name}, update}}); + } + void ClientSubscribe(int subuid, std::span topicNames, - const PubSubOptionsImpl& options) final; - void ClientUnsubscribe(int subuid) final; - void ClientSetValue(int pubuid, const Value& value) final; + const PubSubOptionsImpl& options) final { + std::scoped_lock lock{m_mutex}; + m_queue.enqueue(ClientMessage{ + SubscribeMsg{subuid, {topicNames.begin(), topicNames.end()}, options}}); + } + + void ClientUnsubscribe(int subuid) final { + std::scoped_lock lock{m_mutex}; + m_queue.enqueue(ClientMessage{UnsubscribeMsg{subuid}}); + } + + void ClientSetValue(int pubuid, const Value& value) final { + std::scoped_lock lock{m_mutex}; + if constexpr (MaxValueSize != 0) { + m_valueSize.size += sizeof(ClientMessage) + value.size(); + if (m_valueSize.size > MaxValueSize) { + if (!m_valueSize.errored) { + WPI_ERROR(m_logger, "NT: dropping value set due to memory limits"); + m_valueSize.errored = true; + } + return; // avoid potential out of memory + } + } + m_queue.enqueue(ClientMessage{ClientValueMsg{pubuid, value}}); + } private: wpi::FastQueue m_queue{kBlockSize - 1}; @@ -83,5 +145,3 @@ using LocalClientMessageQueue = using NetworkIncomingClientQueue = detail::ClientMessageQueueImpl<0, false>; } // namespace nt::net - -#include "ClientMessageQueue.inc" diff --git a/ntcore/src/main/native/cpp/net/ClientMessageQueue.inc b/ntcore/src/main/native/cpp/net/ClientMessageQueue.inc deleted file mode 100644 index fd2c5f13a76..00000000000 --- a/ntcore/src/main/native/cpp/net/ClientMessageQueue.inc +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include -#include - -#include - -#include "ClientMessageQueue.h" - -namespace nt::net::detail { - -template -inline void ClientMessageQueueImpl::ClientPublish( - int pubuid, std::string_view name, std::string_view typeStr, - const wpi::json& properties, const PubSubOptionsImpl& options) { - std::scoped_lock lock{m_mutex}; - m_queue.enqueue(ClientMessage{PublishMsg{ - pubuid, std::string{name}, std::string{typeStr}, properties, options}}); -} - -template -inline void ClientMessageQueueImpl::ClientUnpublish( - int pubuid) { - std::scoped_lock lock{m_mutex}; - m_queue.enqueue(ClientMessage{UnpublishMsg{pubuid}}); -} - -template -inline void -ClientMessageQueueImpl::ClientSetProperties( - std::string_view name, const wpi::json& update) { - std::scoped_lock lock{m_mutex}; - m_queue.enqueue(ClientMessage{SetPropertiesMsg{std::string{name}, update}}); -} - -template -inline void ClientMessageQueueImpl::ClientSubscribe( - int subuid, std::span topicNames, - const PubSubOptionsImpl& options) { - std::scoped_lock lock{m_mutex}; - m_queue.enqueue(ClientMessage{ - SubscribeMsg{subuid, {topicNames.begin(), topicNames.end()}, options}}); -} - -template -inline void ClientMessageQueueImpl::ClientUnsubscribe( - int subuid) { - std::scoped_lock lock{m_mutex}; - m_queue.enqueue(ClientMessage{UnsubscribeMsg{subuid}}); -} - -template -std::span -ClientMessageQueueImpl::ReadQueue( - std::span out) { - std::scoped_lock lock{m_mutex}; - size_t count = 0; - for (auto&& msg : out) { - if (!m_queue.try_dequeue(msg)) { - break; - } - if constexpr (MaxValueSize != 0) { - if (auto* val = std::get_if(&msg.contents)) { - m_valueSize.size -= sizeof(ClientMessage) + val->value.size(); - m_valueSize.errored = false; - } - } - ++count; - } - return out.subspan(0, count); -} - -template -void ClientMessageQueueImpl::ClearQueue() { - std::scoped_lock lock{m_mutex}; - ClientMessage msg; - while (m_queue.try_dequeue(msg)) { - } - if constexpr (MaxValueSize != 0) { - m_valueSize.size = 0; - m_valueSize.errored = false; - } -} - -template -void ClientMessageQueueImpl::ClientSetValue( - int pubuid, const Value& value) { - std::scoped_lock lock{m_mutex}; - if constexpr (MaxValueSize != 0) { - m_valueSize.size += sizeof(ClientMessage) + value.size(); - if (m_valueSize.size > MaxValueSize) { - if (!m_valueSize.errored) { - WPI_ERROR(m_logger, "NT: dropping value set due to memory limits"); - m_valueSize.errored = true; - } - return; // avoid potential out of memory - } - } - m_queue.enqueue(ClientMessage{ClientValueMsg{pubuid, value}}); -} - -} // namespace nt::net::detail diff --git a/ntcore/src/main/native/cpp/networktables/Topic.cpp b/ntcore/src/main/native/cpp/networktables/Topic.cpp index 1188667acd2..4447903df98 100644 --- a/ntcore/src/main/native/cpp/networktables/Topic.cpp +++ b/ntcore/src/main/native/cpp/networktables/Topic.cpp @@ -60,3 +60,7 @@ GenericEntry Topic::GetGenericEntry(std::string_view typeString, return GenericEntry{::nt::GetEntry( m_handle, ::nt::GetTypeFromString(typeString), typeString, options)}; } + +void Publisher::anchor() {} + +void Subscriber::anchor() {} diff --git a/ntcore/src/main/native/include/networktables/GenericEntry.h b/ntcore/src/main/native/include/networktables/GenericEntry.h index 6c7fee4fe82..e71a25afad7 100644 --- a/ntcore/src/main/native/include/networktables/GenericEntry.h +++ b/ntcore/src/main/native/include/networktables/GenericEntry.h @@ -9,10 +9,10 @@ #include #include #include -#include #include #include "networktables/Topic.h" +#include "ntcore_cpp.h" namespace nt { @@ -36,7 +36,7 @@ class GenericSubscriber : public Subscriber { * * @param handle Native handle */ - explicit GenericSubscriber(NT_Subscriber handle); + explicit GenericSubscriber(NT_Subscriber handle) : Subscriber{handle} {} /** * Get the last published value. @@ -44,7 +44,7 @@ class GenericSubscriber : public Subscriber { * * @return value */ - ValueType Get() const; + ValueType Get() const { return ::nt::GetEntryValue(m_subHandle); } /** * Gets the entry's value as a boolean. If the entry does not exist or is of @@ -53,7 +53,9 @@ class GenericSubscriber : public Subscriber { * @param defaultValue the value to be returned if no value is found * @return the entry's value or the given default value */ - bool GetBoolean(bool defaultValue) const; + bool GetBoolean(bool defaultValue) const { + return ::nt::GetBoolean(m_subHandle, defaultValue); + } /** * Gets the entry's value as a integer. If the entry does not exist or is of @@ -62,7 +64,9 @@ class GenericSubscriber : public Subscriber { * @param defaultValue the value to be returned if no value is found * @return the entry's value or the given default value */ - int64_t GetInteger(int64_t defaultValue) const; + int64_t GetInteger(int64_t defaultValue) const { + return ::nt::GetInteger(m_subHandle, defaultValue); + } /** * Gets the entry's value as a float. If the entry does not exist or is of @@ -71,7 +75,9 @@ class GenericSubscriber : public Subscriber { * @param defaultValue the value to be returned if no value is found * @return the entry's value or the given default value */ - float GetFloat(float defaultValue) const; + float GetFloat(float defaultValue) const { + return ::nt::GetFloat(m_subHandle, defaultValue); + } /** * Gets the entry's value as a double. If the entry does not exist or is of @@ -80,7 +86,9 @@ class GenericSubscriber : public Subscriber { * @param defaultValue the value to be returned if no value is found * @return the entry's value or the given default value */ - double GetDouble(double defaultValue) const; + double GetDouble(double defaultValue) const { + return ::nt::GetDouble(m_subHandle, defaultValue); + } /** * Gets the entry's value as a string. If the entry does not exist or is of @@ -89,7 +97,9 @@ class GenericSubscriber : public Subscriber { * @param defaultValue the value to be returned if no value is found * @return the entry's value or the given default value */ - std::string GetString(std::string_view defaultValue) const; + std::string GetString(std::string_view defaultValue) const { + return ::nt::GetString(m_subHandle, defaultValue); + } /** * Gets the entry's value as a raw. If the entry does not exist or is of @@ -98,7 +108,9 @@ class GenericSubscriber : public Subscriber { * @param defaultValue the value to be returned if no value is found * @return the entry's value or the given default value */ - std::vector GetRaw(std::span defaultValue) const; + std::vector GetRaw(std::span defaultValue) const { + return ::nt::GetRaw(m_subHandle, defaultValue); + } /** * Gets the entry's value as a boolean array. If the entry does not exist @@ -114,7 +126,9 @@ class GenericSubscriber : public Subscriber { * because std::vector is special-cased in C++. 0 is false, any * non-zero value is true. */ - std::vector GetBooleanArray(std::span defaultValue) const; + std::vector GetBooleanArray(std::span defaultValue) const { + return ::nt::GetBooleanArray(m_subHandle, defaultValue); + } /** * Gets the entry's value as a integer array. If the entry does not exist @@ -127,7 +141,9 @@ class GenericSubscriber : public Subscriber { * concern, use GetValue() instead. */ std::vector GetIntegerArray( - std::span defaultValue) const; + std::span defaultValue) const { + return ::nt::GetIntegerArray(m_subHandle, defaultValue); + } /** * Gets the entry's value as a float array. If the entry does not exist @@ -139,7 +155,9 @@ class GenericSubscriber : public Subscriber { * @note This makes a copy of the array. If the overhead of this is a * concern, use GetValue() instead. */ - std::vector GetFloatArray(std::span defaultValue) const; + std::vector GetFloatArray(std::span defaultValue) const { + return ::nt::GetFloatArray(m_subHandle, defaultValue); + } /** * Gets the entry's value as a double array. If the entry does not exist @@ -152,7 +170,9 @@ class GenericSubscriber : public Subscriber { * concern, use GetValue() instead. */ std::vector GetDoubleArray( - std::span defaultValue) const; + std::span defaultValue) const { + return ::nt::GetDoubleArray(m_subHandle, defaultValue); + } /** * Gets the entry's value as a string array. If the entry does not exist @@ -165,7 +185,9 @@ class GenericSubscriber : public Subscriber { * concern, use GetValue() instead. */ std::vector GetStringArray( - std::span defaultValue) const; + std::span defaultValue) const { + return ::nt::GetStringArray(m_subHandle, defaultValue); + } /** * Get an array of all value changes since the last call to ReadQueue. @@ -177,14 +199,18 @@ class GenericSubscriber : public Subscriber { * @return Array of timestamped values; empty array if no new changes have * been published since the previous call. */ - std::vector ReadQueue(); + std::vector ReadQueue() { + return ::nt::ReadQueueValue(m_subHandle); + } /** * Get the corresponding topic. * * @return Topic */ - TopicType GetTopic() const; + TopicType GetTopic() const { + return Topic{::nt::GetTopicFromHandle(m_subHandle)}; + } }; /** @@ -205,14 +231,14 @@ class GenericPublisher : public Publisher { * * @param handle Native handle */ - explicit GenericPublisher(NT_Publisher handle); + explicit GenericPublisher(NT_Publisher handle) : Publisher{handle} {} /** * Publish a new value. * * @param value value to publish */ - void Set(ParamType value); + void Set(ParamType value) { ::nt::SetEntryValue(m_pubHandle, value); } /** * Sets the entry's value. @@ -221,7 +247,9 @@ class GenericPublisher : public Publisher { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetBoolean(bool value, int64_t time = 0); + bool SetBoolean(bool value, int64_t time = 0) { + return nt::SetBoolean(m_pubHandle, value, time); + } /** * Sets the entry's value. @@ -230,7 +258,9 @@ class GenericPublisher : public Publisher { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetInteger(int64_t value, int64_t time = 0); + bool SetInteger(int64_t value, int64_t time = 0) { + return nt::SetInteger(m_pubHandle, value, time); + } /** * Sets the entry's value. @@ -239,7 +269,9 @@ class GenericPublisher : public Publisher { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetFloat(float value, int64_t time = 0); + bool SetFloat(float value, int64_t time = 0) { + return nt::SetFloat(m_pubHandle, value, time); + } /** * Sets the entry's value. @@ -248,7 +280,9 @@ class GenericPublisher : public Publisher { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetDouble(double value, int64_t time = 0); + bool SetDouble(double value, int64_t time = 0) { + return nt::SetDouble(m_pubHandle, value, time); + } /** * Sets the entry's value. @@ -257,7 +291,9 @@ class GenericPublisher : public Publisher { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetString(std::string_view value, int64_t time = 0); + bool SetString(std::string_view value, int64_t time = 0) { + return nt::SetString(m_pubHandle, value, time); + } /** * Sets the entry's value. @@ -266,7 +302,9 @@ class GenericPublisher : public Publisher { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetRaw(std::span value, int64_t time = 0); + bool SetRaw(std::span value, int64_t time = 0) { + return nt::SetRaw(m_pubHandle, value, time); + } /** * Sets the entry's value. @@ -275,7 +313,9 @@ class GenericPublisher : public Publisher { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetBooleanArray(std::span value, int64_t time = 0); + bool SetBooleanArray(std::span value, int64_t time = 0) { + return SetEntryValue(m_pubHandle, Value::MakeBooleanArray(value, time)); + } /** * Sets the entry's value. @@ -284,7 +324,9 @@ class GenericPublisher : public Publisher { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetBooleanArray(std::span value, int64_t time = 0); + bool SetBooleanArray(std::span value, int64_t time = 0) { + return nt::SetBooleanArray(m_pubHandle, value, time); + } /** * Sets the entry's value. @@ -293,7 +335,9 @@ class GenericPublisher : public Publisher { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetIntegerArray(std::span value, int64_t time = 0); + bool SetIntegerArray(std::span value, int64_t time = 0) { + return nt::SetIntegerArray(m_pubHandle, value, time); + } /** * Sets the entry's value. @@ -302,7 +346,9 @@ class GenericPublisher : public Publisher { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetFloatArray(std::span value, int64_t time = 0); + bool SetFloatArray(std::span value, int64_t time = 0) { + return nt::SetFloatArray(m_pubHandle, value, time); + } /** * Sets the entry's value. @@ -311,7 +357,9 @@ class GenericPublisher : public Publisher { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetDoubleArray(std::span value, int64_t time = 0); + bool SetDoubleArray(std::span value, int64_t time = 0) { + return nt::SetDoubleArray(m_pubHandle, value, time); + } /** * Sets the entry's value. @@ -320,7 +368,9 @@ class GenericPublisher : public Publisher { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetStringArray(std::span value, int64_t time = 0); + bool SetStringArray(std::span value, int64_t time = 0) { + return nt::SetStringArray(m_pubHandle, value, time); + } /** * Publish a default value. @@ -329,7 +379,9 @@ class GenericPublisher : public Publisher { * * @param value value */ - void SetDefault(ParamType value); + void SetDefault(ParamType value) { + ::nt::SetDefaultEntryValue(m_pubHandle, value); + } /** * Sets the entry's value if it does not exist. @@ -337,7 +389,9 @@ class GenericPublisher : public Publisher { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultBoolean(bool defaultValue); + bool SetDefaultBoolean(bool defaultValue) { + return nt::SetDefaultBoolean(m_pubHandle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -345,7 +399,9 @@ class GenericPublisher : public Publisher { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultInteger(int64_t defaultValue); + bool SetDefaultInteger(int64_t defaultValue) { + return nt::SetDefaultInteger(m_pubHandle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -353,7 +409,9 @@ class GenericPublisher : public Publisher { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultFloat(float defaultValue); + bool SetDefaultFloat(float defaultValue) { + return nt::SetDefaultFloat(m_pubHandle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -361,7 +419,9 @@ class GenericPublisher : public Publisher { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultDouble(double defaultValue); + bool SetDefaultDouble(double defaultValue) { + return nt::SetDefaultDouble(m_pubHandle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -369,7 +429,9 @@ class GenericPublisher : public Publisher { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultString(std::string_view defaultValue); + bool SetDefaultString(std::string_view defaultValue) { + return nt::SetDefaultString(m_pubHandle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -377,7 +439,9 @@ class GenericPublisher : public Publisher { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultRaw(std::span defaultValue); + bool SetDefaultRaw(std::span defaultValue) { + return nt::SetDefaultRaw(m_pubHandle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -385,7 +449,9 @@ class GenericPublisher : public Publisher { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultBooleanArray(std::span defaultValue); + bool SetDefaultBooleanArray(std::span defaultValue) { + return nt::SetDefaultBooleanArray(m_pubHandle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -393,7 +459,9 @@ class GenericPublisher : public Publisher { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultIntegerArray(std::span defaultValue); + bool SetDefaultIntegerArray(std::span defaultValue) { + return nt::SetDefaultIntegerArray(m_pubHandle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -401,7 +469,9 @@ class GenericPublisher : public Publisher { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultFloatArray(std::span defaultValue); + bool SetDefaultFloatArray(std::span defaultValue) { + return nt::SetDefaultFloatArray(m_pubHandle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -409,7 +479,9 @@ class GenericPublisher : public Publisher { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultDoubleArray(std::span defaultValue); + bool SetDefaultDoubleArray(std::span defaultValue) { + return nt::SetDefaultDoubleArray(m_pubHandle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -417,14 +489,18 @@ class GenericPublisher : public Publisher { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultStringArray(std::span defaultValue); + bool SetDefaultStringArray(std::span defaultValue) { + return nt::SetDefaultStringArray(m_pubHandle, defaultValue); + } /** * Get the corresponding topic. * * @return Topic */ - TopicType GetTopic() const; + TopicType GetTopic() const { + return Topic{::nt::GetTopicFromHandle(m_pubHandle)}; + } }; /** @@ -449,7 +525,8 @@ class GenericEntry final : public GenericSubscriber, public GenericPublisher { * * @param handle Native handle */ - explicit GenericEntry(NT_Entry handle); + explicit GenericEntry(NT_Entry handle) + : GenericSubscriber{handle}, GenericPublisher{handle} {} /** * Determines if the native handle is valid. @@ -470,14 +547,14 @@ class GenericEntry final : public GenericSubscriber, public GenericPublisher { * * @return Topic */ - TopicType GetTopic() const; + TopicType GetTopic() const { + return Topic{::nt::GetTopicFromHandle(m_subHandle)}; + } /** * Stops publishing the entry if it's published. */ - void Unpublish(); + void Unpublish() { ::nt::Unpublish(m_pubHandle); } }; } // namespace nt - -#include "networktables/GenericEntry.inc" diff --git a/ntcore/src/main/native/include/networktables/GenericEntry.inc b/ntcore/src/main/native/include/networktables/GenericEntry.inc deleted file mode 100644 index f3d996707bc..00000000000 --- a/ntcore/src/main/native/include/networktables/GenericEntry.inc +++ /dev/null @@ -1,214 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include -#include -#include -#include - -#include "networktables/GenericEntry.h" -#include "networktables/NetworkTableType.h" -#include "ntcore_cpp.h" - -namespace nt { - -inline GenericSubscriber::GenericSubscriber(NT_Subscriber handle) - : Subscriber{handle} {} - -inline Value GenericSubscriber::Get() const { - return ::nt::GetEntryValue(m_subHandle); -} - -inline bool GenericSubscriber::GetBoolean(bool defaultValue) const { - return ::nt::GetBoolean(m_subHandle, defaultValue); -} - -inline int64_t GenericSubscriber::GetInteger(int64_t defaultValue) const { - return ::nt::GetInteger(m_subHandle, defaultValue); -} - -inline float GenericSubscriber::GetFloat(float defaultValue) const { - return ::nt::GetFloat(m_subHandle, defaultValue); -} - -inline double GenericSubscriber::GetDouble(double defaultValue) const { - return ::nt::GetDouble(m_subHandle, defaultValue); -} - -inline std::string GenericSubscriber::GetString( - std::string_view defaultValue) const { - return ::nt::GetString(m_subHandle, defaultValue); -} - -inline std::vector GenericSubscriber::GetRaw( - std::span defaultValue) const { - return ::nt::GetRaw(m_subHandle, defaultValue); -} - -inline std::vector GenericSubscriber::GetBooleanArray( - std::span defaultValue) const { - return ::nt::GetBooleanArray(m_subHandle, defaultValue); -} - -inline std::vector GenericSubscriber::GetIntegerArray( - std::span defaultValue) const { - return ::nt::GetIntegerArray(m_subHandle, defaultValue); -} - -inline std::vector GenericSubscriber::GetFloatArray( - std::span defaultValue) const { - return ::nt::GetFloatArray(m_subHandle, defaultValue); -} - -inline std::vector GenericSubscriber::GetDoubleArray( - std::span defaultValue) const { - return ::nt::GetDoubleArray(m_subHandle, defaultValue); -} - -inline std::vector GenericSubscriber::GetStringArray( - std::span defaultValue) const { - return ::nt::GetStringArray(m_subHandle, defaultValue); -} - -inline std::vector GenericSubscriber::ReadQueue() { - return ::nt::ReadQueueValue(m_subHandle); -} - -inline Topic GenericSubscriber::GetTopic() const { - return Topic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline GenericPublisher::GenericPublisher(NT_Publisher handle) - : Publisher{handle} {} - -inline void GenericPublisher::Set(const Value& value) { - ::nt::SetEntryValue(m_pubHandle, value); -} - -inline bool GenericPublisher::SetBoolean(bool value, int64_t time) { - return nt::SetBoolean(m_pubHandle, value, time); -} - -inline bool GenericPublisher::SetInteger(int64_t value, int64_t time) { - return nt::SetInteger(m_pubHandle, value, time); -} - -inline bool GenericPublisher::SetFloat(float value, int64_t time) { - return nt::SetFloat(m_pubHandle, value, time); -} - -inline bool GenericPublisher::SetDouble(double value, int64_t time) { - return nt::SetDouble(m_pubHandle, value, time); -} - -inline bool GenericPublisher::SetString(std::string_view value, int64_t time) { - return nt::SetString(m_pubHandle, value, time); -} - -inline bool GenericPublisher::SetRaw(std::span value, - int64_t time) { - return nt::SetRaw(m_pubHandle, value, time); -} - -inline bool GenericPublisher::SetBooleanArray(std::span value, - int64_t time) { - return SetEntryValue(m_pubHandle, Value::MakeBooleanArray(value, time)); -} - -inline bool GenericPublisher::SetBooleanArray(std::span value, - int64_t time) { - return nt::SetBooleanArray(m_pubHandle, value, time); -} - -inline bool GenericPublisher::SetIntegerArray(std::span value, - int64_t time) { - return nt::SetIntegerArray(m_pubHandle, value, time); -} - -inline bool GenericPublisher::SetFloatArray(std::span value, - int64_t time) { - return nt::SetFloatArray(m_pubHandle, value, time); -} - -inline bool GenericPublisher::SetDoubleArray(std::span value, - int64_t time) { - return nt::SetDoubleArray(m_pubHandle, value, time); -} - -inline bool GenericPublisher::SetStringArray(std::span value, - int64_t time) { - return nt::SetStringArray(m_pubHandle, value, time); -} - -inline void GenericPublisher::SetDefault(const Value& value) { - ::nt::SetDefaultEntryValue(m_pubHandle, value); -} - -inline bool GenericPublisher::SetDefaultBoolean(bool defaultValue) { - return nt::SetDefaultBoolean(m_pubHandle, defaultValue); -} - -inline bool GenericPublisher::SetDefaultInteger(int64_t defaultValue) { - return nt::SetDefaultInteger(m_pubHandle, defaultValue); -} - -inline bool GenericPublisher::SetDefaultFloat(float defaultValue) { - return nt::SetDefaultFloat(m_pubHandle, defaultValue); -} - -inline bool GenericPublisher::SetDefaultDouble(double defaultValue) { - return nt::SetDefaultDouble(m_pubHandle, defaultValue); -} - -inline bool GenericPublisher::SetDefaultString(std::string_view defaultValue) { - return nt::SetDefaultString(m_pubHandle, defaultValue); -} - -inline bool GenericPublisher::SetDefaultRaw( - std::span defaultValue) { - return nt::SetDefaultRaw(m_pubHandle, defaultValue); -} - -inline bool GenericPublisher::SetDefaultBooleanArray( - std::span defaultValue) { - return nt::SetDefaultBooleanArray(m_pubHandle, defaultValue); -} - -inline bool GenericPublisher::SetDefaultIntegerArray( - std::span defaultValue) { - return nt::SetDefaultIntegerArray(m_pubHandle, defaultValue); -} - -inline bool GenericPublisher::SetDefaultFloatArray( - std::span defaultValue) { - return nt::SetDefaultFloatArray(m_pubHandle, defaultValue); -} - -inline bool GenericPublisher::SetDefaultDoubleArray( - std::span defaultValue) { - return nt::SetDefaultDoubleArray(m_pubHandle, defaultValue); -} - -inline bool GenericPublisher::SetDefaultStringArray( - std::span defaultValue) { - return nt::SetDefaultStringArray(m_pubHandle, defaultValue); -} - -inline Topic GenericPublisher::GetTopic() const { - return Topic{::nt::GetTopicFromHandle(m_pubHandle)}; -} - -inline GenericEntry::GenericEntry(NT_Entry handle) - : GenericSubscriber{handle}, GenericPublisher{handle} {} - -inline Topic GenericEntry::GetTopic() const { - return Topic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline void GenericEntry::Unpublish() { - ::nt::Unpublish(m_pubHandle); -} -} // namespace nt diff --git a/ntcore/src/main/native/include/networktables/MultiSubscriber.h b/ntcore/src/main/native/include/networktables/MultiSubscriber.h index f146351b627..85afee58f0f 100644 --- a/ntcore/src/main/native/include/networktables/MultiSubscriber.h +++ b/ntcore/src/main/native/include/networktables/MultiSubscriber.h @@ -30,13 +30,31 @@ class MultiSubscriber final { */ MultiSubscriber(NetworkTableInstance inst, std::span prefixes, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) + : m_handle{::nt::SubscribeMultiple(inst.GetHandle(), prefixes, options)} { + } MultiSubscriber(const MultiSubscriber&) = delete; MultiSubscriber& operator=(const MultiSubscriber&) = delete; - MultiSubscriber(MultiSubscriber&& rhs); - MultiSubscriber& operator=(MultiSubscriber&& rhs); - ~MultiSubscriber(); + + MultiSubscriber(MultiSubscriber&& rhs) : m_handle{rhs.m_handle} { + rhs.m_handle = 0; + } + + MultiSubscriber& operator=(MultiSubscriber&& rhs) { + if (m_handle != 0) { + ::nt::UnsubscribeMultiple(m_handle); + } + m_handle = rhs.m_handle; + rhs.m_handle = 0; + return *this; + } + + ~MultiSubscriber() { + if (m_handle != 0) { + ::nt::UnsubscribeMultiple(m_handle); + } + } /** * Determines if the native handle is valid. @@ -57,5 +75,3 @@ class MultiSubscriber final { }; } // namespace nt - -#include "MultiSubscriber.inc" diff --git a/ntcore/src/main/native/include/networktables/MultiSubscriber.inc b/ntcore/src/main/native/include/networktables/MultiSubscriber.inc deleted file mode 100644 index c32c06a8785..00000000000 --- a/ntcore/src/main/native/include/networktables/MultiSubscriber.inc +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include "networktables/MultiSubscriber.h" - -namespace nt { - -inline MultiSubscriber::MultiSubscriber( - NetworkTableInstance inst, std::span prefixes, - const PubSubOptions& options) - : m_handle{::nt::SubscribeMultiple(inst.GetHandle(), prefixes, options)} {} - -inline MultiSubscriber::MultiSubscriber(MultiSubscriber&& rhs) - : m_handle{rhs.m_handle} { - rhs.m_handle = 0; -} - -inline MultiSubscriber& MultiSubscriber::operator=(MultiSubscriber&& rhs) { - if (m_handle != 0) { - ::nt::UnsubscribeMultiple(m_handle); - } - m_handle = rhs.m_handle; - rhs.m_handle = 0; - return *this; -} - -inline MultiSubscriber::~MultiSubscriber() { - if (m_handle != 0) { - ::nt::UnsubscribeMultiple(m_handle); - } -} - -} // namespace nt diff --git a/ntcore/src/main/native/include/networktables/NetworkTableEntry.h b/ntcore/src/main/native/include/networktables/NetworkTableEntry.h index 6eec8964f36..6b4cd11a85c 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTableEntry.h +++ b/ntcore/src/main/native/include/networktables/NetworkTableEntry.h @@ -6,8 +6,6 @@ #include -#include -#include #include #include #include @@ -15,7 +13,6 @@ #include "networktables/NetworkTableType.h" #include "networktables/NetworkTableValue.h" -#include "ntcore_c.h" #include "ntcore_cpp.h" namespace nt { @@ -36,14 +33,14 @@ class NetworkTableEntry final { /** * Construct invalid instance. */ - NetworkTableEntry(); + NetworkTableEntry() = default; /** * Construct from native handle. * * @param handle Native handle */ - explicit NetworkTableEntry(NT_Entry handle); + explicit NetworkTableEntry(NT_Entry handle) : m_handle{handle} {} /** * Determines if the native handle is valid. @@ -57,7 +54,7 @@ class NetworkTableEntry final { * * @return Native handle */ - NT_Entry GetHandle() const; + NT_Entry GetHandle() const { return m_handle; } /** * Gets the instance for the entry. @@ -71,28 +68,30 @@ class NetworkTableEntry final { * * @return True if the entry exists, false otherwise. */ - bool Exists() const; + bool Exists() const { return GetEntryType(m_handle) != NT_UNASSIGNED; } /** * Gets the name of the entry (the key). * * @return the entry's name */ - std::string GetName() const; + std::string GetName() const { return GetEntryName(m_handle); } /** * Gets the type of the entry. * * @return the entry's type */ - NetworkTableType GetType() const; + NetworkTableType GetType() const { + return static_cast(GetEntryType(m_handle)); + } /** * Gets the last time the entry's value was changed. * * @return Entry last change time */ - int64_t GetLastChange() const; + int64_t GetLastChange() const { return GetEntryLastChange(m_handle); } /** * Gets the entry's value. If the entry does not exist, returns an empty @@ -100,7 +99,7 @@ class NetworkTableEntry final { * * @return the entry's value or an empty value if it does not exist. */ - Value GetValue() const; + Value GetValue() const { return GetEntryValue(m_handle); } /** * Gets the entry's value as a boolean. If the entry does not exist or is of @@ -109,7 +108,9 @@ class NetworkTableEntry final { * @param defaultValue the value to be returned if no value is found * @return the entry's value or the given default value */ - bool GetBoolean(bool defaultValue) const; + bool GetBoolean(bool defaultValue) const { + return nt::GetBoolean(m_handle, defaultValue); + } /** * Gets the entry's value as a integer. If the entry does not exist or is of @@ -118,7 +119,9 @@ class NetworkTableEntry final { * @param defaultValue the value to be returned if no value is found * @return the entry's value or the given default value */ - int64_t GetInteger(int64_t defaultValue) const; + int64_t GetInteger(int64_t defaultValue) const { + return nt::GetInteger(m_handle, defaultValue); + } /** * Gets the entry's value as a float. If the entry does not exist or is of @@ -127,7 +130,9 @@ class NetworkTableEntry final { * @param defaultValue the value to be returned if no value is found * @return the entry's value or the given default value */ - float GetFloat(float defaultValue) const; + float GetFloat(float defaultValue) const { + return nt::GetFloat(m_handle, defaultValue); + } /** * Gets the entry's value as a double. If the entry does not exist or is of @@ -136,7 +141,9 @@ class NetworkTableEntry final { * @param defaultValue the value to be returned if no value is found * @return the entry's value or the given default value */ - double GetDouble(double defaultValue) const; + double GetDouble(double defaultValue) const { + return nt::GetDouble(m_handle, defaultValue); + } /** * Gets the entry's value as a string. If the entry does not exist or is of @@ -145,7 +152,9 @@ class NetworkTableEntry final { * @param defaultValue the value to be returned if no value is found * @return the entry's value or the given default value */ - std::string GetString(std::string_view defaultValue) const; + std::string GetString(std::string_view defaultValue) const { + return nt::GetString(m_handle, defaultValue); + } /** * Gets the entry's value as a raw. If the entry does not exist or is of @@ -154,7 +163,9 @@ class NetworkTableEntry final { * @param defaultValue the value to be returned if no value is found * @return the entry's value or the given default value */ - std::vector GetRaw(std::span defaultValue) const; + std::vector GetRaw(std::span defaultValue) const { + return nt::GetRaw(m_handle, defaultValue); + } /** * Gets the entry's value as a boolean array. If the entry does not exist @@ -170,7 +181,9 @@ class NetworkTableEntry final { * because std::vector is special-cased in C++. 0 is false, any * non-zero value is true. */ - std::vector GetBooleanArray(std::span defaultValue) const; + std::vector GetBooleanArray(std::span defaultValue) const { + return nt::GetBooleanArray(m_handle, defaultValue); + } /** * Gets the entry's value as a integer array. If the entry does not exist @@ -183,7 +196,9 @@ class NetworkTableEntry final { * concern, use GetValue() instead. */ std::vector GetIntegerArray( - std::span defaultValue) const; + std::span defaultValue) const { + return nt::GetIntegerArray(m_handle, defaultValue); + } /** * Gets the entry's value as a float array. If the entry does not exist @@ -195,7 +210,9 @@ class NetworkTableEntry final { * @note This makes a copy of the array. If the overhead of this is a * concern, use GetValue() instead. */ - std::vector GetFloatArray(std::span defaultValue) const; + std::vector GetFloatArray(std::span defaultValue) const { + return nt::GetFloatArray(m_handle, defaultValue); + } /** * Gets the entry's value as a double array. If the entry does not exist @@ -208,7 +225,9 @@ class NetworkTableEntry final { * concern, use GetValue() instead. */ std::vector GetDoubleArray( - std::span defaultValue) const; + std::span defaultValue) const { + return nt::GetDoubleArray(m_handle, defaultValue); + } /** * Gets the entry's value as a string array. If the entry does not exist @@ -221,7 +240,9 @@ class NetworkTableEntry final { * concern, use GetValue() instead. */ std::vector GetStringArray( - std::span defaultValue) const; + std::span defaultValue) const { + return nt::GetStringArray(m_handle, defaultValue); + } /** * Get an array of all value changes since the last call to ReadQueue. @@ -231,7 +252,9 @@ class NetworkTableEntry final { * @return Array of values; empty array if no new changes have been * published since the previous call. */ - std::vector ReadQueue(); + std::vector ReadQueue() { + return nt::ReadQueueValue(m_handle); + } /** * Sets the entry's value if it does not exist. @@ -239,7 +262,9 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultValue(const Value& defaultValue); + bool SetDefaultValue(const Value& defaultValue) { + return SetDefaultEntryValue(m_handle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -247,7 +272,9 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultBoolean(bool defaultValue); + bool SetDefaultBoolean(bool defaultValue) { + return nt::SetDefaultBoolean(m_handle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -255,7 +282,9 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultInteger(int64_t defaultValue); + bool SetDefaultInteger(int64_t defaultValue) { + return nt::SetDefaultInteger(m_handle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -263,7 +292,9 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultFloat(float defaultValue); + bool SetDefaultFloat(float defaultValue) { + return nt::SetDefaultFloat(m_handle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -271,7 +302,9 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultDouble(double defaultValue); + bool SetDefaultDouble(double defaultValue) { + return nt::SetDefaultDouble(m_handle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -279,7 +312,9 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultString(std::string_view defaultValue); + bool SetDefaultString(std::string_view defaultValue) { + return nt::SetDefaultString(m_handle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -287,7 +322,9 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultRaw(std::span defaultValue); + bool SetDefaultRaw(std::span defaultValue) { + return nt::SetDefaultRaw(m_handle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -295,7 +332,9 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultBooleanArray(std::span defaultValue); + bool SetDefaultBooleanArray(std::span defaultValue) { + return nt::SetDefaultBooleanArray(m_handle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -303,7 +342,9 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultIntegerArray(std::span defaultValue); + bool SetDefaultIntegerArray(std::span defaultValue) { + return nt::SetDefaultIntegerArray(m_handle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -311,7 +352,9 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultFloatArray(std::span defaultValue); + bool SetDefaultFloatArray(std::span defaultValue) { + return nt::SetDefaultFloatArray(m_handle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -319,7 +362,9 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultDoubleArray(std::span defaultValue); + bool SetDefaultDoubleArray(std::span defaultValue) { + return nt::SetDefaultDoubleArray(m_handle, defaultValue); + } /** * Sets the entry's value if it does not exist. @@ -327,7 +372,9 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultStringArray(std::span defaultValue); + bool SetDefaultStringArray(std::span defaultValue) { + return nt::SetDefaultStringArray(m_handle, defaultValue); + } /** * Sets the entry's value. @@ -335,7 +382,7 @@ class NetworkTableEntry final { * @param value the value to set * @return False if the entry exists with a different type */ - bool SetValue(const Value& value); + bool SetValue(const Value& value) { return SetEntryValue(m_handle, value); } /** * Sets the entry's value. @@ -344,7 +391,9 @@ class NetworkTableEntry final { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetBoolean(bool value, int64_t time = 0); + bool SetBoolean(bool value, int64_t time = 0) { + return nt::SetBoolean(m_handle, value, time); + } /** * Sets the entry's value. @@ -353,7 +402,9 @@ class NetworkTableEntry final { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetInteger(int64_t value, int64_t time = 0); + bool SetInteger(int64_t value, int64_t time = 0) { + return nt::SetInteger(m_handle, value, time); + } /** * Sets the entry's value. @@ -362,7 +413,9 @@ class NetworkTableEntry final { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetFloat(float value, int64_t time = 0); + bool SetFloat(float value, int64_t time = 0) { + return nt::SetFloat(m_handle, value, time); + } /** * Sets the entry's value. @@ -371,7 +424,9 @@ class NetworkTableEntry final { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetDouble(double value, int64_t time = 0); + bool SetDouble(double value, int64_t time = 0) { + return nt::SetDouble(m_handle, value, time); + } /** * Sets the entry's value. @@ -380,7 +435,9 @@ class NetworkTableEntry final { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetString(std::string_view value, int64_t time = 0); + bool SetString(std::string_view value, int64_t time = 0) { + return nt::SetString(m_handle, value, time); + } /** * Sets the entry's value. @@ -389,7 +446,9 @@ class NetworkTableEntry final { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetRaw(std::span value, int64_t time = 0); + bool SetRaw(std::span value, int64_t time = 0) { + return nt::SetRaw(m_handle, value, time); + } /** * Sets the entry's value. @@ -398,7 +457,9 @@ class NetworkTableEntry final { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetBooleanArray(std::span value, int64_t time = 0); + bool SetBooleanArray(std::span value, int64_t time = 0) { + return SetEntryValue(m_handle, Value::MakeBooleanArray(value, time)); + } /** * Sets the entry's value. @@ -407,7 +468,9 @@ class NetworkTableEntry final { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetBooleanArray(std::span value, int64_t time = 0); + bool SetBooleanArray(std::span value, int64_t time = 0) { + return nt::SetBooleanArray(m_handle, value, time); + } /** * Sets the entry's value. @@ -416,7 +479,9 @@ class NetworkTableEntry final { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetIntegerArray(std::span value, int64_t time = 0); + bool SetIntegerArray(std::span value, int64_t time = 0) { + return nt::SetIntegerArray(m_handle, value, time); + } /** * Sets the entry's value. @@ -425,7 +490,9 @@ class NetworkTableEntry final { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetFloatArray(std::span value, int64_t time = 0); + bool SetFloatArray(std::span value, int64_t time = 0) { + return nt::SetFloatArray(m_handle, value, time); + } /** * Sets the entry's value. @@ -434,7 +501,9 @@ class NetworkTableEntry final { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetDoubleArray(std::span value, int64_t time = 0); + bool SetDoubleArray(std::span value, int64_t time = 0) { + return nt::SetDoubleArray(m_handle, value, time); + } /** * Sets the entry's value. @@ -443,29 +512,37 @@ class NetworkTableEntry final { * @param time the timestamp to set (0 = nt::Now()) * @return False if the entry exists with a different type */ - bool SetStringArray(std::span value, int64_t time = 0); + bool SetStringArray(std::span value, int64_t time = 0) { + return nt::SetStringArray(m_handle, value, time); + } /** * Make value persistent through program restarts. */ - void SetPersistent(); + void SetPersistent() { + nt::SetTopicPersistent(nt::GetTopicFromHandle(m_handle), true); + } /** * Stop making value persistent through program restarts. */ - void ClearPersistent(); + void ClearPersistent() { + nt::SetTopicPersistent(nt::GetTopicFromHandle(m_handle), false); + } /** * Returns whether the value is persistent through program restarts. * * @return True if the value is persistent. */ - bool IsPersistent() const; + bool IsPersistent() const { + return nt::GetTopicPersistent(nt::GetTopicFromHandle(m_handle)); + } /** * Stops publishing the entry if it's been published. */ - void Unpublish(); + void Unpublish() { return nt::Unpublish(m_handle); } /** * Gets the entry's topic. @@ -486,5 +563,3 @@ class NetworkTableEntry final { }; } // namespace nt - -#include "networktables/NetworkTableEntry.inc" diff --git a/ntcore/src/main/native/include/networktables/NetworkTableEntry.inc b/ntcore/src/main/native/include/networktables/NetworkTableEntry.inc deleted file mode 100644 index 0f18e2d445d..00000000000 --- a/ntcore/src/main/native/include/networktables/NetworkTableEntry.inc +++ /dev/null @@ -1,231 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include -#include -#include -#include - -#include "networktables/NetworkTableEntry.h" -#include "ntcore_cpp.h" -#include "ntcore_cpp_types.h" - -namespace nt { - -inline NetworkTableEntry::NetworkTableEntry() {} - -inline NetworkTableEntry::NetworkTableEntry(NT_Entry handle) - : m_handle{handle} {} - -inline NT_Entry NetworkTableEntry::GetHandle() const { - return m_handle; -} - -inline bool NetworkTableEntry::Exists() const { - return GetEntryType(m_handle) != NT_UNASSIGNED; -} - -inline std::string NetworkTableEntry::GetName() const { - return GetEntryName(m_handle); -} - -inline NetworkTableType NetworkTableEntry::GetType() const { - return static_cast(GetEntryType(m_handle)); -} - -inline int64_t NetworkTableEntry::GetLastChange() const { - return GetEntryLastChange(m_handle); -} - -inline Value NetworkTableEntry::GetValue() const { - return GetEntryValue(m_handle); -} - -inline bool NetworkTableEntry::GetBoolean(bool defaultValue) const { - return nt::GetBoolean(m_handle, defaultValue); -} - -inline int64_t NetworkTableEntry::GetInteger(int64_t defaultValue) const { - return nt::GetInteger(m_handle, defaultValue); -} - -inline float NetworkTableEntry::GetFloat(float defaultValue) const { - return nt::GetFloat(m_handle, defaultValue); -} - -inline double NetworkTableEntry::GetDouble(double defaultValue) const { - return nt::GetDouble(m_handle, defaultValue); -} - -inline std::string NetworkTableEntry::GetString( - std::string_view defaultValue) const { - return nt::GetString(m_handle, defaultValue); -} - -inline std::vector NetworkTableEntry::GetRaw( - std::span defaultValue) const { - return nt::GetRaw(m_handle, defaultValue); -} - -inline std::vector NetworkTableEntry::GetBooleanArray( - std::span defaultValue) const { - return nt::GetBooleanArray(m_handle, defaultValue); -} - -inline std::vector NetworkTableEntry::GetIntegerArray( - std::span defaultValue) const { - return nt::GetIntegerArray(m_handle, defaultValue); -} - -inline std::vector NetworkTableEntry::GetFloatArray( - std::span defaultValue) const { - return nt::GetFloatArray(m_handle, defaultValue); -} - -inline std::vector NetworkTableEntry::GetDoubleArray( - std::span defaultValue) const { - return nt::GetDoubleArray(m_handle, defaultValue); -} - -inline std::vector NetworkTableEntry::GetStringArray( - std::span defaultValue) const { - return nt::GetStringArray(m_handle, defaultValue); -} - -inline std::vector NetworkTableEntry::ReadQueue() { - return nt::ReadQueueValue(m_handle); -} - -inline bool NetworkTableEntry::SetDefaultValue(const Value& defaultValue) { - return SetDefaultEntryValue(m_handle, defaultValue); -} - -inline bool NetworkTableEntry::SetDefaultBoolean(bool defaultValue) { - return nt::SetDefaultBoolean(m_handle, defaultValue); -} - -inline bool NetworkTableEntry::SetDefaultInteger(int64_t defaultValue) { - return nt::SetDefaultInteger(m_handle, defaultValue); -} - -inline bool NetworkTableEntry::SetDefaultFloat(float defaultValue) { - return nt::SetDefaultFloat(m_handle, defaultValue); -} - -inline bool NetworkTableEntry::SetDefaultDouble(double defaultValue) { - return nt::SetDefaultDouble(m_handle, defaultValue); -} - -inline bool NetworkTableEntry::SetDefaultString(std::string_view defaultValue) { - return nt::SetDefaultString(m_handle, defaultValue); -} - -inline bool NetworkTableEntry::SetDefaultRaw( - std::span defaultValue) { - return nt::SetDefaultRaw(m_handle, defaultValue); -} - -inline bool NetworkTableEntry::SetDefaultBooleanArray( - std::span defaultValue) { - return nt::SetDefaultBooleanArray(m_handle, defaultValue); -} - -inline bool NetworkTableEntry::SetDefaultIntegerArray( - std::span defaultValue) { - return nt::SetDefaultIntegerArray(m_handle, defaultValue); -} - -inline bool NetworkTableEntry::SetDefaultFloatArray( - std::span defaultValue) { - return nt::SetDefaultFloatArray(m_handle, defaultValue); -} - -inline bool NetworkTableEntry::SetDefaultDoubleArray( - std::span defaultValue) { - return nt::SetDefaultDoubleArray(m_handle, defaultValue); -} - -inline bool NetworkTableEntry::SetDefaultStringArray( - std::span defaultValue) { - return nt::SetDefaultStringArray(m_handle, defaultValue); -} - -inline bool NetworkTableEntry::SetValue(const Value& value) { - return SetEntryValue(m_handle, value); -} - -inline bool NetworkTableEntry::SetBoolean(bool value, int64_t time) { - return nt::SetBoolean(m_handle, value, time); -} - -inline bool NetworkTableEntry::SetInteger(int64_t value, int64_t time) { - return nt::SetInteger(m_handle, value, time); -} - -inline bool NetworkTableEntry::SetFloat(float value, int64_t time) { - return nt::SetFloat(m_handle, value, time); -} - -inline bool NetworkTableEntry::SetDouble(double value, int64_t time) { - return nt::SetDouble(m_handle, value, time); -} - -inline bool NetworkTableEntry::SetString(std::string_view value, int64_t time) { - return nt::SetString(m_handle, value, time); -} - -inline bool NetworkTableEntry::SetRaw(std::span value, - int64_t time) { - return nt::SetRaw(m_handle, value, time); -} - -inline bool NetworkTableEntry::SetBooleanArray(std::span value, - int64_t time) { - return SetEntryValue(m_handle, Value::MakeBooleanArray(value, time)); -} - -inline bool NetworkTableEntry::SetBooleanArray(std::span value, - int64_t time) { - return nt::SetBooleanArray(m_handle, value, time); -} - -inline bool NetworkTableEntry::SetIntegerArray(std::span value, - int64_t time) { - return nt::SetIntegerArray(m_handle, value, time); -} - -inline bool NetworkTableEntry::SetFloatArray(std::span value, - int64_t time) { - return nt::SetFloatArray(m_handle, value, time); -} - -inline bool NetworkTableEntry::SetDoubleArray(std::span value, - int64_t time) { - return nt::SetDoubleArray(m_handle, value, time); -} - -inline bool NetworkTableEntry::SetStringArray( - std::span value, int64_t time) { - return nt::SetStringArray(m_handle, value, time); -} - -inline void NetworkTableEntry::SetPersistent() { - nt::SetTopicPersistent(nt::GetTopicFromHandle(m_handle), true); -} - -inline void NetworkTableEntry::ClearPersistent() { - nt::SetTopicPersistent(nt::GetTopicFromHandle(m_handle), false); -} - -inline bool NetworkTableEntry::IsPersistent() const { - return nt::GetTopicPersistent(nt::GetTopicFromHandle(m_handle)); -} - -inline void NetworkTableEntry::Unpublish() { - return nt::Unpublish(m_handle); -} - -} // namespace nt diff --git a/ntcore/src/main/native/include/networktables/NetworkTableInstance.h b/ntcore/src/main/native/include/networktables/NetworkTableInstance.h index 60cf7841de8..bd522f70168 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTableInstance.h +++ b/ntcore/src/main/native/include/networktables/NetworkTableInstance.h @@ -4,11 +4,9 @@ #pragma once -#include #include #include #include -#include #include #include #include @@ -109,14 +107,14 @@ class NetworkTableInstance final { /** * Construct invalid instance. */ - NetworkTableInstance() noexcept; + NetworkTableInstance() noexcept = default; /** * Construct from native handle. * - * @param inst Native handle + * @param handle Native handle */ - explicit NetworkTableInstance(NT_Inst inst) noexcept; + explicit NetworkTableInstance(NT_Inst handle) noexcept : m_handle{handle} {} /** * Determines if the native handle is valid. @@ -130,28 +128,37 @@ class NetworkTableInstance final { * * @return Global default instance */ - static NetworkTableInstance GetDefault(); + static NetworkTableInstance GetDefault() { + return NetworkTableInstance{GetDefaultInstance()}; + } /** * Create an instance. * * @return Newly created instance */ - static NetworkTableInstance Create(); + static NetworkTableInstance Create() { + return NetworkTableInstance{CreateInstance()}; + } /** * Destroys an instance (note: this has global effect). * * @param inst Instance */ - static void Destroy(NetworkTableInstance& inst); + static void Destroy(NetworkTableInstance& inst) { + if (inst.m_handle != 0) { + DestroyInstance(inst.m_handle); + inst.m_handle = 0; + } + } /** * Gets the native handle for the entry. * * @return Native handle */ - NT_Inst GetHandle() const; + NT_Inst GetHandle() const { return m_handle; } /** * Gets a "generic" (untyped) topic. @@ -256,7 +263,9 @@ class NetworkTableInstance final { * @return Topic */ template - ProtobufTopic GetProtobufTopic(std::string_view name) const; + ProtobufTopic GetProtobufTopic(std::string_view name) const { + return ProtobufTopic{GetTopic(name)}; + } /** * Gets a raw struct serialized value topic. @@ -267,7 +276,9 @@ class NetworkTableInstance final { */ template requires wpi::StructSerializable - StructTopic GetStructTopic(std::string_view name, I... info) const; + StructTopic GetStructTopic(std::string_view name, I... info) const { + return StructTopic{GetTopic(name), std::move(info)...}; + } /** * Gets a raw struct serialized array topic. @@ -279,7 +290,9 @@ class NetworkTableInstance final { template requires wpi::StructSerializable StructArrayTopic GetStructArrayTopic(std::string_view name, - I... info) const; + I... info) const { + return StructArrayTopic{GetTopic(name), std::move(info)...}; + } /** * Get Published Topics. @@ -288,7 +301,10 @@ class NetworkTableInstance final { * * @return Array of topics. */ - std::vector GetTopics(); + std::vector GetTopics() { + auto handles = ::nt::GetTopics(m_handle, "", 0); + return {handles.begin(), handles.end()}; + } /** * Get Published Topics. @@ -300,7 +316,10 @@ class NetworkTableInstance final { * starts with this string are returned * @return Array of topics. */ - std::vector GetTopics(std::string_view prefix); + std::vector GetTopics(std::string_view prefix) { + auto handles = ::nt::GetTopics(m_handle, prefix, 0); + return {handles.begin(), handles.end()}; + } /** * Get Published Topics. @@ -314,7 +333,10 @@ class NetworkTableInstance final { * as a "don't care" * @return Array of topics. */ - std::vector GetTopics(std::string_view prefix, unsigned int types); + std::vector GetTopics(std::string_view prefix, unsigned int types) { + auto handles = ::nt::GetTopics(m_handle, prefix, types); + return {handles.begin(), handles.end()}; + } /** * Get Published Topics. @@ -328,7 +350,10 @@ class NetworkTableInstance final { * @return Array of topic handles. */ std::vector GetTopics(std::string_view prefix, - std::span types); + std::span types) { + auto handles = ::nt::GetTopics(m_handle, prefix, types); + return {handles.begin(), handles.end()}; + } /** * Get Topic Information about multiple topics. @@ -337,7 +362,9 @@ class NetworkTableInstance final { * * @return Array of topic information. */ - std::vector GetTopicInfo(); + std::vector GetTopicInfo() { + return ::nt::GetTopicInfo(m_handle, "", 0); + } /** * Get Topic Information about multiple topics. @@ -350,7 +377,9 @@ class NetworkTableInstance final { * starts with this string are returned * @return Array of topic information. */ - std::vector GetTopicInfo(std::string_view prefix); + std::vector GetTopicInfo(std::string_view prefix) { + return ::nt::GetTopicInfo(m_handle, prefix, 0); + } /** * Get Topic Information about multiple topics. @@ -366,7 +395,9 @@ class NetworkTableInstance final { * @return Array of topic information. */ std::vector GetTopicInfo(std::string_view prefix, - unsigned int types); + unsigned int types) { + return ::nt::GetTopicInfo(m_handle, prefix, types); + } /** * Get Topic Information about multiple topics. @@ -381,7 +412,9 @@ class NetworkTableInstance final { * @return Array of topic information. */ std::vector GetTopicInfo(std::string_view prefix, - std::span types); + std::span types) { + return ::nt::GetTopicInfo(m_handle, prefix, types); + } /** * Gets the entry for a key. @@ -389,7 +422,9 @@ class NetworkTableInstance final { * @param name Key * @return Network table entry. */ - NetworkTableEntry GetEntry(std::string_view name); + NetworkTableEntry GetEntry(std::string_view name) { + return NetworkTableEntry{::nt::GetEntry(m_handle, name)}; + } /** * Gets the table with the specified key. @@ -409,7 +444,9 @@ class NetworkTableInstance final { * * @param listener Listener handle to remove */ - static void RemoveListener(NT_Listener listener); + static void RemoveListener(NT_Listener listener) { + ::nt::RemoveListener(listener); + } /** * Wait for the listener queue to be empty. This is primarily @@ -421,7 +458,9 @@ class NetworkTableInstance final { * a negative value to block indefinitely * @return False if timed out, otherwise true. */ - bool WaitForListenerQueue(double timeout); + bool WaitForListenerQueue(double timeout) { + return ::nt::WaitForListenerQueue(m_handle, timeout); + } /** * Add a connection listener. The callback function is called asynchronously @@ -433,7 +472,12 @@ class NetworkTableInstance final { * @return Listener handle */ NT_Listener AddConnectionListener(bool immediate_notify, - ListenerCallback callback) const; + ListenerCallback callback) const { + return ::nt::AddListener( + m_handle, + NT_EVENT_CONNECTION | (immediate_notify ? NT_EVENT_IMMEDIATE : 0), + std::move(callback)); + } /** * Add a time synchronization listener. The callback function is called @@ -447,7 +491,12 @@ class NetworkTableInstance final { * @return Listener handle */ NT_Listener AddTimeSyncListener(bool immediate_notify, - ListenerCallback callback) const; + ListenerCallback callback) const { + return ::nt::AddListener( + m_handle, + NT_EVENT_TIMESYNC | (immediate_notify ? NT_EVENT_IMMEDIATE : 0), + std::move(callback)); + } /** * Add a listener for changes on a particular topic. The callback @@ -523,7 +572,10 @@ class NetworkTableInstance final { * @return Listener handle */ NT_Listener AddListener(std::span prefixes, - int eventMask, ListenerCallback listener); + int eventMask, ListenerCallback listener) { + return ::nt::AddListener(m_handle, prefixes, eventMask, + std::move(listener)); + } /** @} */ @@ -537,20 +589,20 @@ class NetworkTableInstance final { * * @return Bitmask of NetworkMode. */ - unsigned int GetNetworkMode() const; + unsigned int GetNetworkMode() const { return ::nt::GetNetworkMode(m_handle); } /** * Starts local-only operation. Prevents calls to StartServer or StartClient * from taking effect. Has no effect if StartServer or StartClient * has already been called. */ - void StartLocal(); + void StartLocal() { ::nt::StartLocal(m_handle); } /** * Stops local-only operation. StartServer or StartClient can be called after * this call to start a server or client. */ - void StopLocal(); + void StopLocal() { ::nt::StopLocal(m_handle); } /** * Starts a server using the specified filename, listening address, and port. @@ -565,12 +617,14 @@ class NetworkTableInstance final { void StartServer(std::string_view persist_filename = "networktables.json", const char* listen_address = "", unsigned int port3 = kDefaultPort3, - unsigned int port4 = kDefaultPort4); + unsigned int port4 = kDefaultPort4) { + ::nt::StartServer(m_handle, persist_filename, listen_address, port3, port4); + } /** * Stops the server if it is running. */ - void StopServer(); + void StopServer() { ::nt::StopServer(m_handle); } /** * Starts a NT3 client. Use SetServer or SetServerTeam to set the server name @@ -578,7 +632,9 @@ class NetworkTableInstance final { * * @param identity network identity to advertise (cannot be empty string) */ - void StartClient3(std::string_view identity); + void StartClient3(std::string_view identity) { + ::nt::StartClient3(m_handle, identity); + } /** * Starts a NT4 client. Use SetServer or SetServerTeam to set the server name @@ -586,12 +642,14 @@ class NetworkTableInstance final { * * @param identity network identity to advertise (cannot be empty string) */ - void StartClient4(std::string_view identity); + void StartClient4(std::string_view identity) { + ::nt::StartClient4(m_handle, identity); + } /** * Stops the client if it is running. */ - void StopClient(); + void StopClient() { ::nt::StopClient(m_handle); } /** * Sets server address and port for client (without restarting client). @@ -599,7 +657,9 @@ class NetworkTableInstance final { * @param server_name server name (UTF-8 string) * @param port port to communicate over (0 = default) */ - void SetServer(std::string_view server_name, unsigned int port = 0); + void SetServer(std::string_view server_name, unsigned int port = 0) { + ::nt::SetServer(m_handle, server_name, port); + } /** * Sets server addresses and ports for client (without restarting client). @@ -608,7 +668,9 @@ class NetworkTableInstance final { * @param servers array of server address and port pairs */ void SetServer( - std::span> servers); + std::span> servers) { + ::nt::SetServer(m_handle, servers); + } /** * Sets server addresses and port for client (without restarting client). @@ -627,13 +689,15 @@ class NetworkTableInstance final { * @param team team number * @param port port to communicate over (0 = default) */ - void SetServerTeam(unsigned int team, unsigned int port = 0); + void SetServerTeam(unsigned int team, unsigned int port = 0) { + ::nt::SetServerTeam(m_handle, team, port); + } /** * Disconnects the client if it's running and connected. This will * automatically start reconnection attempts to the current server list. */ - void Disconnect(); + void Disconnect() { ::nt::Disconnect(m_handle); } /** * Starts requesting server address from Driver Station. @@ -642,18 +706,20 @@ class NetworkTableInstance final { * * @param port server port to use in combination with IP from DS (0 = default) */ - void StartDSClient(unsigned int port = 0); + void StartDSClient(unsigned int port = 0) { + ::nt::StartDSClient(m_handle, port); + } /** * Stops requesting server address from Driver Station. */ - void StopDSClient(); + void StopDSClient() { ::nt::StopDSClient(m_handle); } /** * Flushes all updated values immediately to the local client/server. This * does not flush to the network. */ - void FlushLocal() const; + void FlushLocal() const { ::nt::FlushLocal(m_handle); } /** * Flushes all updated values immediately to the network. @@ -661,7 +727,7 @@ class NetworkTableInstance final { * This is primarily useful for synchronizing network updates with * user code. */ - void Flush() const; + void Flush() const { ::nt::Flush(m_handle); } /** * Get information on the currently established network connections. @@ -669,14 +735,16 @@ class NetworkTableInstance final { * * @return array of connection information */ - std::vector GetConnections() const; + std::vector GetConnections() const { + return ::nt::GetConnections(m_handle); + } /** * Return whether or not the instance is connected to another node. * * @return True if connected. */ - bool IsConnected() const; + bool IsConnected() const { return ::nt::IsConnected(m_handle); } /** * Get the time offset between server time and local time. Add this value to @@ -689,7 +757,9 @@ class NetworkTableInstance final { * * @return Time offset in microseconds (optional) */ - std::optional GetServerTimeOffset() const; + std::optional GetServerTimeOffset() const { + return ::nt::GetServerTimeOffset(m_handle); + } /** @} */ @@ -710,14 +780,18 @@ class NetworkTableInstance final { */ NT_DataLogger StartEntryDataLog(wpi::log::DataLog& log, std::string_view prefix, - std::string_view logPrefix); + std::string_view logPrefix) { + return ::nt::StartEntryDataLog(m_handle, log, prefix, logPrefix); + } /** * Stops logging entry changes to a DataLog. * * @param logger data logger handle */ - static void StopEntryDataLog(NT_DataLogger logger); + static void StopEntryDataLog(NT_DataLogger logger) { + ::nt::StopEntryDataLog(logger); + } /** * Starts logging connection changes to a DataLog. @@ -728,14 +802,18 @@ class NetworkTableInstance final { * @return Data logger handle */ NT_ConnectionDataLogger StartConnectionDataLog(wpi::log::DataLog& log, - std::string_view name); + std::string_view name) { + return ::nt::StartConnectionDataLog(m_handle, log, name); + } /** * Stops logging connection changes to a DataLog. * * @param logger data logger handle */ - static void StopConnectionDataLog(NT_ConnectionDataLogger logger); + static void StopConnectionDataLog(NT_ConnectionDataLogger logger) { + ::nt::StopConnectionDataLog(logger); + } /** @} */ @@ -757,7 +835,9 @@ class NetworkTableInstance final { * @return Listener handle */ NT_Listener AddLogger(unsigned int minLevel, unsigned int maxLevel, - ListenerCallback func); + ListenerCallback func) { + return ::nt::AddLogger(m_handle, minLevel, maxLevel, std::move(func)); + } /** @} */ @@ -775,7 +855,9 @@ class NetworkTableInstance final { * schema) * @return True if schema already registered */ - bool HasSchema(std::string_view name) const; + bool HasSchema(std::string_view name) const { + return ::nt::HasSchema(m_handle, name); + } /** * Registers a data schema. Data schemas provide information for how a @@ -792,7 +874,9 @@ class NetworkTableInstance final { * @param schema Schema data */ void AddSchema(std::string_view name, std::string_view type, - std::span schema); + std::span schema) { + ::nt::AddSchema(m_handle, name, type, schema); + } /** * Registers a data schema. Data schemas provide information for how a @@ -809,7 +893,15 @@ class NetworkTableInstance final { * @param schema Schema data */ void AddSchema(std::string_view name, std::string_view type, - std::string_view schema); + std::string_view schema) { + ::nt::AddSchema(m_handle, name, type, schema); + } + +// Suppress unused-lambda-capture warning on AddSchema() call +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-lambda-capture" +#endif /** * Registers a protobuf schema. Duplicate calls to this function with the same @@ -819,7 +911,13 @@ class NetworkTableInstance final { * @param msg protobuf message */ template - void AddProtobufSchema(wpi::ProtobufMessage& msg); + void AddProtobufSchema(wpi::ProtobufMessage& msg) { + msg.ForEachProtobufDescriptor( + [this](auto typeString) { return HasSchema(typeString); }, + [this](auto typeString, auto schema) { + AddSchema(typeString, "proto:FileDescriptorProto", schema); + }); + } /** * Registers a struct schema. Duplicate calls to this function with the same @@ -830,7 +928,17 @@ class NetworkTableInstance final { */ template requires wpi::StructSerializable - void AddStructSchema(const I&... info); + void AddStructSchema(const I&... info) { + wpi::ForEachStructSchema( + [this](auto typeString, auto schema) { + AddSchema(typeString, "structschema", schema); + }, + info...); + } + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif /** * Equality operator. Returns true if both instances refer to the same @@ -844,5 +952,3 @@ class NetworkTableInstance final { }; } // namespace nt - -#include "networktables/NetworkTableInstance.inc" diff --git a/ntcore/src/main/native/include/networktables/NetworkTableInstance.inc b/ntcore/src/main/native/include/networktables/NetworkTableInstance.inc deleted file mode 100644 index 20b5c0b58ae..00000000000 --- a/ntcore/src/main/native/include/networktables/NetworkTableInstance.inc +++ /dev/null @@ -1,291 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include -#include -#include - -#include "networktables/NetworkTableInstance.h" -#include "networktables/Topic.h" -#include "ntcore_c.h" - -namespace nt { - -inline NetworkTableInstance::NetworkTableInstance() noexcept {} - -inline NetworkTableInstance::NetworkTableInstance(NT_Inst handle) noexcept - : m_handle{handle} {} - -inline NetworkTableInstance NetworkTableInstance::GetDefault() { - return NetworkTableInstance{GetDefaultInstance()}; -} - -inline NetworkTableInstance NetworkTableInstance::Create() { - return NetworkTableInstance{CreateInstance()}; -} - -inline void NetworkTableInstance::Destroy(NetworkTableInstance& inst) { - if (inst.m_handle != 0) { - DestroyInstance(inst.m_handle); - inst.m_handle = 0; - } -} - -inline NT_Inst NetworkTableInstance::GetHandle() const { - return m_handle; -} - -template -inline ProtobufTopic NetworkTableInstance::GetProtobufTopic( - std::string_view name) const { - return ProtobufTopic{GetTopic(name)}; -} - -template - requires wpi::StructSerializable -inline StructTopic NetworkTableInstance::GetStructTopic( - std::string_view name, I... info) const { - return StructTopic{GetTopic(name), std::move(info)...}; -} - -template - requires wpi::StructSerializable -inline StructArrayTopic NetworkTableInstance::GetStructArrayTopic( - std::string_view name, I... info) const { - return StructArrayTopic{GetTopic(name), std::move(info)...}; -} - -inline std::vector NetworkTableInstance::GetTopics() { - auto handles = ::nt::GetTopics(m_handle, "", 0); - return {handles.begin(), handles.end()}; -} - -inline std::vector NetworkTableInstance::GetTopics( - std::string_view prefix) { - auto handles = ::nt::GetTopics(m_handle, prefix, 0); - return {handles.begin(), handles.end()}; -} - -inline std::vector NetworkTableInstance::GetTopics( - std::string_view prefix, unsigned int types) { - auto handles = ::nt::GetTopics(m_handle, prefix, types); - return {handles.begin(), handles.end()}; -} - -inline std::vector NetworkTableInstance::GetTopics( - std::string_view prefix, std::span types) { - auto handles = ::nt::GetTopics(m_handle, prefix, types); - return {handles.begin(), handles.end()}; -} - -inline std::vector NetworkTableInstance::GetTopicInfo() { - return ::nt::GetTopicInfo(m_handle, "", 0); -} - -inline std::vector NetworkTableInstance::GetTopicInfo( - std::string_view prefix) { - return ::nt::GetTopicInfo(m_handle, prefix, 0); -} - -inline std::vector NetworkTableInstance::GetTopicInfo( - std::string_view prefix, unsigned int types) { - return ::nt::GetTopicInfo(m_handle, prefix, types); -} - -inline std::vector NetworkTableInstance::GetTopicInfo( - std::string_view prefix, std::span types) { - return ::nt::GetTopicInfo(m_handle, prefix, types); -} - -inline NetworkTableEntry NetworkTableInstance::GetEntry(std::string_view name) { - return NetworkTableEntry{::nt::GetEntry(m_handle, name)}; -} - -inline bool NetworkTableInstance::WaitForListenerQueue(double timeout) { - return ::nt::WaitForListenerQueue(m_handle, timeout); -} - -inline void NetworkTableInstance::RemoveListener(NT_Listener listener) { - ::nt::RemoveListener(listener); -} - -inline NT_Listener NetworkTableInstance::AddConnectionListener( - bool immediate_notify, ListenerCallback callback) const { - return ::nt::AddListener( - m_handle, - NT_EVENT_CONNECTION | (immediate_notify ? NT_EVENT_IMMEDIATE : 0), - std::move(callback)); -} - -inline NT_Listener NetworkTableInstance::AddTimeSyncListener( - bool immediate_notify, ListenerCallback callback) const { - return ::nt::AddListener( - m_handle, NT_EVENT_TIMESYNC | (immediate_notify ? NT_EVENT_IMMEDIATE : 0), - std::move(callback)); -} - -inline NT_Listener NetworkTableInstance::AddListener( - std::span prefixes, int eventMask, - ListenerCallback listener) { - return ::nt::AddListener(m_handle, prefixes, eventMask, std::move(listener)); -} - -inline unsigned int NetworkTableInstance::GetNetworkMode() const { - return ::nt::GetNetworkMode(m_handle); -} - -inline void NetworkTableInstance::StartLocal() { - ::nt::StartLocal(m_handle); -} - -inline void NetworkTableInstance::StopLocal() { - ::nt::StopLocal(m_handle); -} - -inline void NetworkTableInstance::StartServer(std::string_view persist_filename, - const char* listen_address, - unsigned int port3, - unsigned int port4) { - ::nt::StartServer(m_handle, persist_filename, listen_address, port3, port4); -} - -inline void NetworkTableInstance::StopServer() { - ::nt::StopServer(m_handle); -} - -inline void NetworkTableInstance::StartClient3(std::string_view identity) { - ::nt::StartClient3(m_handle, identity); -} - -inline void NetworkTableInstance::StartClient4(std::string_view identity) { - ::nt::StartClient4(m_handle, identity); -} - -inline void NetworkTableInstance::StopClient() { - ::nt::StopClient(m_handle); -} - -inline void NetworkTableInstance::SetServer(std::string_view server_name, - unsigned int port) { - ::nt::SetServer(m_handle, server_name, port); -} - -inline void NetworkTableInstance::SetServer( - std::span> servers) { - ::nt::SetServer(m_handle, servers); -} - -inline void NetworkTableInstance::SetServerTeam(unsigned int team, - unsigned int port) { - ::nt::SetServerTeam(m_handle, team, port); -} - -inline void NetworkTableInstance::Disconnect() { - ::nt::Disconnect(m_handle); -} - -inline void NetworkTableInstance::StartDSClient(unsigned int port) { - ::nt::StartDSClient(m_handle, port); -} - -inline void NetworkTableInstance::StopDSClient() { - ::nt::StopDSClient(m_handle); -} - -inline void NetworkTableInstance::FlushLocal() const { - ::nt::FlushLocal(m_handle); -} - -inline void NetworkTableInstance::Flush() const { - ::nt::Flush(m_handle); -} - -inline std::vector NetworkTableInstance::GetConnections() - const { - return ::nt::GetConnections(m_handle); -} - -inline bool NetworkTableInstance::IsConnected() const { - return ::nt::IsConnected(m_handle); -} - -inline std::optional NetworkTableInstance::GetServerTimeOffset() - const { - return ::nt::GetServerTimeOffset(m_handle); -} - -inline NT_DataLogger NetworkTableInstance::StartEntryDataLog( - wpi::log::DataLog& log, std::string_view prefix, - std::string_view logPrefix) { - return ::nt::StartEntryDataLog(m_handle, log, prefix, logPrefix); -} - -inline void NetworkTableInstance::StopEntryDataLog(NT_DataLogger logger) { - ::nt::StopEntryDataLog(logger); -} - -inline NT_ConnectionDataLogger NetworkTableInstance::StartConnectionDataLog( - wpi::log::DataLog& log, std::string_view name) { - return ::nt::StartConnectionDataLog(m_handle, log, name); -} - -inline void NetworkTableInstance::StopConnectionDataLog( - NT_ConnectionDataLogger logger) { - ::nt::StopConnectionDataLog(logger); -} - -inline NT_Listener NetworkTableInstance::AddLogger(unsigned int min_level, - unsigned int max_level, - ListenerCallback func) { - return ::nt::AddLogger(m_handle, min_level, max_level, std::move(func)); -} - -inline bool NetworkTableInstance::HasSchema(std::string_view name) const { - return ::nt::HasSchema(m_handle, name); -} - -inline void NetworkTableInstance::AddSchema(std::string_view name, - std::string_view type, - std::span schema) { - ::nt::AddSchema(m_handle, name, type, schema); -} - -inline void NetworkTableInstance::AddSchema(std::string_view name, - std::string_view type, - std::string_view schema) { - ::nt::AddSchema(m_handle, name, type, schema); -} - -// Suppress unused-lambda-capture warning on AddSchema() call -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-lambda-capture" -#endif - -template -void NetworkTableInstance::AddProtobufSchema(wpi::ProtobufMessage& msg) { - msg.ForEachProtobufDescriptor( - [this](auto typeString) { return HasSchema(typeString); }, - [this](auto typeString, auto schema) { - AddSchema(typeString, "proto:FileDescriptorProto", schema); - }); -} - -template - requires wpi::StructSerializable -void NetworkTableInstance::AddStructSchema(const I&... info) { - wpi::ForEachStructSchema( - [this](auto typeString, auto schema) { - AddSchema(typeString, "structschema", schema); - }, - info...); -} - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -} // namespace nt diff --git a/ntcore/src/main/native/include/networktables/NetworkTableListener.h b/ntcore/src/main/native/include/networktables/NetworkTableListener.h index 1a8cf1fa46a..fc0cf65e600 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTableListener.h +++ b/ntcore/src/main/native/include/networktables/NetworkTableListener.h @@ -4,11 +4,15 @@ #pragma once -#include #include #include +#include #include +#include "networktables/MultiSubscriber.h" +#include "networktables/NetworkTableEntry.h" +#include "networktables/NetworkTableInstance.h" +#include "networktables/Topic.h" #include "ntcore_cpp.h" namespace nt { @@ -42,7 +46,10 @@ class NetworkTableListener final { */ static NetworkTableListener CreateListener( NetworkTableInstance inst, std::span prefixes, - unsigned int mask, ListenerCallback listener); + unsigned int mask, ListenerCallback listener) { + return NetworkTableListener{::nt::AddListener(inst.GetHandle(), prefixes, + mask, std::move(listener))}; + } /** * Create a listener for changes on a particular topic. This creates a @@ -54,7 +61,10 @@ class NetworkTableListener final { * @return Listener */ static NetworkTableListener CreateListener(Topic topic, unsigned int mask, - ListenerCallback listener); + ListenerCallback listener) { + return NetworkTableListener{ + nt::AddListener(topic.GetHandle(), mask, std::move(listener))}; + } /** * Create a listener for topic changes on a subscriber. This does NOT keep the @@ -67,7 +77,10 @@ class NetworkTableListener final { */ static NetworkTableListener CreateListener(Subscriber& subscriber, unsigned int mask, - ListenerCallback listener); + ListenerCallback listener) { + return NetworkTableListener{ + ::nt::AddListener(subscriber.GetHandle(), mask, std::move(listener))}; + } /** * Create a listener for topic changes on a subscriber. This does NOT keep the @@ -80,7 +93,10 @@ class NetworkTableListener final { */ static NetworkTableListener CreateListener(MultiSubscriber& subscriber, unsigned int mask, - ListenerCallback listener); + ListenerCallback listener) { + return NetworkTableListener{ + ::nt::AddListener(subscriber.GetHandle(), mask, std::move(listener))}; + } /** * Create a listener for topic changes on an entry. @@ -92,7 +108,10 @@ class NetworkTableListener final { */ static NetworkTableListener CreateListener(NetworkTableEntry& entry, unsigned int mask, - ListenerCallback listener); + ListenerCallback listener) { + return NetworkTableListener{ + ::nt::AddListener(entry.GetHandle(), mask, std::move(listener))}; + } /** * Create a connection listener. @@ -104,7 +123,12 @@ class NetworkTableListener final { */ static NetworkTableListener CreateConnectionListener( NetworkTableInstance inst, bool immediate_notify, - ListenerCallback listener); + ListenerCallback listener) { + return NetworkTableListener{::nt::AddListener( + inst.GetHandle(), + NT_EVENT_CONNECTION | (immediate_notify ? NT_EVENT_IMMEDIATE : 0), + std::move(listener))}; + } /** * Create a time synchronization listener. @@ -115,9 +139,14 @@ class NetworkTableListener final { * @param listener listener function * @return Listener */ - static NetworkTableListener CreateTimeSyncListener(NetworkTableInstance inst, - bool immediate_notify, - ListenerCallback listener); + static NetworkTableListener CreateTimeSyncListener( + NetworkTableInstance inst, bool immediate_notify, + ListenerCallback listener) { + return NetworkTableListener{::nt::AddListener( + inst.GetHandle(), + NT_EVENT_TIMESYNC | (immediate_notify ? NT_EVENT_IMMEDIATE : 0), + std::move(listener))}; + } /** * Create a listener for log messages. By default, log messages are sent to @@ -136,13 +165,32 @@ class NetworkTableListener final { static NetworkTableListener CreateLogger(NetworkTableInstance inst, unsigned int minLevel, unsigned int maxLevel, - ListenerCallback listener); + ListenerCallback listener) { + return NetworkTableListener{::nt::AddLogger(inst.GetHandle(), minLevel, + maxLevel, std::move(listener))}; + } NetworkTableListener(const NetworkTableListener&) = delete; NetworkTableListener& operator=(const NetworkTableListener&) = delete; - NetworkTableListener(NetworkTableListener&& rhs); - NetworkTableListener& operator=(NetworkTableListener&& rhs); - ~NetworkTableListener(); + + NetworkTableListener(NetworkTableListener&& rhs) : m_handle(rhs.m_handle) { + rhs.m_handle = 0; + } + + NetworkTableListener& operator=(NetworkTableListener&& rhs) { + if (m_handle != 0) { + nt::RemoveListener(m_handle); + } + m_handle = rhs.m_handle; + rhs.m_handle = 0; + return *this; + } + + ~NetworkTableListener() { + if (m_handle != 0) { + nt::RemoveListener(m_handle); + } + } explicit operator bool() const { return m_handle != 0; } @@ -163,7 +211,13 @@ class NetworkTableListener final { * a negative value to block indefinitely * @return False if timed out, otherwise true. */ - bool WaitForQueue(double timeout); + bool WaitForQueue(double timeout) { + if (m_handle != 0) { + return nt::WaitForListenerQueue(m_handle, timeout); + } else { + return false; + } + } private: explicit NetworkTableListener(NT_Listener handle) : m_handle{handle} {} @@ -185,14 +239,32 @@ class NetworkTableListenerPoller final { * * @param inst Instance */ - explicit NetworkTableListenerPoller(NetworkTableInstance inst); + explicit NetworkTableListenerPoller(NetworkTableInstance inst) + : m_handle(nt::CreateListenerPoller(inst.GetHandle())) {} NetworkTableListenerPoller(const NetworkTableListenerPoller&) = delete; NetworkTableListenerPoller& operator=(const NetworkTableListenerPoller&) = delete; - NetworkTableListenerPoller(NetworkTableListenerPoller&& rhs); - NetworkTableListenerPoller& operator=(NetworkTableListenerPoller&& rhs); - ~NetworkTableListenerPoller(); + + NetworkTableListenerPoller(NetworkTableListenerPoller&& rhs) + : m_handle(rhs.m_handle) { + rhs.m_handle = 0; + } + + NetworkTableListenerPoller& operator=(NetworkTableListenerPoller&& rhs) { + if (m_handle != 0) { + nt::DestroyListenerPoller(m_handle); + } + m_handle = rhs.m_handle; + rhs.m_handle = 0; + return *this; + } + + ~NetworkTableListenerPoller() { + if (m_handle != 0) { + nt::DestroyListenerPoller(m_handle); + } + } explicit operator bool() const { return m_handle != 0; } @@ -213,7 +285,9 @@ class NetworkTableListenerPoller final { * @return Listener handle */ NT_Listener AddListener(std::span prefixes, - unsigned int mask); + unsigned int mask) { + return nt::AddPolledListener(m_handle, prefixes, mask); + } /** * Start listening to changes to a particular topic. This creates a @@ -223,7 +297,9 @@ class NetworkTableListenerPoller final { * @param mask Bitmask of EventFlags values * @return Listener handle */ - NT_Listener AddListener(Topic topic, unsigned int mask); + NT_Listener AddListener(Topic topic, unsigned int mask) { + return ::nt::AddPolledListener(m_handle, topic.GetHandle(), mask); + } /** * Start listening to topic changes on a subscriber. This does NOT keep the @@ -233,7 +309,9 @@ class NetworkTableListenerPoller final { * @param mask Bitmask of EventFlags values * @return Listener handle */ - NT_Listener AddListener(Subscriber& subscriber, unsigned int mask); + NT_Listener AddListener(Subscriber& subscriber, unsigned int mask) { + return ::nt::AddPolledListener(m_handle, subscriber.GetHandle(), mask); + } /** * Start listening to topic changes on a subscriber. This does NOT keep the @@ -243,7 +321,9 @@ class NetworkTableListenerPoller final { * @param mask Bitmask of EventFlags values * @return Listener handle */ - NT_Listener AddListener(MultiSubscriber& subscriber, unsigned int mask); + NT_Listener AddListener(MultiSubscriber& subscriber, unsigned int mask) { + return ::nt::AddPolledListener(m_handle, subscriber.GetHandle(), mask); + } /** * Start listening to topic changes on an entry. @@ -252,7 +332,9 @@ class NetworkTableListenerPoller final { * @param mask Bitmask of EventFlags values * @return Listener handle */ - NT_Listener AddListener(NetworkTableEntry& entry, unsigned int mask); + NT_Listener AddListener(NetworkTableEntry& entry, unsigned int mask) { + return ::nt::AddPolledListener(m_handle, entry.GetHandle(), mask); + } /** * Add a connection listener. The callback function is called asynchronously @@ -262,7 +344,11 @@ class NetworkTableListenerPoller final { * @param immediate_notify notify listener of all existing connections * @return Listener handle */ - NT_Listener AddConnectionListener(bool immediate_notify); + NT_Listener AddConnectionListener(bool immediate_notify) { + return ::nt::AddPolledListener( + m_handle, ::nt::GetInstanceFromHandle(m_handle), + NT_EVENT_CONNECTION | (immediate_notify ? NT_EVENT_IMMEDIATE : 0)); + } /** * Add a time synchronization listener. The callback function is called @@ -274,7 +360,11 @@ class NetworkTableListenerPoller final { * value * @return Listener handle */ - NT_Listener AddTimeSyncListener(bool immediate_notify); + NT_Listener AddTimeSyncListener(bool immediate_notify) { + return ::nt::AddPolledListener( + m_handle, ::nt::GetInstanceFromHandle(m_handle), + NT_EVENT_TIMESYNC | (immediate_notify ? NT_EVENT_IMMEDIATE : 0)); + } /** * Add logger callback function. By default, log messages are sent to stderr; @@ -287,26 +377,26 @@ class NetworkTableListenerPoller final { * @param maxLevel maximum log level * @return Listener handle */ - NT_Listener AddLogger(unsigned int minLevel, unsigned int maxLevel); + NT_Listener AddLogger(unsigned int minLevel, unsigned int maxLevel) { + return ::nt::AddPolledLogger(m_handle, minLevel, maxLevel); + } /** * Remove a listener. * * @param listener Listener handle */ - void RemoveListener(NT_Listener listener); + void RemoveListener(NT_Listener listener) { ::nt::RemoveListener(listener); } /** * Read events. * * @return Events since the previous call to ReadQueue() */ - std::vector ReadQueue(); + std::vector ReadQueue() { return ::nt::ReadListenerQueue(m_handle); } private: NT_ListenerPoller m_handle{0}; }; } // namespace nt - -#include "NetworkTableListener.inc" diff --git a/ntcore/src/main/native/include/networktables/NetworkTableListener.inc b/ntcore/src/main/native/include/networktables/NetworkTableListener.inc deleted file mode 100644 index 5453d87584c..00000000000 --- a/ntcore/src/main/native/include/networktables/NetworkTableListener.inc +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include -#include -#include -#include - -#include "networktables/MultiSubscriber.h" -#include "networktables/NetworkTableEntry.h" -#include "networktables/NetworkTableInstance.h" -#include "networktables/NetworkTableListener.h" -#include "networktables/Topic.h" -#include "ntcore_cpp.h" - -namespace nt { - -inline NetworkTableListener NetworkTableListener::CreateListener( - NetworkTableInstance inst, std::span prefixes, - unsigned int mask, ListenerCallback listener) { - return NetworkTableListener{ - ::nt::AddListener(inst.GetHandle(), prefixes, mask, std::move(listener))}; -} - -inline NetworkTableListener NetworkTableListener::CreateListener( - Topic topic, unsigned int mask, ListenerCallback listener) { - return NetworkTableListener{ - nt::AddListener(topic.GetHandle(), mask, std::move(listener))}; -} - -inline NetworkTableListener NetworkTableListener::CreateListener( - Subscriber& subscriber, unsigned int mask, ListenerCallback listener) { - return NetworkTableListener{ - ::nt::AddListener(subscriber.GetHandle(), mask, std::move(listener))}; -} - -inline NetworkTableListener NetworkTableListener::CreateListener( - MultiSubscriber& subscriber, unsigned int mask, ListenerCallback listener) { - return NetworkTableListener{ - ::nt::AddListener(subscriber.GetHandle(), mask, std::move(listener))}; -} - -inline NetworkTableListener NetworkTableListener::CreateListener( - NetworkTableEntry& entry, unsigned int mask, ListenerCallback listener) { - return NetworkTableListener{ - ::nt::AddListener(entry.GetHandle(), mask, std::move(listener))}; -} - -inline NetworkTableListener NetworkTableListener::CreateConnectionListener( - NetworkTableInstance inst, bool immediate_notify, - ListenerCallback listener) { - return NetworkTableListener{::nt::AddListener( - inst.GetHandle(), - NT_EVENT_CONNECTION | (immediate_notify ? NT_EVENT_IMMEDIATE : 0), - std::move(listener))}; -} - -inline NetworkTableListener NetworkTableListener::CreateTimeSyncListener( - NetworkTableInstance inst, bool immediate_notify, - ListenerCallback listener) { - return NetworkTableListener{::nt::AddListener( - inst.GetHandle(), - NT_EVENT_TIMESYNC | (immediate_notify ? NT_EVENT_IMMEDIATE : 0), - std::move(listener))}; -} - -inline NetworkTableListener NetworkTableListener::CreateLogger( - NetworkTableInstance inst, unsigned int minLevel, unsigned int maxLevel, - ListenerCallback listener) { - return NetworkTableListener{::nt::AddLogger(inst.GetHandle(), minLevel, - maxLevel, std::move(listener))}; -} - -inline NetworkTableListener::NetworkTableListener(NetworkTableListener&& rhs) - : m_handle(rhs.m_handle) { - rhs.m_handle = 0; -} - -inline NetworkTableListener& NetworkTableListener::operator=( - NetworkTableListener&& rhs) { - if (m_handle != 0) { - nt::RemoveListener(m_handle); - } - m_handle = rhs.m_handle; - rhs.m_handle = 0; - return *this; -} - -inline NetworkTableListener::~NetworkTableListener() { - if (m_handle != 0) { - nt::RemoveListener(m_handle); - } -} - -inline bool NetworkTableListener::WaitForQueue(double timeout) { - if (m_handle != 0) { - return nt::WaitForListenerQueue(m_handle, timeout); - } else { - return false; - } -} - -inline NetworkTableListenerPoller::NetworkTableListenerPoller( - NetworkTableInstance inst) - : m_handle(nt::CreateListenerPoller(inst.GetHandle())) {} - -inline NetworkTableListenerPoller::NetworkTableListenerPoller( - NetworkTableListenerPoller&& rhs) - : m_handle(rhs.m_handle) { - rhs.m_handle = 0; -} - -inline NetworkTableListenerPoller& NetworkTableListenerPoller::operator=( - NetworkTableListenerPoller&& rhs) { - if (m_handle != 0) { - nt::DestroyListenerPoller(m_handle); - } - m_handle = rhs.m_handle; - rhs.m_handle = 0; - return *this; -} - -inline NetworkTableListenerPoller::~NetworkTableListenerPoller() { - if (m_handle != 0) { - nt::DestroyListenerPoller(m_handle); - } -} - -inline NT_Listener NetworkTableListenerPoller::AddListener( - std::span prefixes, unsigned int mask) { - return nt::AddPolledListener(m_handle, prefixes, mask); -} - -inline NT_Listener NetworkTableListenerPoller::AddListener(Topic topic, - unsigned int mask) { - return ::nt::AddPolledListener(m_handle, topic.GetHandle(), mask); -} - -inline NT_Listener NetworkTableListenerPoller::AddListener( - Subscriber& subscriber, unsigned int mask) { - return ::nt::AddPolledListener(m_handle, subscriber.GetHandle(), mask); -} - -inline NT_Listener NetworkTableListenerPoller::AddListener( - MultiSubscriber& subscriber, unsigned int mask) { - return ::nt::AddPolledListener(m_handle, subscriber.GetHandle(), mask); -} - -inline NT_Listener NetworkTableListenerPoller::AddListener( - NetworkTableEntry& entry, unsigned int mask) { - return ::nt::AddPolledListener(m_handle, entry.GetHandle(), mask); -} - -inline NT_Listener NetworkTableListenerPoller::AddConnectionListener( - bool immediate_notify) { - return ::nt::AddPolledListener( - m_handle, ::nt::GetInstanceFromHandle(m_handle), - NT_EVENT_CONNECTION | (immediate_notify ? NT_EVENT_IMMEDIATE : 0)); -} - -inline NT_Listener NetworkTableListenerPoller::AddTimeSyncListener( - bool immediate_notify) { - return ::nt::AddPolledListener( - m_handle, ::nt::GetInstanceFromHandle(m_handle), - NT_EVENT_TIMESYNC | (immediate_notify ? NT_EVENT_IMMEDIATE : 0)); -} - -inline NT_Listener NetworkTableListenerPoller::AddLogger( - unsigned int minLevel, unsigned int maxLevel) { - return ::nt::AddPolledLogger(m_handle, minLevel, maxLevel); -} - -inline void NetworkTableListenerPoller::RemoveListener(NT_Listener listener) { - ::nt::RemoveListener(listener); -} - -inline std::vector NetworkTableListenerPoller::ReadQueue() { - return ::nt::ReadListenerQueue(m_handle); -} - -} // namespace nt diff --git a/ntcore/src/main/native/include/networktables/Topic.h b/ntcore/src/main/native/include/networktables/Topic.h index e34d7facc1c..a9360317185 100644 --- a/ntcore/src/main/native/include/networktables/Topic.h +++ b/ntcore/src/main/native/include/networktables/Topic.h @@ -56,14 +56,16 @@ class Topic { * * @return the topic's name */ - std::string GetName() const; + std::string GetName() const { return ::nt::GetTopicName(m_handle); } /** * Gets the type of the topic. * * @return the topic's type */ - NetworkTableType GetType() const; + NetworkTableType GetType() const { + return static_cast(::nt::GetTopicType(m_handle)); + } /** * Gets the type string of the topic. This may have more information @@ -71,28 +73,34 @@ class Topic { * * @return the topic's type */ - std::string GetTypeString() const; + std::string GetTypeString() const { + return ::nt::GetTopicTypeString(m_handle); + } /** * Make value persistent through server restarts. * * @param persistent True for persistent, false for not persistent. */ - void SetPersistent(bool persistent); + void SetPersistent(bool persistent) { + ::nt::SetTopicPersistent(m_handle, persistent); + } /** * Returns whether the value is persistent through server restarts. * * @return True if the value is persistent. */ - bool IsPersistent() const; + bool IsPersistent() const { return ::nt::GetTopicPersistent(m_handle); } /** * Make the server retain the topic even when there are no publishers. * * @param retained True for retained, false for not retained. */ - void SetRetained(bool retained); + void SetRetained(bool retained) { + ::nt::SetTopicRetained(m_handle, retained); + } /** * Returns whether the topic is retained by server when there are no @@ -100,7 +108,7 @@ class Topic { * * @return True if the topic is retained. */ - bool IsRetained() const; + bool IsRetained() const { return ::nt::GetTopicRetained(m_handle); } /** * Allow storage of the topic's last value, allowing the value to be read (and @@ -108,21 +116,21 @@ class Topic { * * @param cached True for cached, false for not cached. */ - void SetCached(bool cached); + void SetCached(bool cached) { ::nt::SetTopicCached(m_handle, cached); } /** * Returns whether the topic's last value is stored. * * @return True if the topic is cached. */ - bool IsCached() const; + bool IsCached() const { return ::nt::GetTopicCached(m_handle); } /** * Determines if the topic is currently being published. * * @return True if the topic exists, false otherwise. */ - bool Exists() const; + bool Exists() const { return nt::GetTopicExists(m_handle); } /** * Gets the current value of a property (as a JSON object). @@ -145,7 +153,9 @@ class Topic { * * @param name property name */ - void DeleteProperty(std::string_view name); + void DeleteProperty(std::string_view name) { + ::nt::DeleteTopicProperty(m_handle, name); + } /** * Gets all topic properties as a JSON object. Each key in the object @@ -164,14 +174,16 @@ class Topic { * @param properties JSON object with keys to add/update/delete * @return False if properties is not an object */ - bool SetProperties(const wpi::json& properties); + bool SetProperties(const wpi::json& properties) { + return ::nt::SetTopicProperties(m_handle, properties); + } /** * Gets combined information about the topic. * * @return Topic information */ - TopicInfo GetInfo() const; + TopicInfo GetInfo() const { return ::nt::GetTopicInfo(m_handle); } /** * Create a new subscriber to the topic. @@ -308,13 +320,23 @@ class Topic { /** NetworkTables subscriber. */ class Subscriber { public: - virtual ~Subscriber(); + virtual ~Subscriber() { ::nt::Release(m_subHandle); } Subscriber(const Subscriber&) = delete; Subscriber& operator=(const Subscriber&) = delete; - Subscriber(Subscriber&&); - Subscriber& operator=(Subscriber&&); + Subscriber(Subscriber&& rhs) : m_subHandle{rhs.m_subHandle} { + rhs.m_subHandle = 0; + } + + Subscriber& operator=(Subscriber&& rhs) { + if (m_subHandle != 0) { + ::nt::Release(m_subHandle); + } + m_subHandle = rhs.m_subHandle; + rhs.m_subHandle = 0; + return *this; + } /** * Determines if the native handle is valid. @@ -335,7 +357,7 @@ class Subscriber { * * @return True if the topic exists, false otherwise. */ - bool Exists() const; + bool Exists() const { return nt::GetTopicExists(m_subHandle); } /** * Gets the last time the value was changed. @@ -344,32 +366,49 @@ class Subscriber { * * @return Topic last change time */ - int64_t GetLastChange() const; + int64_t GetLastChange() const { + return ::nt::GetEntryLastChange(m_subHandle); + } /** * Gets the subscribed-to topic. * * @return Topic */ - Topic GetTopic() const; + Topic GetTopic() const { + return Topic{::nt::GetTopicFromHandle(m_subHandle)}; + } protected: Subscriber() = default; explicit Subscriber(NT_Subscriber handle) : m_subHandle{handle} {} NT_Subscriber m_subHandle{0}; + + private: + void anchor(); }; /** NetworkTables publisher. */ class Publisher { public: - virtual ~Publisher(); + virtual ~Publisher() { ::nt::Release(m_pubHandle); } Publisher(const Publisher&) = delete; Publisher& operator=(const Publisher&) = delete; - Publisher(Publisher&&); - Publisher& operator=(Publisher&&); + Publisher(Publisher&& rhs) : m_pubHandle{rhs.m_pubHandle} { + rhs.m_pubHandle = 0; + } + + Publisher& operator=(Publisher&& rhs) { + if (m_pubHandle != 0) { + ::nt::Release(m_pubHandle); + } + m_pubHandle = rhs.m_pubHandle; + rhs.m_pubHandle = 0; + return *this; + } /** * Determines if the native handle is valid. @@ -390,7 +429,9 @@ class Publisher { * * @return Topic */ - Topic GetTopic() const; + Topic GetTopic() const { + return Topic{::nt::GetTopicFromHandle(m_pubHandle)}; + } protected: Publisher() = default; @@ -398,8 +439,9 @@ class Publisher { /// NetworkTables handle. NT_Publisher m_pubHandle{0}; + + private: + void anchor(); }; } // namespace nt - -#include "networktables/Topic.inc" diff --git a/ntcore/src/main/native/include/networktables/Topic.inc b/ntcore/src/main/native/include/networktables/Topic.inc deleted file mode 100644 index 605f9d8d10d..00000000000 --- a/ntcore/src/main/native/include/networktables/Topic.inc +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include - -#include "networktables/NetworkTableType.h" -#include "networktables/Topic.h" -#include "ntcore_c.h" -#include "ntcore_cpp.h" - -namespace nt { - -inline std::string Topic::GetName() const { - return ::nt::GetTopicName(m_handle); -} - -inline NetworkTableType Topic::GetType() const { - return static_cast(::nt::GetTopicType(m_handle)); -} - -inline std::string Topic::GetTypeString() const { - return ::nt::GetTopicTypeString(m_handle); -} - -inline void Topic::SetPersistent(bool persistent) { - ::nt::SetTopicPersistent(m_handle, persistent); -} - -inline bool Topic::IsPersistent() const { - return ::nt::GetTopicPersistent(m_handle); -} - -inline void Topic::SetRetained(bool retained) { - ::nt::SetTopicRetained(m_handle, retained); -} - -inline bool Topic::IsRetained() const { - return ::nt::GetTopicRetained(m_handle); -} - -inline void Topic::SetCached(bool cached) { - ::nt::SetTopicCached(m_handle, cached); -} - -inline bool Topic::IsCached() const { - return ::nt::GetTopicCached(m_handle); -} - -inline bool Topic::Exists() const { - return nt::GetTopicExists(m_handle); -} - -inline void Topic::DeleteProperty(std::string_view name) { - ::nt::DeleteTopicProperty(m_handle, name); -} - -inline bool Topic::SetProperties(const wpi::json& properties) { - return ::nt::SetTopicProperties(m_handle, properties); -} - -inline TopicInfo Topic::GetInfo() const { - return ::nt::GetTopicInfo(m_handle); -} - -inline Subscriber::~Subscriber() { - ::nt::Release(m_subHandle); -} - -inline Subscriber::Subscriber(Subscriber&& rhs) : m_subHandle{rhs.m_subHandle} { - rhs.m_subHandle = 0; -} - -inline Subscriber& Subscriber::operator=(Subscriber&& rhs) { - if (m_subHandle != 0) { - ::nt::Release(m_subHandle); - } - m_subHandle = rhs.m_subHandle; - rhs.m_subHandle = 0; - return *this; -} - -inline bool Subscriber::Exists() const { - return nt::GetTopicExists(m_subHandle); -} - -inline int64_t Subscriber::GetLastChange() const { - return ::nt::GetEntryLastChange(m_subHandle); -} - -inline Topic Subscriber::GetTopic() const { - return Topic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -inline Publisher::~Publisher() { - ::nt::Release(m_pubHandle); -} - -inline Publisher::Publisher(Publisher&& rhs) : m_pubHandle{rhs.m_pubHandle} { - rhs.m_pubHandle = 0; -} - -inline Publisher& Publisher::operator=(Publisher&& rhs) { - if (m_pubHandle != 0) { - ::nt::Release(m_pubHandle); - } - m_pubHandle = rhs.m_pubHandle; - rhs.m_pubHandle = 0; - return *this; -} - -inline Topic Publisher::GetTopic() const { - return Topic{::nt::GetTopicFromHandle(m_pubHandle)}; -} - -} // namespace nt diff --git a/ntcore/src/main/native/include/networktables/UnitTopic.h b/ntcore/src/main/native/include/networktables/UnitTopic.h index eb6ad6dcad3..ff836c034a3 100644 --- a/ntcore/src/main/native/include/networktables/UnitTopic.h +++ b/ntcore/src/main/native/include/networktables/UnitTopic.h @@ -6,11 +6,10 @@ #include -#include #include #include -#include +#include #include "networktables/Topic.h" #include "ntcore_cpp.h" @@ -69,7 +68,8 @@ class UnitSubscriber : public Subscriber { * @param handle Native handle * @param defaultValue Default value */ - UnitSubscriber(NT_Subscriber handle, ParamType defaultValue); + UnitSubscriber(NT_Subscriber handle, ParamType defaultValue) + : Subscriber{handle}, m_defaultValue{defaultValue} {} /** * Get the last published value. @@ -77,7 +77,7 @@ class UnitSubscriber : public Subscriber { * * @return value */ - ValueType Get() const; + ValueType Get() const { return Get(m_defaultValue); } /** * Get the last published value. @@ -86,7 +86,9 @@ class UnitSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return value */ - ValueType Get(ParamType defaultValue) const; + ValueType Get(ParamType defaultValue) const { + return T{::nt::GetDouble(m_subHandle, defaultValue.value())}; + } /** * Get the last published value along with its timestamp @@ -95,7 +97,7 @@ class UnitSubscriber : public Subscriber { * * @return timestamped value */ - TimestampedValueType GetAtomic() const; + TimestampedValueType GetAtomic() const { return GetAtomic(m_defaultValue); } /** * Get the last published value along with its timestamp. @@ -105,7 +107,10 @@ class UnitSubscriber : public Subscriber { * @param defaultValue default value to return if no value has been published * @return timestamped value */ - TimestampedValueType GetAtomic(ParamType defaultValue) const; + TimestampedValueType GetAtomic(ParamType defaultValue) const { + auto doubleVal = ::nt::GetAtomicDouble(m_subHandle, defaultValue.value()); + return {doubleVal.time, doubleVal.serverTime, doubleVal.value}; + } /** * Get an array of all value changes since the last call to ReadQueue. @@ -117,14 +122,23 @@ class UnitSubscriber : public Subscriber { * @return Array of timestamped values; empty array if no new changes have * been published since the previous call. */ - std::vector ReadQueue(); + std::vector ReadQueue() { + std::vector> vals; + auto doubleVals = ::nt::ReadQueueDouble(m_subHandle); + vals.reserve(doubleVals.size()); + for (auto&& val : doubleVals) { + vals.emplace_back(val.time, val.serverTime, val.value); + } + } /** * Get the corresponding topic. * * @return Topic */ - TopicType GetTopic() const; + TopicType GetTopic() const { + return UnitTopic{::nt::GetTopicFromHandle(m_subHandle)}; + } private: ValueType m_defaultValue; @@ -152,7 +166,7 @@ class UnitPublisher : public Publisher { * * @param handle Native handle */ - explicit UnitPublisher(NT_Publisher handle); + explicit UnitPublisher(NT_Publisher handle) : Publisher{handle} {} /** * Publish a new value. @@ -160,7 +174,9 @@ class UnitPublisher : public Publisher { * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(ParamType value, int64_t time = 0); + void Set(ParamType value, int64_t time = 0) { + ::nt::SetDouble(m_pubHandle, value.value(), time); + } /** * Publish a default value. @@ -169,14 +185,18 @@ class UnitPublisher : public Publisher { * * @param value value */ - void SetDefault(ParamType value); + void SetDefault(ParamType value) { + ::nt::SetDefaultDouble(m_pubHandle, value.value()); + } /** * Get the corresponding topic. * * @return Topic */ - TopicType GetTopic() const; + TopicType GetTopic() const { + return UnitTopic{::nt::GetTopicFromHandle(m_pubHandle)}; + } }; /** @@ -206,7 +226,8 @@ class UnitEntry final : public UnitSubscriber, public UnitPublisher { * @param handle Native handle * @param defaultValue Default value */ - UnitEntry(NT_Entry handle, ParamType defaultValue); + UnitEntry(NT_Entry handle, ParamType defaultValue) + : UnitSubscriber{handle, defaultValue}, UnitPublisher{handle} {} /** * Determines if the native handle is valid. @@ -227,12 +248,14 @@ class UnitEntry final : public UnitSubscriber, public UnitPublisher { * * @return Topic */ - TopicType GetTopic() const; + TopicType GetTopic() const { + return UnitTopic{::nt::GetTopicFromHandle(this->m_subHandle)}; + } /** * Stops publishing the entry if it's published. */ - void Unpublish(); + void Unpublish() { ::nt::Unpublish(this->m_pubHandle); } }; /** @@ -276,7 +299,7 @@ class UnitTopic final : public Topic { * * @return True if unit matches, false if not matching or topic not published. */ - bool IsMatchingUnit() const; + bool IsMatchingUnit() const { return GetProperty("unit") == T{}.name(); } /** * Create a new subscriber to the topic. @@ -296,7 +319,10 @@ class UnitTopic final : public Topic { [[nodiscard]] SubscriberType Subscribe( ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return UnitSubscriber{ + ::nt::Subscribe(m_handle, NT_DOUBLE, "double", options), defaultValue}; + } /** * Create a new subscriber to the topic, with specific type string. @@ -317,7 +343,11 @@ class UnitTopic final : public Topic { [[nodiscard]] SubscriberType SubscribeEx( std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return UnitSubscriber{ + ::nt::Subscribe(m_handle, NT_DOUBLE, typeString, options), + defaultValue}; + } /** * Create a new publisher to the topic. @@ -335,7 +365,10 @@ class UnitTopic final : public Topic { * @return publisher */ [[nodiscard]] - PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions) { + return UnitPublisher{::nt::PublishEx(m_handle, NT_DOUBLE, "double", + {{"unit", T{}.name()}}, options)}; + } /** * Create a new publisher to the topic, with type string and initial @@ -356,9 +389,14 @@ class UnitTopic final : public Topic { * @return publisher */ [[nodiscard]] - PublisherType PublishEx(std::string_view typeString, - const wpi::json& properties, - const PubSubOptions& options = kDefaultPubSubOptions); + PublisherType PublishEx( + std::string_view typeString, const wpi::json& properties, + const PubSubOptions& options = kDefaultPubSubOptions) { + wpi::json props = properties; + props["unit"] = T{}.name(); + return UnitPublisher{ + ::nt::PublishEx(m_handle, NT_DOUBLE, typeString, props, options)}; + } /** * Create a new entry for the topic. @@ -382,7 +420,10 @@ class UnitTopic final : public Topic { */ [[nodiscard]] EntryType GetEntry(ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return UnitEntry{::nt::GetEntry(m_handle, NT_DOUBLE, "double", options), + defaultValue}; + } /** * Create a new entry for the topic, with specific type string. @@ -407,9 +448,10 @@ class UnitTopic final : public Topic { */ [[nodiscard]] EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, - const PubSubOptions& options = kDefaultPubSubOptions); + const PubSubOptions& options = kDefaultPubSubOptions) { + return UnitEntry{ + ::nt::GetEntry(m_handle, NT_DOUBLE, typeString, options), defaultValue}; + } }; } // namespace nt - -#include "networktables/UnitTopic.inc" diff --git a/ntcore/src/main/native/include/networktables/UnitTopic.inc b/ntcore/src/main/native/include/networktables/UnitTopic.inc deleted file mode 100644 index c107526da1f..00000000000 --- a/ntcore/src/main/native/include/networktables/UnitTopic.inc +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include - -#include - -#include "networktables/NetworkTableType.h" -#include "networktables/UnitTopic.h" -#include "ntcore_cpp.h" - -namespace nt { - -template -inline UnitSubscriber::UnitSubscriber(NT_Subscriber handle, T defaultValue) - : Subscriber{handle}, m_defaultValue{defaultValue} {} - -template -inline T UnitSubscriber::Get() const { - return Get(m_defaultValue); -} - -template -inline T UnitSubscriber::Get(T defaultValue) const { - return T{::nt::GetDouble(m_subHandle, defaultValue.value())}; -} - -template -inline TimestampedUnit UnitSubscriber::GetAtomic() const { - return GetAtomic(m_defaultValue); -} - -template -inline TimestampedUnit UnitSubscriber::GetAtomic(T defaultValue) const { - auto doubleVal = ::nt::GetAtomicDouble(m_subHandle, defaultValue.value()); - return {doubleVal.time, doubleVal.serverTime, doubleVal.value}; -} - -template -inline std::vector> UnitSubscriber::ReadQueue() { - std::vector> vals; - auto doubleVals = ::nt::ReadQueueDouble(m_subHandle); - vals.reserve(doubleVals.size()); - for (auto&& val : doubleVals) { - vals.emplace_back(val.time, val.serverTime, val.value); - } -} - -template -inline UnitTopic UnitSubscriber::GetTopic() const { - return UnitTopic{::nt::GetTopicFromHandle(m_subHandle)}; -} - -template -inline UnitPublisher::UnitPublisher(NT_Publisher handle) - : Publisher{handle} {} - -template -inline void UnitPublisher::Set(T value, int64_t time) { - ::nt::SetDouble(m_pubHandle, value.value(), time); -} - -template -inline void UnitPublisher::SetDefault(T value) { - ::nt::SetDefaultDouble(m_pubHandle, value.value()); -} - -template -inline UnitTopic UnitPublisher::GetTopic() const { - return UnitTopic{::nt::GetTopicFromHandle(m_pubHandle)}; -} - -template -inline UnitEntry::UnitEntry(NT_Entry handle, T defaultValue) - : UnitSubscriber{handle, defaultValue}, UnitPublisher{handle} {} - -template -inline UnitTopic UnitEntry::GetTopic() const { - return UnitTopic{::nt::GetTopicFromHandle(this->m_subHandle)}; -} - -template -inline void UnitEntry::Unpublish() { - ::nt::Unpublish(this->m_pubHandle); -} - -template -inline bool UnitTopic::IsMatchingUnit() const { - return GetProperty("unit") == T{}.name(); -} - -template -inline UnitSubscriber UnitTopic::Subscribe(T defaultValue, - const PubSubOptions& options) { - return UnitSubscriber{ - ::nt::Subscribe(m_handle, NT_DOUBLE, "double", options), defaultValue}; -} - -template -inline UnitSubscriber UnitTopic::SubscribeEx( - std::string_view typeString, T defaultValue, const PubSubOptions& options) { - return UnitSubscriber{ - ::nt::Subscribe(m_handle, NT_DOUBLE, typeString, options), defaultValue}; -} - -template -inline UnitPublisher UnitTopic::Publish(const PubSubOptions& options) { - return UnitPublisher{::nt::PublishEx(m_handle, NT_DOUBLE, "double", - {{"unit", T{}.name()}}, options)}; -} - -template -inline UnitPublisher UnitTopic::PublishEx(std::string_view typeString, - const wpi::json& properties, - const PubSubOptions& options) { - wpi::json props = properties; - props["unit"] = T{}.name(); - return UnitPublisher{ - ::nt::PublishEx(m_handle, NT_DOUBLE, typeString, props, options)}; -} - -template -inline UnitEntry UnitTopic::GetEntry(T defaultValue, - const PubSubOptions& options) { - return UnitEntry{::nt::GetEntry(m_handle, NT_DOUBLE, "double", options), - defaultValue}; -} - -template -inline UnitEntry UnitTopic::GetEntryEx(std::string_view typeString, - T defaultValue, - const PubSubOptions& options) { - return UnitEntry{::nt::GetEntry(m_handle, NT_DOUBLE, typeString, options), - defaultValue}; -} - -} // namespace nt