WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::nt::UnitSubscriber< T > Class Template Reference

NetworkTables unit-typed subscriber. More...

#include <wpi/nt/UnitTopic.hpp>

Inheritance diagram for wpi::nt::UnitSubscriber< T >:
wpi::nt::Subscriber wpi::nt::UnitEntry< T >

Public Types

using TopicType = UnitTopic<T>
using ValueType = T
using ParamType = T
using TimestampedValueType = TimestampedUnit<T>

Public Member Functions

 UnitSubscriber ()=default
 UnitSubscriber (NT_Subscriber handle, ParamType defaultValue)
 Construct from a subscriber handle; recommended to use UnitTopic::Subscribe() instead.
ValueType Get () const
 Get the last published value.
ValueType Get (ParamType defaultValue) const
 Get the last published value.
TimestampedValueType GetAtomic () const
 Get the last published value along with its timestamp If no value has been published, returns the stored default value and a timestamp of 0.
TimestampedValueType GetAtomic (ParamType defaultValue) const
 Get the last published value along with its timestamp.
std::vector< TimestampedValueTypeReadQueue ()
 Get an array of all value changes since the last call to ReadQueue.
TopicType GetTopic () const
 Get the corresponding topic.
Public Member Functions inherited from wpi::nt::Subscriber
virtual ~Subscriber ()
 Subscriber (const Subscriber &)=delete
Subscriberoperator= (const Subscriber &)=delete
 Subscriber (Subscriber &&rhs)
Subscriberoperator= (Subscriber &&rhs)
 operator bool () const
 Determines if the native handle is valid.
NT_Subscriber GetHandle () const
 Gets the native handle for the subscriber.
bool Exists () const
 Determines if the topic is currently being published.
int64_t GetLastChange () const
 Gets the last time the value was changed.
Topic GetTopic () const
 Gets the subscribed-to topic.

Additional Inherited Members

Protected Member Functions inherited from wpi::nt::Subscriber
 Subscriber ()=default
 Subscriber (NT_Subscriber handle)
Protected Attributes inherited from wpi::nt::Subscriber
NT_Subscriber m_subHandle {0}

Detailed Description

template<typename T>
class wpi::nt::UnitSubscriber< T >

NetworkTables unit-typed subscriber.

Template Parameters
Tunit type, e.g. wpi::units::meter_t

Member Typedef Documentation

◆ ParamType

template<typename T>
using wpi::nt::UnitSubscriber< T >::ParamType = T

◆ TimestampedValueType

template<typename T>
using wpi::nt::UnitSubscriber< T >::TimestampedValueType = TimestampedUnit<T>

◆ TopicType

template<typename T>
using wpi::nt::UnitSubscriber< T >::TopicType = UnitTopic<T>

◆ ValueType

template<typename T>
using wpi::nt::UnitSubscriber< T >::ValueType = T

Constructor & Destructor Documentation

◆ UnitSubscriber() [1/2]

template<typename T>
wpi::nt::UnitSubscriber< T >::UnitSubscriber ( )
default

◆ UnitSubscriber() [2/2]

template<typename T>
wpi::nt::UnitSubscriber< T >::UnitSubscriber ( NT_Subscriber handle,
ParamType defaultValue )
inline

Construct from a subscriber handle; recommended to use UnitTopic::Subscribe() instead.

Parameters
handleNative handle
defaultValueDefault value

Member Function Documentation

◆ Get() [1/2]

template<typename T>
ValueType wpi::nt::UnitSubscriber< T >::Get ( ) const
inline

Get the last published value.

If no value has been published, returns the stored default value.

Returns
value

◆ Get() [2/2]

template<typename T>
ValueType wpi::nt::UnitSubscriber< T >::Get ( ParamType defaultValue) const
inline

Get the last published value.

If no value has been published, returns the passed defaultValue.

Parameters
defaultValuedefault value to return if no value has been published
Returns
value

◆ GetAtomic() [1/2]

template<typename T>
TimestampedValueType wpi::nt::UnitSubscriber< T >::GetAtomic ( ) const
inline

Get the last published value along with its timestamp If no value has been published, returns the stored default value and a timestamp of 0.

Returns
timestamped value

◆ GetAtomic() [2/2]

template<typename T>
TimestampedValueType wpi::nt::UnitSubscriber< T >::GetAtomic ( ParamType defaultValue) const
inline

Get the last published value along with its timestamp.

If no value has been published, returns the passed defaultValue and a timestamp of 0.

Parameters
defaultValuedefault value to return if no value has been published
Returns
timestamped value

◆ GetTopic()

template<typename T>
TopicType wpi::nt::UnitSubscriber< T >::GetTopic ( ) const
inline

Get the corresponding topic.

Returns
Topic

◆ ReadQueue()

template<typename T>
std::vector< TimestampedValueType > wpi::nt::UnitSubscriber< T >::ReadQueue ( )
inline

Get an array of all value changes since the last call to ReadQueue.

Also provides a timestamp for each value.

Note
The "poll storage" subscribe option can be used to set the queue depth.
Returns
Array of timestamped values; empty array if no new changes have been published since the previous call.

The documentation for this class was generated from the following file: