mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
[ntcore] Merge .inc files into headers (#7210)
This commit is contained in:
@@ -15,7 +15,9 @@
|
||||
|
||||
#include <wpi/json_fwd.h>
|
||||
|
||||
#include "networktables/NetworkTableType.h"
|
||||
#include "networktables/Topic.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
namespace wpi {
|
||||
template <typename T>
|
||||
@@ -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<SmallElemType>& buf) const;
|
||||
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& buf, ParamType defaultValue) const;
|
||||
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& buf) const;
|
||||
wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& 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<TimestampedValueType> ReadQueue();
|
||||
std::vector<TimestampedValueType> 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 %}
|
||||
};
|
||||
|
||||
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)};
|
||||
}
|
||||
|
||||
inline {{ TypeName }}Topic {{ TypeName }}Entry::GetTopic() const {
|
||||
return {{ TypeName }}Topic{::nt::GetTopicFromHandle(m_subHandle)};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
|
||||
#include "networktables/{{ TypeName }}Topic.inc"
|
||||
|
||||
|
||||
@@ -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 <vector>
|
||||
|
||||
#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<Timestamped{{ TypeName }}>
|
||||
{{ 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
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
|
||||
#include <wpi/json_fwd.h>
|
||||
|
||||
#include "networktables/NetworkTableType.h"
|
||||
#include "networktables/Topic.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
namespace wpi {
|
||||
template <typename T>
|
||||
@@ -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<SmallElemType>& buf) const;
|
||||
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& buf, ParamType defaultValue) const;
|
||||
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& buf) const;
|
||||
wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& 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<TimestampedValueType> ReadQueue();
|
||||
std::vector<TimestampedValueType> 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)};
|
||||
}
|
||||
|
||||
#include "networktables/BooleanArrayTopic.inc"
|
||||
inline BooleanArrayTopic BooleanArrayPublisher::GetTopic() const {
|
||||
return BooleanArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)};
|
||||
}
|
||||
|
||||
inline BooleanArrayTopic BooleanArrayEntry::GetTopic() const {
|
||||
return BooleanArrayTopic{::nt::GetTopicFromHandle(m_subHandle)};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
|
||||
@@ -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 <vector>
|
||||
|
||||
#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<int> BooleanArraySubscriber::Get() const {
|
||||
return Get(m_defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<int> BooleanArraySubscriber::Get(
|
||||
ParamType defaultValue) const {
|
||||
return ::nt::GetBooleanArray(m_subHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::span<int> BooleanArraySubscriber::Get(wpi::SmallVectorImpl<int>& buf) const {
|
||||
return Get(buf, m_defaultValue);
|
||||
}
|
||||
|
||||
inline std::span<int> BooleanArraySubscriber::Get(wpi::SmallVectorImpl<int>& 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<int>& buf) const {
|
||||
return GetAtomic(buf, m_defaultValue);
|
||||
}
|
||||
|
||||
inline TimestampedBooleanArrayView BooleanArraySubscriber::GetAtomic(wpi::SmallVectorImpl<int>& buf, ParamType defaultValue) const {
|
||||
return nt::GetAtomicBooleanArray(m_subHandle, buf, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<TimestampedBooleanArray>
|
||||
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<const int> 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<const int> 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<const int> 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<const int> defaultValue,
|
||||
const PubSubOptions& options) {
|
||||
return BooleanArrayEntry{
|
||||
::nt::GetEntry(m_handle, NT_BOOLEAN_ARRAY, typeString, options),
|
||||
defaultValue};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
@@ -15,7 +15,9 @@
|
||||
|
||||
#include <wpi/json_fwd.h>
|
||||
|
||||
#include "networktables/NetworkTableType.h"
|
||||
#include "networktables/Topic.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
namespace wpi {
|
||||
template <typename T>
|
||||
@@ -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<TimestampedValueType> ReadQueue();
|
||||
std::vector<TimestampedValueType> 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)};
|
||||
}
|
||||
|
||||
#include "networktables/BooleanTopic.inc"
|
||||
inline BooleanTopic BooleanPublisher::GetTopic() const {
|
||||
return BooleanTopic{::nt::GetTopicFromHandle(m_pubHandle)};
|
||||
}
|
||||
|
||||
inline BooleanTopic BooleanEntry::GetTopic() const {
|
||||
return BooleanTopic{::nt::GetTopicFromHandle(m_subHandle)};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
|
||||
@@ -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 <vector>
|
||||
|
||||
#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<TimestampedBoolean>
|
||||
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
|
||||
@@ -15,7 +15,9 @@
|
||||
|
||||
#include <wpi/json_fwd.h>
|
||||
|
||||
#include "networktables/NetworkTableType.h"
|
||||
#include "networktables/Topic.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
namespace wpi {
|
||||
template <typename T>
|
||||
@@ -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<SmallElemType>& buf) const;
|
||||
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& buf, ParamType defaultValue) const;
|
||||
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& buf) const;
|
||||
wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& 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<TimestampedValueType> ReadQueue();
|
||||
std::vector<TimestampedValueType> 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)};
|
||||
}
|
||||
|
||||
#include "networktables/DoubleArrayTopic.inc"
|
||||
inline DoubleArrayTopic DoubleArrayPublisher::GetTopic() const {
|
||||
return DoubleArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)};
|
||||
}
|
||||
|
||||
inline DoubleArrayTopic DoubleArrayEntry::GetTopic() const {
|
||||
return DoubleArrayTopic{::nt::GetTopicFromHandle(m_subHandle)};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
|
||||
@@ -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 <vector>
|
||||
|
||||
#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<double> DoubleArraySubscriber::Get() const {
|
||||
return Get(m_defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<double> DoubleArraySubscriber::Get(
|
||||
ParamType defaultValue) const {
|
||||
return ::nt::GetDoubleArray(m_subHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::span<double> DoubleArraySubscriber::Get(wpi::SmallVectorImpl<double>& buf) const {
|
||||
return Get(buf, m_defaultValue);
|
||||
}
|
||||
|
||||
inline std::span<double> DoubleArraySubscriber::Get(wpi::SmallVectorImpl<double>& 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<double>& buf) const {
|
||||
return GetAtomic(buf, m_defaultValue);
|
||||
}
|
||||
|
||||
inline TimestampedDoubleArrayView DoubleArraySubscriber::GetAtomic(wpi::SmallVectorImpl<double>& buf, ParamType defaultValue) const {
|
||||
return nt::GetAtomicDoubleArray(m_subHandle, buf, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<TimestampedDoubleArray>
|
||||
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<const double> 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<const double> 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<const double> 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<const double> defaultValue,
|
||||
const PubSubOptions& options) {
|
||||
return DoubleArrayEntry{
|
||||
::nt::GetEntry(m_handle, NT_DOUBLE_ARRAY, typeString, options),
|
||||
defaultValue};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
@@ -15,7 +15,9 @@
|
||||
|
||||
#include <wpi/json_fwd.h>
|
||||
|
||||
#include "networktables/NetworkTableType.h"
|
||||
#include "networktables/Topic.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
namespace wpi {
|
||||
template <typename T>
|
||||
@@ -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<TimestampedValueType> ReadQueue();
|
||||
std::vector<TimestampedValueType> 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)};
|
||||
}
|
||||
|
||||
#include "networktables/DoubleTopic.inc"
|
||||
inline DoubleTopic DoublePublisher::GetTopic() const {
|
||||
return DoubleTopic{::nt::GetTopicFromHandle(m_pubHandle)};
|
||||
}
|
||||
|
||||
inline DoubleTopic DoubleEntry::GetTopic() const {
|
||||
return DoubleTopic{::nt::GetTopicFromHandle(m_subHandle)};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
|
||||
@@ -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 <vector>
|
||||
|
||||
#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<TimestampedDouble>
|
||||
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
|
||||
@@ -15,7 +15,9 @@
|
||||
|
||||
#include <wpi/json_fwd.h>
|
||||
|
||||
#include "networktables/NetworkTableType.h"
|
||||
#include "networktables/Topic.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
namespace wpi {
|
||||
template <typename T>
|
||||
@@ -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<SmallElemType>& buf) const;
|
||||
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& buf, ParamType defaultValue) const;
|
||||
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& buf) const;
|
||||
wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& 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<TimestampedValueType> ReadQueue();
|
||||
std::vector<TimestampedValueType> 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)};
|
||||
}
|
||||
|
||||
#include "networktables/FloatArrayTopic.inc"
|
||||
inline FloatArrayTopic FloatArrayPublisher::GetTopic() const {
|
||||
return FloatArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)};
|
||||
}
|
||||
|
||||
inline FloatArrayTopic FloatArrayEntry::GetTopic() const {
|
||||
return FloatArrayTopic{::nt::GetTopicFromHandle(m_subHandle)};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
|
||||
@@ -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 <vector>
|
||||
|
||||
#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<float> FloatArraySubscriber::Get() const {
|
||||
return Get(m_defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<float> FloatArraySubscriber::Get(
|
||||
ParamType defaultValue) const {
|
||||
return ::nt::GetFloatArray(m_subHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::span<float> FloatArraySubscriber::Get(wpi::SmallVectorImpl<float>& buf) const {
|
||||
return Get(buf, m_defaultValue);
|
||||
}
|
||||
|
||||
inline std::span<float> FloatArraySubscriber::Get(wpi::SmallVectorImpl<float>& 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<float>& buf) const {
|
||||
return GetAtomic(buf, m_defaultValue);
|
||||
}
|
||||
|
||||
inline TimestampedFloatArrayView FloatArraySubscriber::GetAtomic(wpi::SmallVectorImpl<float>& buf, ParamType defaultValue) const {
|
||||
return nt::GetAtomicFloatArray(m_subHandle, buf, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<TimestampedFloatArray>
|
||||
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<const float> 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<const float> 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<const float> 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<const float> defaultValue,
|
||||
const PubSubOptions& options) {
|
||||
return FloatArrayEntry{
|
||||
::nt::GetEntry(m_handle, NT_FLOAT_ARRAY, typeString, options),
|
||||
defaultValue};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
@@ -15,7 +15,9 @@
|
||||
|
||||
#include <wpi/json_fwd.h>
|
||||
|
||||
#include "networktables/NetworkTableType.h"
|
||||
#include "networktables/Topic.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
namespace wpi {
|
||||
template <typename T>
|
||||
@@ -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<TimestampedValueType> ReadQueue();
|
||||
std::vector<TimestampedValueType> 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)};
|
||||
}
|
||||
|
||||
#include "networktables/FloatTopic.inc"
|
||||
inline FloatTopic FloatPublisher::GetTopic() const {
|
||||
return FloatTopic{::nt::GetTopicFromHandle(m_pubHandle)};
|
||||
}
|
||||
|
||||
inline FloatTopic FloatEntry::GetTopic() const {
|
||||
return FloatTopic{::nt::GetTopicFromHandle(m_subHandle)};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
|
||||
@@ -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 <vector>
|
||||
|
||||
#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<TimestampedFloat>
|
||||
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
|
||||
@@ -15,7 +15,9 @@
|
||||
|
||||
#include <wpi/json_fwd.h>
|
||||
|
||||
#include "networktables/NetworkTableType.h"
|
||||
#include "networktables/Topic.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
namespace wpi {
|
||||
template <typename T>
|
||||
@@ -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<SmallElemType>& buf) const;
|
||||
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& buf, ParamType defaultValue) const;
|
||||
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& buf) const;
|
||||
wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& 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<TimestampedValueType> ReadQueue();
|
||||
std::vector<TimestampedValueType> 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)};
|
||||
}
|
||||
|
||||
#include "networktables/IntegerArrayTopic.inc"
|
||||
inline IntegerArrayTopic IntegerArrayPublisher::GetTopic() const {
|
||||
return IntegerArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)};
|
||||
}
|
||||
|
||||
inline IntegerArrayTopic IntegerArrayEntry::GetTopic() const {
|
||||
return IntegerArrayTopic{::nt::GetTopicFromHandle(m_subHandle)};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
|
||||
@@ -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 <vector>
|
||||
|
||||
#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<int64_t> IntegerArraySubscriber::Get() const {
|
||||
return Get(m_defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<int64_t> IntegerArraySubscriber::Get(
|
||||
ParamType defaultValue) const {
|
||||
return ::nt::GetIntegerArray(m_subHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::span<int64_t> IntegerArraySubscriber::Get(wpi::SmallVectorImpl<int64_t>& buf) const {
|
||||
return Get(buf, m_defaultValue);
|
||||
}
|
||||
|
||||
inline std::span<int64_t> IntegerArraySubscriber::Get(wpi::SmallVectorImpl<int64_t>& 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<int64_t>& buf) const {
|
||||
return GetAtomic(buf, m_defaultValue);
|
||||
}
|
||||
|
||||
inline TimestampedIntegerArrayView IntegerArraySubscriber::GetAtomic(wpi::SmallVectorImpl<int64_t>& buf, ParamType defaultValue) const {
|
||||
return nt::GetAtomicIntegerArray(m_subHandle, buf, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<TimestampedIntegerArray>
|
||||
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<const int64_t> 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<const int64_t> 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<const int64_t> 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<const int64_t> defaultValue,
|
||||
const PubSubOptions& options) {
|
||||
return IntegerArrayEntry{
|
||||
::nt::GetEntry(m_handle, NT_INTEGER_ARRAY, typeString, options),
|
||||
defaultValue};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
@@ -15,7 +15,9 @@
|
||||
|
||||
#include <wpi/json_fwd.h>
|
||||
|
||||
#include "networktables/NetworkTableType.h"
|
||||
#include "networktables/Topic.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
namespace wpi {
|
||||
template <typename T>
|
||||
@@ -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<TimestampedValueType> ReadQueue();
|
||||
std::vector<TimestampedValueType> 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)};
|
||||
}
|
||||
|
||||
#include "networktables/IntegerTopic.inc"
|
||||
inline IntegerTopic IntegerPublisher::GetTopic() const {
|
||||
return IntegerTopic{::nt::GetTopicFromHandle(m_pubHandle)};
|
||||
}
|
||||
|
||||
inline IntegerTopic IntegerEntry::GetTopic() const {
|
||||
return IntegerTopic{::nt::GetTopicFromHandle(m_subHandle)};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
|
||||
@@ -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 <vector>
|
||||
|
||||
#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<TimestampedInteger>
|
||||
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
|
||||
@@ -15,7 +15,9 @@
|
||||
|
||||
#include <wpi/json_fwd.h>
|
||||
|
||||
#include "networktables/NetworkTableType.h"
|
||||
#include "networktables/Topic.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
namespace wpi {
|
||||
template <typename T>
|
||||
@@ -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<SmallElemType>& buf) const;
|
||||
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& buf, ParamType defaultValue) const;
|
||||
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& buf) const;
|
||||
wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& 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<TimestampedValueType> ReadQueue();
|
||||
std::vector<TimestampedValueType> 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)};
|
||||
}
|
||||
|
||||
#include "networktables/RawTopic.inc"
|
||||
inline RawTopic RawPublisher::GetTopic() const {
|
||||
return RawTopic{::nt::GetTopicFromHandle(m_pubHandle)};
|
||||
}
|
||||
|
||||
inline RawTopic RawEntry::GetTopic() const {
|
||||
return RawTopic{::nt::GetTopicFromHandle(m_subHandle)};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
|
||||
@@ -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 <vector>
|
||||
|
||||
#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<uint8_t> RawSubscriber::Get() const {
|
||||
return Get(m_defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<uint8_t> RawSubscriber::Get(
|
||||
ParamType defaultValue) const {
|
||||
return ::nt::GetRaw(m_subHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::span<uint8_t> RawSubscriber::Get(wpi::SmallVectorImpl<uint8_t>& buf) const {
|
||||
return Get(buf, m_defaultValue);
|
||||
}
|
||||
|
||||
inline std::span<uint8_t> RawSubscriber::Get(wpi::SmallVectorImpl<uint8_t>& 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<uint8_t>& buf) const {
|
||||
return GetAtomic(buf, m_defaultValue);
|
||||
}
|
||||
|
||||
inline TimestampedRawView RawSubscriber::GetAtomic(wpi::SmallVectorImpl<uint8_t>& buf, ParamType defaultValue) const {
|
||||
return nt::GetAtomicRaw(m_subHandle, buf, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<TimestampedRaw>
|
||||
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<const uint8_t> 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<const uint8_t> defaultValue,
|
||||
const PubSubOptions& options) {
|
||||
return RawEntry{
|
||||
::nt::GetEntry(m_handle, NT_RAW, typeString, options),
|
||||
defaultValue};
|
||||
}
|
||||
} // namespace nt
|
||||
@@ -15,7 +15,9 @@
|
||||
|
||||
#include <wpi/json_fwd.h>
|
||||
|
||||
#include "networktables/NetworkTableType.h"
|
||||
#include "networktables/Topic.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
namespace wpi {
|
||||
template <typename T>
|
||||
@@ -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<TimestampedValueType> ReadQueue();
|
||||
std::vector<TimestampedValueType> 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)};
|
||||
}
|
||||
|
||||
#include "networktables/StringArrayTopic.inc"
|
||||
inline StringArrayTopic StringArrayPublisher::GetTopic() const {
|
||||
return StringArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)};
|
||||
}
|
||||
|
||||
inline StringArrayTopic StringArrayEntry::GetTopic() const {
|
||||
return StringArrayTopic{::nt::GetTopicFromHandle(m_subHandle)};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
|
||||
@@ -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 <vector>
|
||||
|
||||
#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<std::string> StringArraySubscriber::Get() const {
|
||||
return Get(m_defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<std::string> 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<TimestampedStringArray>
|
||||
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<const std::string> 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<const std::string> 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<const std::string> 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<const std::string> defaultValue,
|
||||
const PubSubOptions& options) {
|
||||
return StringArrayEntry{
|
||||
::nt::GetEntry(m_handle, NT_STRING_ARRAY, typeString, options),
|
||||
defaultValue};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
@@ -17,7 +17,9 @@
|
||||
|
||||
#include <wpi/json_fwd.h>
|
||||
|
||||
#include "networktables/NetworkTableType.h"
|
||||
#include "networktables/Topic.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
namespace wpi {
|
||||
template <typename T>
|
||||
@@ -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<SmallElemType>& buf) const;
|
||||
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& buf, ParamType defaultValue) const;
|
||||
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& buf) const;
|
||||
wpi::SmallVectorImpl<SmallElemType>& 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<SmallElemType>& 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<TimestampedValueType> ReadQueue();
|
||||
std::vector<TimestampedValueType> 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)};
|
||||
}
|
||||
|
||||
#include "networktables/StringTopic.inc"
|
||||
inline StringTopic StringPublisher::GetTopic() const {
|
||||
return StringTopic{::nt::GetTopicFromHandle(m_pubHandle)};
|
||||
}
|
||||
|
||||
inline StringTopic StringEntry::GetTopic() const {
|
||||
return StringTopic{::nt::GetTopicFromHandle(m_subHandle)};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
|
||||
@@ -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 <vector>
|
||||
|
||||
#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<char>& buf) const {
|
||||
return Get(buf, m_defaultValue);
|
||||
}
|
||||
|
||||
inline std::string_view StringSubscriber::Get(wpi::SmallVectorImpl<char>& 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<char>& buf) const {
|
||||
return GetAtomic(buf, m_defaultValue);
|
||||
}
|
||||
|
||||
inline TimestampedStringView StringSubscriber::GetAtomic(wpi::SmallVectorImpl<char>& buf, ParamType defaultValue) const {
|
||||
return nt::GetAtomicString(m_subHandle, buf, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<TimestampedString>
|
||||
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
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <string>
|
||||
|
||||
#include <wpi/FastQueue.h>
|
||||
#include <wpi/Logger.h>
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#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<ClientMessage> ReadQueue(std::span<ClientMessage> out) final;
|
||||
void ClearQueue() final;
|
||||
std::span<ClientMessage> ReadQueue(std::span<ClientMessage> 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<ClientValueMsg>(&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<const std::string> 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<ClientMessage, kBlockSize> m_queue{kBlockSize - 1};
|
||||
@@ -83,5 +145,3 @@ using LocalClientMessageQueue =
|
||||
using NetworkIncomingClientQueue = detail::ClientMessageQueueImpl<0, false>;
|
||||
|
||||
} // namespace nt::net
|
||||
|
||||
#include "ClientMessageQueue.inc"
|
||||
|
||||
@@ -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 <span>
|
||||
#include <string>
|
||||
|
||||
#include <wpi/Logger.h>
|
||||
|
||||
#include "ClientMessageQueue.h"
|
||||
|
||||
namespace nt::net::detail {
|
||||
|
||||
template <size_t MaxValueSize, bool IsMutexed>
|
||||
inline void ClientMessageQueueImpl<MaxValueSize, IsMutexed>::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 <size_t MaxValueSize, bool IsMutexed>
|
||||
inline void ClientMessageQueueImpl<MaxValueSize, IsMutexed>::ClientUnpublish(
|
||||
int pubuid) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_queue.enqueue(ClientMessage{UnpublishMsg{pubuid}});
|
||||
}
|
||||
|
||||
template <size_t MaxValueSize, bool IsMutexed>
|
||||
inline void
|
||||
ClientMessageQueueImpl<MaxValueSize, IsMutexed>::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 <size_t MaxValueSize, bool IsMutexed>
|
||||
inline void ClientMessageQueueImpl<MaxValueSize, IsMutexed>::ClientSubscribe(
|
||||
int subuid, std::span<const std::string> topicNames,
|
||||
const PubSubOptionsImpl& options) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_queue.enqueue(ClientMessage{
|
||||
SubscribeMsg{subuid, {topicNames.begin(), topicNames.end()}, options}});
|
||||
}
|
||||
|
||||
template <size_t MaxValueSize, bool IsMutexed>
|
||||
inline void ClientMessageQueueImpl<MaxValueSize, IsMutexed>::ClientUnsubscribe(
|
||||
int subuid) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_queue.enqueue(ClientMessage{UnsubscribeMsg{subuid}});
|
||||
}
|
||||
|
||||
template <size_t MaxValueSize, bool IsMutexed>
|
||||
std::span<ClientMessage>
|
||||
ClientMessageQueueImpl<MaxValueSize, IsMutexed>::ReadQueue(
|
||||
std::span<ClientMessage> 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<ClientValueMsg>(&msg.contents)) {
|
||||
m_valueSize.size -= sizeof(ClientMessage) + val->value.size();
|
||||
m_valueSize.errored = false;
|
||||
}
|
||||
}
|
||||
++count;
|
||||
}
|
||||
return out.subspan(0, count);
|
||||
}
|
||||
|
||||
template <size_t MaxValueSize, bool IsMutexed>
|
||||
void ClientMessageQueueImpl<MaxValueSize, IsMutexed>::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 <size_t MaxValueSize, bool IsMutexed>
|
||||
void ClientMessageQueueImpl<MaxValueSize, IsMutexed>::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
|
||||
@@ -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() {}
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<uint8_t> GetRaw(std::span<const uint8_t> defaultValue) const;
|
||||
std::vector<uint8_t> GetRaw(std::span<const uint8_t> 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<bool> is special-cased in C++. 0 is false, any
|
||||
* non-zero value is true.
|
||||
*/
|
||||
std::vector<int> GetBooleanArray(std::span<const int> defaultValue) const;
|
||||
std::vector<int> GetBooleanArray(std::span<const int> 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<int64_t> GetIntegerArray(
|
||||
std::span<const int64_t> defaultValue) const;
|
||||
std::span<const int64_t> 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<float> GetFloatArray(std::span<const float> defaultValue) const;
|
||||
std::vector<float> GetFloatArray(std::span<const float> 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<double> GetDoubleArray(
|
||||
std::span<const double> defaultValue) const;
|
||||
std::span<const double> 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<std::string> GetStringArray(
|
||||
std::span<const std::string> defaultValue) const;
|
||||
std::span<const std::string> 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<TimestampedValueType> ReadQueue();
|
||||
std::vector<TimestampedValueType> 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<const uint8_t> value, int64_t time = 0);
|
||||
bool SetRaw(std::span<const uint8_t> 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<const bool> value, int64_t time = 0);
|
||||
bool SetBooleanArray(std::span<const bool> 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<const int> value, int64_t time = 0);
|
||||
bool SetBooleanArray(std::span<const int> 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<const int64_t> value, int64_t time = 0);
|
||||
bool SetIntegerArray(std::span<const int64_t> 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<const float> value, int64_t time = 0);
|
||||
bool SetFloatArray(std::span<const float> 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<const double> value, int64_t time = 0);
|
||||
bool SetDoubleArray(std::span<const double> 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<const std::string> value, int64_t time = 0);
|
||||
bool SetStringArray(std::span<const std::string> 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<const uint8_t> defaultValue);
|
||||
bool SetDefaultRaw(std::span<const uint8_t> 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<const int> defaultValue);
|
||||
bool SetDefaultBooleanArray(std::span<const int> 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<const int64_t> defaultValue);
|
||||
bool SetDefaultIntegerArray(std::span<const int64_t> 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<const float> defaultValue);
|
||||
bool SetDefaultFloatArray(std::span<const float> 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<const double> defaultValue);
|
||||
bool SetDefaultDoubleArray(std::span<const double> 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<const std::string> defaultValue);
|
||||
bool SetDefaultStringArray(std::span<const std::string> 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"
|
||||
|
||||
@@ -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 <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#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<uint8_t> GenericSubscriber::GetRaw(
|
||||
std::span<const uint8_t> defaultValue) const {
|
||||
return ::nt::GetRaw(m_subHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<int> GenericSubscriber::GetBooleanArray(
|
||||
std::span<const int> defaultValue) const {
|
||||
return ::nt::GetBooleanArray(m_subHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<int64_t> GenericSubscriber::GetIntegerArray(
|
||||
std::span<const int64_t> defaultValue) const {
|
||||
return ::nt::GetIntegerArray(m_subHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<float> GenericSubscriber::GetFloatArray(
|
||||
std::span<const float> defaultValue) const {
|
||||
return ::nt::GetFloatArray(m_subHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<double> GenericSubscriber::GetDoubleArray(
|
||||
std::span<const double> defaultValue) const {
|
||||
return ::nt::GetDoubleArray(m_subHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<std::string> GenericSubscriber::GetStringArray(
|
||||
std::span<const std::string> defaultValue) const {
|
||||
return ::nt::GetStringArray(m_subHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<Value> 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<const uint8_t> value,
|
||||
int64_t time) {
|
||||
return nt::SetRaw(m_pubHandle, value, time);
|
||||
}
|
||||
|
||||
inline bool GenericPublisher::SetBooleanArray(std::span<const bool> value,
|
||||
int64_t time) {
|
||||
return SetEntryValue(m_pubHandle, Value::MakeBooleanArray(value, time));
|
||||
}
|
||||
|
||||
inline bool GenericPublisher::SetBooleanArray(std::span<const int> value,
|
||||
int64_t time) {
|
||||
return nt::SetBooleanArray(m_pubHandle, value, time);
|
||||
}
|
||||
|
||||
inline bool GenericPublisher::SetIntegerArray(std::span<const int64_t> value,
|
||||
int64_t time) {
|
||||
return nt::SetIntegerArray(m_pubHandle, value, time);
|
||||
}
|
||||
|
||||
inline bool GenericPublisher::SetFloatArray(std::span<const float> value,
|
||||
int64_t time) {
|
||||
return nt::SetFloatArray(m_pubHandle, value, time);
|
||||
}
|
||||
|
||||
inline bool GenericPublisher::SetDoubleArray(std::span<const double> value,
|
||||
int64_t time) {
|
||||
return nt::SetDoubleArray(m_pubHandle, value, time);
|
||||
}
|
||||
|
||||
inline bool GenericPublisher::SetStringArray(std::span<const std::string> 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<const uint8_t> defaultValue) {
|
||||
return nt::SetDefaultRaw(m_pubHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline bool GenericPublisher::SetDefaultBooleanArray(
|
||||
std::span<const int> defaultValue) {
|
||||
return nt::SetDefaultBooleanArray(m_pubHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline bool GenericPublisher::SetDefaultIntegerArray(
|
||||
std::span<const int64_t> defaultValue) {
|
||||
return nt::SetDefaultIntegerArray(m_pubHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline bool GenericPublisher::SetDefaultFloatArray(
|
||||
std::span<const float> defaultValue) {
|
||||
return nt::SetDefaultFloatArray(m_pubHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline bool GenericPublisher::SetDefaultDoubleArray(
|
||||
std::span<const double> defaultValue) {
|
||||
return nt::SetDefaultDoubleArray(m_pubHandle, defaultValue);
|
||||
}
|
||||
|
||||
inline bool GenericPublisher::SetDefaultStringArray(
|
||||
std::span<const std::string> 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
|
||||
@@ -30,13 +30,31 @@ class MultiSubscriber final {
|
||||
*/
|
||||
MultiSubscriber(NetworkTableInstance inst,
|
||||
std::span<const std::string_view> 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"
|
||||
|
||||
@@ -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<const std::string_view> 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
|
||||
@@ -6,8 +6,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
@@ -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<NetworkTableType>(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<uint8_t> GetRaw(std::span<const uint8_t> defaultValue) const;
|
||||
std::vector<uint8_t> GetRaw(std::span<const uint8_t> 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<bool> is special-cased in C++. 0 is false, any
|
||||
* non-zero value is true.
|
||||
*/
|
||||
std::vector<int> GetBooleanArray(std::span<const int> defaultValue) const;
|
||||
std::vector<int> GetBooleanArray(std::span<const int> 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<int64_t> GetIntegerArray(
|
||||
std::span<const int64_t> defaultValue) const;
|
||||
std::span<const int64_t> 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<float> GetFloatArray(std::span<const float> defaultValue) const;
|
||||
std::vector<float> GetFloatArray(std::span<const float> 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<double> GetDoubleArray(
|
||||
std::span<const double> defaultValue) const;
|
||||
std::span<const double> 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<std::string> GetStringArray(
|
||||
std::span<const std::string> defaultValue) const;
|
||||
std::span<const std::string> 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<NetworkTableValue> ReadQueue();
|
||||
std::vector<NetworkTableValue> 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<const uint8_t> defaultValue);
|
||||
bool SetDefaultRaw(std::span<const uint8_t> 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<const int> defaultValue);
|
||||
bool SetDefaultBooleanArray(std::span<const int> 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<const int64_t> defaultValue);
|
||||
bool SetDefaultIntegerArray(std::span<const int64_t> 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<const float> defaultValue);
|
||||
bool SetDefaultFloatArray(std::span<const float> 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<const double> defaultValue);
|
||||
bool SetDefaultDoubleArray(std::span<const double> 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<const std::string> defaultValue);
|
||||
bool SetDefaultStringArray(std::span<const std::string> 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<const uint8_t> value, int64_t time = 0);
|
||||
bool SetRaw(std::span<const uint8_t> 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<const bool> value, int64_t time = 0);
|
||||
bool SetBooleanArray(std::span<const bool> 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<const int> value, int64_t time = 0);
|
||||
bool SetBooleanArray(std::span<const int> 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<const int64_t> value, int64_t time = 0);
|
||||
bool SetIntegerArray(std::span<const int64_t> 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<const float> value, int64_t time = 0);
|
||||
bool SetFloatArray(std::span<const float> 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<const double> value, int64_t time = 0);
|
||||
bool SetDoubleArray(std::span<const double> 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<const std::string> value, int64_t time = 0);
|
||||
bool SetStringArray(std::span<const std::string> 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"
|
||||
|
||||
@@ -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 <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#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<NetworkTableType>(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<uint8_t> NetworkTableEntry::GetRaw(
|
||||
std::span<const uint8_t> defaultValue) const {
|
||||
return nt::GetRaw(m_handle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<int> NetworkTableEntry::GetBooleanArray(
|
||||
std::span<const int> defaultValue) const {
|
||||
return nt::GetBooleanArray(m_handle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<int64_t> NetworkTableEntry::GetIntegerArray(
|
||||
std::span<const int64_t> defaultValue) const {
|
||||
return nt::GetIntegerArray(m_handle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<float> NetworkTableEntry::GetFloatArray(
|
||||
std::span<const float> defaultValue) const {
|
||||
return nt::GetFloatArray(m_handle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<double> NetworkTableEntry::GetDoubleArray(
|
||||
std::span<const double> defaultValue) const {
|
||||
return nt::GetDoubleArray(m_handle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<std::string> NetworkTableEntry::GetStringArray(
|
||||
std::span<const std::string> defaultValue) const {
|
||||
return nt::GetStringArray(m_handle, defaultValue);
|
||||
}
|
||||
|
||||
inline std::vector<NetworkTableValue> 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<const uint8_t> defaultValue) {
|
||||
return nt::SetDefaultRaw(m_handle, defaultValue);
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetDefaultBooleanArray(
|
||||
std::span<const int> defaultValue) {
|
||||
return nt::SetDefaultBooleanArray(m_handle, defaultValue);
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetDefaultIntegerArray(
|
||||
std::span<const int64_t> defaultValue) {
|
||||
return nt::SetDefaultIntegerArray(m_handle, defaultValue);
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetDefaultFloatArray(
|
||||
std::span<const float> defaultValue) {
|
||||
return nt::SetDefaultFloatArray(m_handle, defaultValue);
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetDefaultDoubleArray(
|
||||
std::span<const double> defaultValue) {
|
||||
return nt::SetDefaultDoubleArray(m_handle, defaultValue);
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetDefaultStringArray(
|
||||
std::span<const std::string> 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<const uint8_t> value,
|
||||
int64_t time) {
|
||||
return nt::SetRaw(m_handle, value, time);
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetBooleanArray(std::span<const bool> value,
|
||||
int64_t time) {
|
||||
return SetEntryValue(m_handle, Value::MakeBooleanArray(value, time));
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetBooleanArray(std::span<const int> value,
|
||||
int64_t time) {
|
||||
return nt::SetBooleanArray(m_handle, value, time);
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetIntegerArray(std::span<const int64_t> value,
|
||||
int64_t time) {
|
||||
return nt::SetIntegerArray(m_handle, value, time);
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetFloatArray(std::span<const float> value,
|
||||
int64_t time) {
|
||||
return nt::SetFloatArray(m_handle, value, time);
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetDoubleArray(std::span<const double> value,
|
||||
int64_t time) {
|
||||
return nt::SetDoubleArray(m_handle, value, time);
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetStringArray(
|
||||
std::span<const std::string> 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
|
||||
@@ -4,11 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -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 <wpi::ProtobufSerializable T>
|
||||
ProtobufTopic<T> GetProtobufTopic(std::string_view name) const;
|
||||
ProtobufTopic<T> GetProtobufTopic(std::string_view name) const {
|
||||
return ProtobufTopic<T>{GetTopic(name)};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a raw struct serialized value topic.
|
||||
@@ -267,7 +276,9 @@ class NetworkTableInstance final {
|
||||
*/
|
||||
template <typename T, typename... I>
|
||||
requires wpi::StructSerializable<T, I...>
|
||||
StructTopic<T, I...> GetStructTopic(std::string_view name, I... info) const;
|
||||
StructTopic<T, I...> GetStructTopic(std::string_view name, I... info) const {
|
||||
return StructTopic<T, I...>{GetTopic(name), std::move(info)...};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a raw struct serialized array topic.
|
||||
@@ -279,7 +290,9 @@ class NetworkTableInstance final {
|
||||
template <typename T, typename... I>
|
||||
requires wpi::StructSerializable<T, I...>
|
||||
StructArrayTopic<T, I...> GetStructArrayTopic(std::string_view name,
|
||||
I... info) const;
|
||||
I... info) const {
|
||||
return StructArrayTopic<T, I...>{GetTopic(name), std::move(info)...};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Published Topics.
|
||||
@@ -288,7 +301,10 @@ class NetworkTableInstance final {
|
||||
*
|
||||
* @return Array of topics.
|
||||
*/
|
||||
std::vector<Topic> GetTopics();
|
||||
std::vector<Topic> 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<Topic> GetTopics(std::string_view prefix);
|
||||
std::vector<Topic> 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<Topic> GetTopics(std::string_view prefix, unsigned int types);
|
||||
std::vector<Topic> 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<Topic> GetTopics(std::string_view prefix,
|
||||
std::span<std::string_view> types);
|
||||
std::span<std::string_view> 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<TopicInfo> GetTopicInfo();
|
||||
std::vector<TopicInfo> 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<TopicInfo> GetTopicInfo(std::string_view prefix);
|
||||
std::vector<TopicInfo> 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<TopicInfo> 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<TopicInfo> GetTopicInfo(std::string_view prefix,
|
||||
std::span<std::string_view> types);
|
||||
std::span<std::string_view> 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<const std::string_view> 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<const std::pair<std::string_view, unsigned int>> servers);
|
||||
std::span<const std::pair<std::string_view, unsigned int>> 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<ConnectionInfo> GetConnections() const;
|
||||
std::vector<ConnectionInfo> 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<int64_t> GetServerTimeOffset() const;
|
||||
std::optional<int64_t> 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<const uint8_t> schema);
|
||||
std::span<const uint8_t> 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 <wpi::ProtobufSerializable T>
|
||||
void AddProtobufSchema(wpi::ProtobufMessage<T>& msg);
|
||||
void AddProtobufSchema(wpi::ProtobufMessage<T>& 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 <typename T, typename... I>
|
||||
requires wpi::StructSerializable<T, I...>
|
||||
void AddStructSchema(const I&... info);
|
||||
void AddStructSchema(const I&... info) {
|
||||
wpi::ForEachStructSchema<T>(
|
||||
[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"
|
||||
|
||||
@@ -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 <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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 <wpi::ProtobufSerializable T>
|
||||
inline ProtobufTopic<T> NetworkTableInstance::GetProtobufTopic(
|
||||
std::string_view name) const {
|
||||
return ProtobufTopic<T>{GetTopic(name)};
|
||||
}
|
||||
|
||||
template <typename T, typename... I>
|
||||
requires wpi::StructSerializable<T, I...>
|
||||
inline StructTopic<T, I...> NetworkTableInstance::GetStructTopic(
|
||||
std::string_view name, I... info) const {
|
||||
return StructTopic<T, I...>{GetTopic(name), std::move(info)...};
|
||||
}
|
||||
|
||||
template <typename T, typename... I>
|
||||
requires wpi::StructSerializable<T, I...>
|
||||
inline StructArrayTopic<T, I...> NetworkTableInstance::GetStructArrayTopic(
|
||||
std::string_view name, I... info) const {
|
||||
return StructArrayTopic<T, I...>{GetTopic(name), std::move(info)...};
|
||||
}
|
||||
|
||||
inline std::vector<Topic> NetworkTableInstance::GetTopics() {
|
||||
auto handles = ::nt::GetTopics(m_handle, "", 0);
|
||||
return {handles.begin(), handles.end()};
|
||||
}
|
||||
|
||||
inline std::vector<Topic> NetworkTableInstance::GetTopics(
|
||||
std::string_view prefix) {
|
||||
auto handles = ::nt::GetTopics(m_handle, prefix, 0);
|
||||
return {handles.begin(), handles.end()};
|
||||
}
|
||||
|
||||
inline std::vector<Topic> 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<Topic> NetworkTableInstance::GetTopics(
|
||||
std::string_view prefix, std::span<std::string_view> types) {
|
||||
auto handles = ::nt::GetTopics(m_handle, prefix, types);
|
||||
return {handles.begin(), handles.end()};
|
||||
}
|
||||
|
||||
inline std::vector<TopicInfo> NetworkTableInstance::GetTopicInfo() {
|
||||
return ::nt::GetTopicInfo(m_handle, "", 0);
|
||||
}
|
||||
|
||||
inline std::vector<TopicInfo> NetworkTableInstance::GetTopicInfo(
|
||||
std::string_view prefix) {
|
||||
return ::nt::GetTopicInfo(m_handle, prefix, 0);
|
||||
}
|
||||
|
||||
inline std::vector<TopicInfo> NetworkTableInstance::GetTopicInfo(
|
||||
std::string_view prefix, unsigned int types) {
|
||||
return ::nt::GetTopicInfo(m_handle, prefix, types);
|
||||
}
|
||||
|
||||
inline std::vector<TopicInfo> NetworkTableInstance::GetTopicInfo(
|
||||
std::string_view prefix, std::span<std::string_view> 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<const std::string_view> 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<const std::pair<std::string_view, unsigned int>> 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<ConnectionInfo> NetworkTableInstance::GetConnections()
|
||||
const {
|
||||
return ::nt::GetConnections(m_handle);
|
||||
}
|
||||
|
||||
inline bool NetworkTableInstance::IsConnected() const {
|
||||
return ::nt::IsConnected(m_handle);
|
||||
}
|
||||
|
||||
inline std::optional<int64_t> 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<const uint8_t> 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 <wpi::ProtobufSerializable T>
|
||||
void NetworkTableInstance::AddProtobufSchema(wpi::ProtobufMessage<T>& msg) {
|
||||
msg.ForEachProtobufDescriptor(
|
||||
[this](auto typeString) { return HasSchema(typeString); },
|
||||
[this](auto typeString, auto schema) {
|
||||
AddSchema(typeString, "proto:FileDescriptorProto", schema);
|
||||
});
|
||||
}
|
||||
|
||||
template <typename T, typename... I>
|
||||
requires wpi::StructSerializable<T, I...>
|
||||
void NetworkTableInstance::AddStructSchema(const I&... info) {
|
||||
wpi::ForEachStructSchema<T>(
|
||||
[this](auto typeString, auto schema) {
|
||||
AddSchema(typeString, "structschema", schema);
|
||||
},
|
||||
info...);
|
||||
}
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
} // namespace nt
|
||||
@@ -4,11 +4,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<const std::string_view> 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<const std::string_view> 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<Event> ReadQueue();
|
||||
std::vector<Event> ReadQueue() { return ::nt::ReadListenerQueue(m_handle); }
|
||||
|
||||
private:
|
||||
NT_ListenerPoller m_handle{0};
|
||||
};
|
||||
|
||||
} // namespace nt
|
||||
|
||||
#include "NetworkTableListener.inc"
|
||||
|
||||
@@ -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 <span>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<const std::string_view> 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<const std::string_view> 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<Event> NetworkTableListenerPoller::ReadQueue() {
|
||||
return ::nt::ReadListenerQueue(m_handle);
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
@@ -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<NetworkTableType>(::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"
|
||||
|
||||
@@ -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 <string>
|
||||
|
||||
#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<NetworkTableType>(::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
|
||||
@@ -6,11 +6,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/json_fwd.h>
|
||||
#include <wpi/json.h>
|
||||
|
||||
#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<TimestampedValueType> ReadQueue();
|
||||
std::vector<TimestampedValueType> ReadQueue() {
|
||||
std::vector<TimestampedUnit<T>> 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<T>{::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<T>{::nt::GetTopicFromHandle(m_pubHandle)};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -206,7 +226,8 @@ class UnitEntry final : public UnitSubscriber<T>, public UnitPublisher<T> {
|
||||
* @param handle Native handle
|
||||
* @param defaultValue Default value
|
||||
*/
|
||||
UnitEntry(NT_Entry handle, ParamType defaultValue);
|
||||
UnitEntry(NT_Entry handle, ParamType defaultValue)
|
||||
: UnitSubscriber<T>{handle, defaultValue}, UnitPublisher<T>{handle} {}
|
||||
|
||||
/**
|
||||
* Determines if the native handle is valid.
|
||||
@@ -227,12 +248,14 @@ class UnitEntry final : public UnitSubscriber<T>, public UnitPublisher<T> {
|
||||
*
|
||||
* @return Topic
|
||||
*/
|
||||
TopicType GetTopic() const;
|
||||
TopicType GetTopic() const {
|
||||
return UnitTopic<T>{::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<T>{
|
||||
::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<T>{
|
||||
::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<T>{::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<T>{
|
||||
::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<T>{::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<T>{
|
||||
::nt::GetEntry(m_handle, NT_DOUBLE, typeString, options), defaultValue};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace nt
|
||||
|
||||
#include "networktables/UnitTopic.inc"
|
||||
|
||||
@@ -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 <vector>
|
||||
|
||||
#include <wpi/json.h>
|
||||
|
||||
#include "networktables/NetworkTableType.h"
|
||||
#include "networktables/UnitTopic.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
namespace nt {
|
||||
|
||||
template <typename T>
|
||||
inline UnitSubscriber<T>::UnitSubscriber(NT_Subscriber handle, T defaultValue)
|
||||
: Subscriber{handle}, m_defaultValue{defaultValue} {}
|
||||
|
||||
template <typename T>
|
||||
inline T UnitSubscriber<T>::Get() const {
|
||||
return Get(m_defaultValue);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T UnitSubscriber<T>::Get(T defaultValue) const {
|
||||
return T{::nt::GetDouble(m_subHandle, defaultValue.value())};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline TimestampedUnit<T> UnitSubscriber<T>::GetAtomic() const {
|
||||
return GetAtomic(m_defaultValue);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline TimestampedUnit<T> UnitSubscriber<T>::GetAtomic(T defaultValue) const {
|
||||
auto doubleVal = ::nt::GetAtomicDouble(m_subHandle, defaultValue.value());
|
||||
return {doubleVal.time, doubleVal.serverTime, doubleVal.value};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline std::vector<TimestampedUnit<T>> UnitSubscriber<T>::ReadQueue() {
|
||||
std::vector<TimestampedUnit<T>> 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 <typename T>
|
||||
inline UnitTopic<T> UnitSubscriber<T>::GetTopic() const {
|
||||
return UnitTopic<T>{::nt::GetTopicFromHandle(m_subHandle)};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline UnitPublisher<T>::UnitPublisher(NT_Publisher handle)
|
||||
: Publisher{handle} {}
|
||||
|
||||
template <typename T>
|
||||
inline void UnitPublisher<T>::Set(T value, int64_t time) {
|
||||
::nt::SetDouble(m_pubHandle, value.value(), time);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void UnitPublisher<T>::SetDefault(T value) {
|
||||
::nt::SetDefaultDouble(m_pubHandle, value.value());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline UnitTopic<T> UnitPublisher<T>::GetTopic() const {
|
||||
return UnitTopic<T>{::nt::GetTopicFromHandle(m_pubHandle)};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline UnitEntry<T>::UnitEntry(NT_Entry handle, T defaultValue)
|
||||
: UnitSubscriber<T>{handle, defaultValue}, UnitPublisher<T>{handle} {}
|
||||
|
||||
template <typename T>
|
||||
inline UnitTopic<T> UnitEntry<T>::GetTopic() const {
|
||||
return UnitTopic<T>{::nt::GetTopicFromHandle(this->m_subHandle)};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void UnitEntry<T>::Unpublish() {
|
||||
::nt::Unpublish(this->m_pubHandle);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool UnitTopic<T>::IsMatchingUnit() const {
|
||||
return GetProperty("unit") == T{}.name();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline UnitSubscriber<T> UnitTopic<T>::Subscribe(T defaultValue,
|
||||
const PubSubOptions& options) {
|
||||
return UnitSubscriber<T>{
|
||||
::nt::Subscribe(m_handle, NT_DOUBLE, "double", options), defaultValue};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline UnitSubscriber<T> UnitTopic<T>::SubscribeEx(
|
||||
std::string_view typeString, T defaultValue, const PubSubOptions& options) {
|
||||
return UnitSubscriber<T>{
|
||||
::nt::Subscribe(m_handle, NT_DOUBLE, typeString, options), defaultValue};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline UnitPublisher<T> UnitTopic<T>::Publish(const PubSubOptions& options) {
|
||||
return UnitPublisher<T>{::nt::PublishEx(m_handle, NT_DOUBLE, "double",
|
||||
{{"unit", T{}.name()}}, options)};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline UnitPublisher<T> UnitTopic<T>::PublishEx(std::string_view typeString,
|
||||
const wpi::json& properties,
|
||||
const PubSubOptions& options) {
|
||||
wpi::json props = properties;
|
||||
props["unit"] = T{}.name();
|
||||
return UnitPublisher<T>{
|
||||
::nt::PublishEx(m_handle, NT_DOUBLE, typeString, props, options)};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline UnitEntry<T> UnitTopic<T>::GetEntry(T defaultValue,
|
||||
const PubSubOptions& options) {
|
||||
return UnitEntry<T>{::nt::GetEntry(m_handle, NT_DOUBLE, "double", options),
|
||||
defaultValue};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline UnitEntry<T> UnitTopic<T>::GetEntryEx(std::string_view typeString,
|
||||
T defaultValue,
|
||||
const PubSubOptions& options) {
|
||||
return UnitEntry<T>{::nt::GetEntry(m_handle, NT_DOUBLE, typeString, options),
|
||||
defaultValue};
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
Reference in New Issue
Block a user