WPILibC++ 2024.1.1-beta-4
nt::Topic Class Reference

NetworkTables Topic. More...

#include <networktables/Topic.h>

Inheritance diagram for nt::Topic:
nt::BooleanArrayTopic nt::BooleanTopic nt::DoubleArrayTopic nt::DoubleTopic nt::FloatArrayTopic nt::FloatTopic nt::IntegerArrayTopic nt::IntegerTopic nt::ProtobufTopic< T > nt::RawTopic nt::StringArrayTopic nt::StringTopic nt::StructArrayTopic< T > nt::StructTopic< T > nt::UnitTopic< T >

Public Member Functions

 Topic ()=default
 
 Topic (NT_Topic handle)
 
 operator bool () const
 Determines if the native handle is valid. More...
 
NT_Topic GetHandle () const
 Gets the native handle for the topic. More...
 
NetworkTableInstance GetInstance () const
 Gets the instance for the topic. More...
 
std::string GetName () const
 Gets the name of the topic. More...
 
NetworkTableType GetType () const
 Gets the type of the topic. More...
 
std::string GetTypeString () const
 Gets the type string of the topic. More...
 
void SetPersistent (bool persistent)
 Make value persistent through server restarts. More...
 
bool IsPersistent () const
 Returns whether the value is persistent through server restarts. More...
 
void SetRetained (bool retained)
 Make the server retain the topic even when there are no publishers. More...
 
bool IsRetained () const
 Returns whether the topic is retained by server when there are no publishers. More...
 
void SetCached (bool cached)
 Allow storage of the topic's last value, allowing the value to be read (and not just accessed through event queues and listeners). More...
 
bool IsCached () const
 Returns whether the topic's last value is stored. More...
 
bool Exists () const
 Determines if the topic is currently being published. More...
 
wpi::json GetProperty (std::string_view name) const
 Gets the current value of a property (as a JSON object). More...
 
void SetProperty (std::string_view name, const wpi::json &value)
 Sets a property value. More...
 
void DeleteProperty (std::string_view name)
 Deletes a property. More...
 
wpi::json GetProperties () const
 Gets all topic properties as a JSON object. More...
 
bool SetProperties (const wpi::json &properties)
 Updates multiple topic properties. More...
 
TopicInfo GetInfo () const
 Gets combined information about the topic. More...
 
GenericSubscriber GenericSubscribe (const PubSubOptions &options=kDefaultPubSubOptions)
 Create a new subscriber to the topic. More...
 
GenericSubscriber GenericSubscribe (std::string_view typeString, const PubSubOptions &options=kDefaultPubSubOptions)
 Create a new subscriber to the topic. More...
 
GenericPublisher GenericPublish (std::string_view typeString, const PubSubOptions &options=kDefaultPubSubOptions)
 Create a new publisher to the topic. More...
 
GenericPublisher GenericPublishEx (std::string_view typeString, const wpi::json &properties, const PubSubOptions &options=kDefaultPubSubOptions)
 Create a new publisher to the topic, with type string and initial properties. More...
 
GenericEntry GetGenericEntry (const PubSubOptions &options=kDefaultPubSubOptions)
 Create a new generic entry for the topic. More...
 
GenericEntry GetGenericEntry (std::string_view typeString, const PubSubOptions &options=kDefaultPubSubOptions)
 Create a new generic entry for the topic. More...
 
bool operator== (const Topic &) const =default
 Equality operator. More...
 

Protected Attributes

NT_Topic m_handle {0}
 

Detailed Description

NetworkTables Topic.

Constructor & Destructor Documentation

◆ Topic() [1/2]

nt::Topic::Topic ( )
default

◆ Topic() [2/2]

nt::Topic::Topic ( NT_Topic  handle)
inlineexplicit

Member Function Documentation

◆ DeleteProperty()

void nt::Topic::DeleteProperty ( std::string_view  name)
inline

Deletes a property.

Has no effect if the property does not exist.

Parameters
nameproperty name

◆ Exists()

bool nt::Topic::Exists ( ) const
inline

Determines if the topic is currently being published.

Returns
True if the topic exists, false otherwise.

◆ GenericPublish()

GenericPublisher nt::Topic::GenericPublish ( std::string_view  typeString,
const PubSubOptions options = kDefaultPubSubOptions 
)

Create a new publisher to the topic.

The publisher is only active as long as the returned object is not destroyed.

Note
It is not possible to publish two different data types to the same topic. Conflicts between publishers are typically resolved by the server on a first-come, first-served basis. Any published values that do not match the topic's data type are dropped (ignored). To determine if the data type matches, use the appropriate Topic functions.
Parameters
typeStringtype string
optionspublish options
Returns
publisher

◆ GenericPublishEx()

GenericPublisher nt::Topic::GenericPublishEx ( std::string_view  typeString,
const wpi::json &  properties,
const PubSubOptions options = kDefaultPubSubOptions 
)

Create a new publisher to the topic, with type string and initial properties.

The publisher is only active as long as the returned object is not destroyed.

Note
It is not possible to publish two different data types to the same topic. Conflicts between publishers are typically resolved by the server on a first-come, first-served basis. Any published values that do not match the topic's data type are dropped (ignored). To determine if the data type matches, use the appropriate Topic functions.
Parameters
typeStringtype string
propertiesJSON properties
optionspublish options
Returns
publisher

◆ GenericSubscribe() [1/2]

GenericSubscriber nt::Topic::GenericSubscribe ( const PubSubOptions options = kDefaultPubSubOptions)

Create a new subscriber to the topic.

The subscriber is only active as long as the returned object is not destroyed.

Parameters
optionssubscribe options
Returns
subscriber

◆ GenericSubscribe() [2/2]

GenericSubscriber nt::Topic::GenericSubscribe ( std::string_view  typeString,
const PubSubOptions options = kDefaultPubSubOptions 
)

Create a new subscriber to the topic.

The subscriber is only active as long as the returned object is not destroyed.

Note
Subscribers that do not match the published data type do not return any values. To determine if the data type matches, use the appropriate Topic functions.
Parameters
typeStringtype string
optionssubscribe options
Returns
subscriber

◆ GetGenericEntry() [1/2]

GenericEntry nt::Topic::GetGenericEntry ( const PubSubOptions options = kDefaultPubSubOptions)

Create a new generic entry for the topic.

Entries act as a combination of a subscriber and a weak publisher. The subscriber is active as long as the entry is not destroyed. The publisher is created when the entry is first written to, and remains active until either Unpublish() is called or the entry is destroyed.

Note
It is not possible to use two different data types with the same topic. Conflicts between publishers are typically resolved by the server on a first-come, first-served basis. Any published values that do not match the topic's data type are dropped (ignored), and the entry will show no new values if the data type does not match. To determine if the data type matches, use the appropriate Topic functions.
Parameters
optionspublish and/or subscribe options
Returns
entry

◆ GetGenericEntry() [2/2]

GenericEntry nt::Topic::GetGenericEntry ( std::string_view  typeString,
const PubSubOptions options = kDefaultPubSubOptions 
)

Create a new generic entry for the topic.

Entries act as a combination of a subscriber and a weak publisher. The subscriber is active as long as the entry is not destroyed. The publisher is created when the entry is first written to, and remains active until either Unpublish() is called or the entry is destroyed.

Note
It is not possible to use two different data types with the same topic. Conflicts between publishers are typically resolved by the server on a first-come, first-served basis. Any published values that do not match the topic's data type are dropped (ignored), and the entry will show no new values if the data type does not match. To determine if the data type matches, use the appropriate Topic functions.
Parameters
typeStringtype string
optionspublish and/or subscribe options
Returns
entry

◆ GetHandle()

NT_Topic nt::Topic::GetHandle ( ) const
inline

Gets the native handle for the topic.

Returns
Native handle

◆ GetInfo()

TopicInfo nt::Topic::GetInfo ( ) const
inline

Gets combined information about the topic.

Returns
Topic information

◆ GetInstance()

NetworkTableInstance nt::Topic::GetInstance ( ) const

Gets the instance for the topic.

Returns
Instance

◆ GetName()

std::string nt::Topic::GetName ( ) const
inline

Gets the name of the topic.

Returns
the topic's name

◆ GetProperties()

wpi::json nt::Topic::GetProperties ( ) const

Gets all topic properties as a JSON object.

Each key in the object is the property name, and the corresponding value is the property value.

Returns
JSON object

◆ GetProperty()

wpi::json nt::Topic::GetProperty ( std::string_view  name) const

Gets the current value of a property (as a JSON object).

Parameters
nameproperty name
Returns
JSON object; null object if the property does not exist.

◆ GetType()

NetworkTableType nt::Topic::GetType ( ) const
inline

Gets the type of the topic.

Returns
the topic's type

◆ GetTypeString()

std::string nt::Topic::GetTypeString ( ) const
inline

Gets the type string of the topic.

This may have more information than the numeric type (especially for raw values).

Returns
the topic's type

◆ IsCached()

bool nt::Topic::IsCached ( ) const
inline

Returns whether the topic's last value is stored.

Returns
True if the topic is cached.

◆ IsPersistent()

bool nt::Topic::IsPersistent ( ) const
inline

Returns whether the value is persistent through server restarts.

Returns
True if the value is persistent.

◆ IsRetained()

bool nt::Topic::IsRetained ( ) const
inline

Returns whether the topic is retained by server when there are no publishers.

Returns
True if the topic is retained.

◆ operator bool()

nt::Topic::operator bool ( ) const
inlineexplicit

Determines if the native handle is valid.

Returns
True if the native handle is valid, false otherwise.

◆ operator==()

bool nt::Topic::operator== ( const Topic ) const
default

Equality operator.

Returns true if both instances refer to the same native handle.

◆ SetCached()

void nt::Topic::SetCached ( bool  cached)
inline

Allow storage of the topic's last value, allowing the value to be read (and not just accessed through event queues and listeners).

Parameters
cachedTrue for cached, false for not cached.

◆ SetPersistent()

void nt::Topic::SetPersistent ( bool  persistent)
inline

Make value persistent through server restarts.

Parameters
persistentTrue for persistent, false for not persistent.

◆ SetProperties()

bool nt::Topic::SetProperties ( const wpi::json &  properties)
inline

Updates multiple topic properties.

Each key in the passed-in object is the name of the property to add/update, and the corresponding value is the property value to set for that property. Null values result in deletion of the corresponding property.

Parameters
propertiesJSON object with keys to add/update/delete
Returns
False if properties is not an object

◆ SetProperty()

void nt::Topic::SetProperty ( std::string_view  name,
const wpi::json &  value 
)

Sets a property value.

Parameters
nameproperty name
valueproperty value

◆ SetRetained()

void nt::Topic::SetRetained ( bool  retained)
inline

Make the server retain the topic even when there are no publishers.

Parameters
retainedTrue for retained, false for not retained.

Member Data Documentation

◆ m_handle

NT_Topic nt::Topic::m_handle {0}
protected

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