WPILibC++ 2023.4.3-108-ge5452e3
nt::GenericSubscriber Class Reference

NetworkTables generic subscriber. More...

#include <networktables/GenericEntry.h>

Inheritance diagram for nt::GenericSubscriber:
nt::Subscriber 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. More...
 
ValueType Get () const
 Get the last published value. More...
 
bool GetBoolean (bool defaultValue) const
 Gets the entry's value as a boolean. More...
 
int64_t GetInteger (int64_t defaultValue) const
 Gets the entry's value as a integer. More...
 
float GetFloat (float defaultValue) const
 Gets the entry's value as a float. More...
 
double GetDouble (double defaultValue) const
 Gets the entry's value as a double. More...
 
std::string GetString (std::string_view defaultValue) const
 Gets the entry's value as a string. More...
 
std::vector< uint8_t > GetRaw (std::span< const uint8_t > defaultValue) const
 Gets the entry's value as a raw. More...
 
std::vector< int > GetBooleanArray (std::span< const int > defaultValue) const
 Gets the entry's value as a boolean array. More...
 
std::vector< int64_t > GetIntegerArray (std::span< const int64_t > defaultValue) const
 Gets the entry's value as a integer array. More...
 
std::vector< float > GetFloatArray (std::span< const float > defaultValue) const
 Gets the entry's value as a float array. More...
 
std::vector< double > GetDoubleArray (std::span< const double > defaultValue) const
 Gets the entry's value as a double array. More...
 
std::vector< std::string > GetStringArray (std::span< const std::string > defaultValue) const
 Gets the entry's value as a string array. More...
 
std::vector< TimestampedValueTypeReadQueue ()
 Get an array of all value changes since the last call to ReadQueue. More...
 
TopicType GetTopic () const
 Get the corresponding topic. More...
 
- Public Member Functions inherited from nt::Subscriber
virtual ~Subscriber ()
 
 Subscriber (const Subscriber &)=delete
 
Subscriberoperator= (const Subscriber &)=delete
 
 Subscriber (Subscriber &&)
 
Subscriberoperator= (Subscriber &&)
 
 operator bool () const
 Determines if the native handle is valid. More...
 
NT_Subscriber GetHandle () const
 Gets the native handle for the subscriber. More...
 
bool Exists () const
 Determines if the topic is currently being published. More...
 
int64_t GetLastChange () const
 Gets the last time the value was changed. More...
 
Topic GetTopic () const
 Gets the subscribed-to topic. More...
 

Additional Inherited Members

- Protected Member Functions inherited from nt::Subscriber
 Subscriber ()=default
 
 Subscriber (NT_Subscriber handle)
 
- Protected Attributes inherited from 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]

nt::GenericSubscriber::GenericSubscriber ( )
default

◆ GenericSubscriber() [2/2]

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()

Value 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 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 > 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 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 > 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 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 > 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 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 > 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 > 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 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 > 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()

Topic nt::GenericSubscriber::GetTopic ( ) const
inline

Get the corresponding topic.

Returns
Topic

◆ ReadQueue()

std::vector< Value > 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 files: