WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::nt::GenericSubscriber Class Reference

NetworkTables generic subscriber. More...

#include <wpi/nt/GenericEntry.hpp>

Inheritance diagram for wpi::nt::GenericSubscriber:
wpi::nt::Subscriber wpi::nt::GenericEntry

Public Types

using TopicType = Topic
using ValueType = Value
using ParamType = const Value&
using TimestampedValueType = Value

Public Member Functions

 GenericSubscriber ()=default
 GenericSubscriber (NT_Subscriber handle)
 Construct from a subscriber handle; recommended to use Topic::GenericSubscribe() instead.
ValueType Get () const
 Get the last published value.
bool GetBoolean (bool defaultValue) const
 Gets the entry's value as a boolean.
int64_t GetInteger (int64_t defaultValue) const
 Gets the entry's value as a integer.
float GetFloat (float defaultValue) const
 Gets the entry's value as a float.
double GetDouble (double defaultValue) const
 Gets the entry's value as a double.
std::string GetString (std::string_view defaultValue) const
 Gets the entry's value as a string.
std::vector< uint8_t > GetRaw (std::span< const uint8_t > defaultValue) const
 Gets the entry's value as a raw.
std::vector< int > GetBooleanArray (std::span< const int > defaultValue) const
 Gets the entry's value as a boolean array.
std::vector< int64_t > GetIntegerArray (std::span< const int64_t > defaultValue) const
 Gets the entry's value as a integer array.
std::vector< float > GetFloatArray (std::span< const float > defaultValue) const
 Gets the entry's value as a float array.
std::vector< double > GetDoubleArray (std::span< const double > defaultValue) const
 Gets the entry's value as a double array.
std::vector< std::string > GetStringArray (std::span< const std::string > defaultValue) const
 Gets the entry's value as a string array.
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

NetworkTables generic subscriber.

Member Typedef Documentation

◆ ParamType

◆ TimestampedValueType

◆ TopicType

◆ ValueType

Constructor & Destructor Documentation

◆ GenericSubscriber() [1/2]

wpi::nt::GenericSubscriber::GenericSubscriber ( )
default

◆ GenericSubscriber() [2/2]

wpi::nt::GenericSubscriber::GenericSubscriber ( NT_Subscriber handle)
inlineexplicit

Construct from a subscriber handle; recommended to use Topic::GenericSubscribe() instead.

Parameters
handleNative handle

Member Function Documentation

◆ Get()

ValueType wpi::nt::GenericSubscriber::Get ( ) const
inline

Get the last published value.

If no value has been published, returns a value with unassigned type.

Returns
value

◆ GetBoolean()

bool wpi::nt::GenericSubscriber::GetBoolean ( bool defaultValue) const
inline

Gets the entry's value as a boolean.

If the entry does not exist or is of different type, it will return the default value.

Parameters
defaultValuethe value to be returned if no value is found
Returns
the entry's value or the given default value

◆ GetBooleanArray()

std::vector< int > wpi::nt::GenericSubscriber::GetBooleanArray ( std::span< const int > defaultValue) const
inline

Gets the entry's value as a boolean array.

If the entry does not exist or is of different type, it will return the default value.

Parameters
defaultValuethe value to be returned if no value is found
Returns
the entry's value or the given default value
Note
This makes a copy of the array. If the overhead of this is a concern, use GetValue() instead.
The returned array is std::vector<int> instead of std::vector<bool> because std::vector<bool> is special-cased in C++. 0 is false, any non-zero value is true.

◆ GetDouble()

double wpi::nt::GenericSubscriber::GetDouble ( double defaultValue) const
inline

Gets the entry's value as a double.

If the entry does not exist or is of different type, it will return the default value.

Parameters
defaultValuethe value to be returned if no value is found
Returns
the entry's value or the given default value

◆ GetDoubleArray()

std::vector< double > wpi::nt::GenericSubscriber::GetDoubleArray ( std::span< const double > defaultValue) const
inline

Gets the entry's value as a double array.

If the entry does not exist or is of different type, it will return the default value.

Parameters
defaultValuethe value to be returned if no value is found
Returns
the entry's value or the given default value
Note
This makes a copy of the array. If the overhead of this is a concern, use GetValue() instead.

◆ GetFloat()

float wpi::nt::GenericSubscriber::GetFloat ( float defaultValue) const
inline

Gets the entry's value as a float.

If the entry does not exist or is of different type, it will return the default value.

Parameters
defaultValuethe value to be returned if no value is found
Returns
the entry's value or the given default value

◆ GetFloatArray()

std::vector< float > wpi::nt::GenericSubscriber::GetFloatArray ( std::span< const float > defaultValue) const
inline

Gets the entry's value as a float array.

If the entry does not exist or is of different type, it will return the default value.

Parameters
defaultValuethe value to be returned if no value is found
Returns
the entry's value or the given default value
Note
This makes a copy of the array. If the overhead of this is a concern, use GetValue() instead.

◆ GetInteger()

int64_t wpi::nt::GenericSubscriber::GetInteger ( int64_t defaultValue) const
inline

Gets the entry's value as a integer.

If the entry does not exist or is of different type, it will return the default value.

Parameters
defaultValuethe value to be returned if no value is found
Returns
the entry's value or the given default value

◆ GetIntegerArray()

std::vector< int64_t > wpi::nt::GenericSubscriber::GetIntegerArray ( std::span< const int64_t > defaultValue) const
inline

Gets the entry's value as a integer array.

If the entry does not exist or is of different type, it will return the default value.

Parameters
defaultValuethe value to be returned if no value is found
Returns
the entry's value or the given default value
Note
This makes a copy of the array. If the overhead of this is a concern, use GetValue() instead.

◆ GetRaw()

std::vector< uint8_t > wpi::nt::GenericSubscriber::GetRaw ( std::span< const uint8_t > defaultValue) const
inline

Gets the entry's value as a raw.

If the entry does not exist or is of different type, it will return the default value.

Parameters
defaultValuethe value to be returned if no value is found
Returns
the entry's value or the given default value

◆ GetString()

std::string wpi::nt::GenericSubscriber::GetString ( std::string_view defaultValue) const
inline

Gets the entry's value as a string.

If the entry does not exist or is of different type, it will return the default value.

Parameters
defaultValuethe value to be returned if no value is found
Returns
the entry's value or the given default value

◆ GetStringArray()

std::vector< std::string > wpi::nt::GenericSubscriber::GetStringArray ( std::span< const std::string > defaultValue) const
inline

Gets the entry's value as a string array.

If the entry does not exist or is of different type, it will return the default value.

Parameters
defaultValuethe value to be returned if no value is found
Returns
the entry's value or the given default value
Note
This makes a copy of the array. If the overhead of this is a concern, use GetValue() instead.

◆ GetTopic()

TopicType wpi::nt::GenericSubscriber::GetTopic ( ) const
inline

Get the corresponding topic.

Returns
Topic

◆ ReadQueue()

std::vector< TimestampedValueType > wpi::nt::GenericSubscriber::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: