WPILibC++ 2023.4.3-108-ge5452e3
nt::NetworkTableEntry Class Referencefinal

NetworkTables Entry. More...

#include <networktables/NetworkTableEntry.h>

Public Types

enum  Flags { kPersistent = NT_PERSISTENT }
 Flag values (as returned by GetFlags()). More...
 

Public Member Functions

 NetworkTableEntry ()
 Construct invalid instance. More...
 
 NetworkTableEntry (NT_Entry handle)
 Construct from native handle. More...
 
 operator bool () const
 Determines if the native handle is valid. More...
 
NT_Entry GetHandle () const
 Gets the native handle for the entry. More...
 
NetworkTableInstance GetInstance () const
 Gets the instance for the entry. More...
 
bool Exists () const
 Determines if the entry currently exists. More...
 
std::string GetName () const
 Gets the name of the entry (the key). More...
 
NetworkTableType GetType () const
 Gets the type of the entry. More...
 
unsigned int GetFlags () const
 Returns the flags. More...
 
int64_t GetLastChange () const
 Gets the last time the entry's value was changed. More...
 
Value GetValue () const
 Gets the entry's 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< NetworkTableValueReadQueue ()
 Get an array of all value changes since the last call to ReadQueue. More...
 
bool SetDefaultValue (const Value &defaultValue)
 Sets the entry's value if it does not exist. More...
 
bool SetDefaultBoolean (bool defaultValue)
 Sets the entry's value if it does not exist. More...
 
bool SetDefaultInteger (int64_t defaultValue)
 Sets the entry's value if it does not exist. More...
 
bool SetDefaultFloat (float defaultValue)
 Sets the entry's value if it does not exist. More...
 
bool SetDefaultDouble (double defaultValue)
 Sets the entry's value if it does not exist. More...
 
bool SetDefaultString (std::string_view defaultValue)
 Sets the entry's value if it does not exist. More...
 
bool SetDefaultRaw (std::span< const uint8_t > defaultValue)
 Sets the entry's value if it does not exist. More...
 
bool SetDefaultBooleanArray (std::span< const int > defaultValue)
 Sets the entry's value if it does not exist. More...
 
bool SetDefaultIntegerArray (std::span< const int64_t > defaultValue)
 Sets the entry's value if it does not exist. More...
 
bool SetDefaultFloatArray (std::span< const float > defaultValue)
 Sets the entry's value if it does not exist. More...
 
bool SetDefaultDoubleArray (std::span< const double > defaultValue)
 Sets the entry's value if it does not exist. More...
 
bool SetDefaultStringArray (std::span< const std::string > defaultValue)
 Sets the entry's value if it does not exist. More...
 
bool SetValue (const Value &value)
 Sets the entry's value. More...
 
bool SetBoolean (bool value, int64_t time=0)
 Sets the entry's value. More...
 
bool SetInteger (int64_t value, int64_t time=0)
 Sets the entry's value. More...
 
bool SetFloat (float value, int64_t time=0)
 Sets the entry's value. More...
 
bool SetDouble (double value, int64_t time=0)
 Sets the entry's value. More...
 
bool SetString (std::string_view value, int64_t time=0)
 Sets the entry's value. More...
 
bool SetRaw (std::span< const uint8_t > value, int64_t time=0)
 Sets the entry's value. More...
 
bool SetBooleanArray (std::span< const bool > value, int64_t time=0)
 Sets the entry's value. More...
 
bool SetBooleanArray (std::span< const int > value, int64_t time=0)
 Sets the entry's value. More...
 
bool SetIntegerArray (std::span< const int64_t > value, int64_t time=0)
 Sets the entry's value. More...
 
bool SetFloatArray (std::span< const float > value, int64_t time=0)
 Sets the entry's value. More...
 
bool SetDoubleArray (std::span< const double > value, int64_t time=0)
 Sets the entry's value. More...
 
bool SetStringArray (std::span< const std::string > value, int64_t time=0)
 Sets the entry's value. More...
 
void SetFlags (unsigned int flags)
 Sets flags. More...
 
void ClearFlags (unsigned int flags)
 Clears flags. More...
 
void SetPersistent ()
 Make value persistent through program restarts. More...
 
void ClearPersistent ()
 Stop making value persistent through program restarts. More...
 
bool IsPersistent () const
 Returns whether the value is persistent through program restarts. More...
 
void Unpublish ()
 Stops publishing the entry if it's been published. More...
 
void Delete ()
 Deletes the entry. More...
 
Topic GetTopic () const
 Gets the entry's topic. More...
 
bool operator== (const NetworkTableEntry &) const =default
 Equality operator. More...
 

Protected Attributes

NT_Entry m_handle {0}
 

Detailed Description

NetworkTables Entry.

Note
For backwards compatibility, the NetworkTableEntry destructor does not release the entry.

Member Enumeration Documentation

◆ Flags

Flag values (as returned by GetFlags()).

Deprecated:
Use IsPersistent() instead.
Enumerator
kPersistent 

Constructor & Destructor Documentation

◆ NetworkTableEntry() [1/2]

nt::NetworkTableEntry::NetworkTableEntry ( )
inline

Construct invalid instance.

◆ NetworkTableEntry() [2/2]

nt::NetworkTableEntry::NetworkTableEntry ( NT_Entry  handle)
inlineexplicit

Construct from native handle.

Parameters
handleNative handle

Member Function Documentation

◆ ClearFlags()

void nt::NetworkTableEntry::ClearFlags ( unsigned int  flags)
inline

Clears flags.

Parameters
flagsthe flags to clear (bitmask)
Deprecated:
Use SetPersistent() or topic properties instead

◆ ClearPersistent()

void nt::NetworkTableEntry::ClearPersistent ( )
inline

Stop making value persistent through program restarts.

◆ Delete()

void nt::NetworkTableEntry::Delete ( )
inline

Deletes the entry.

Deprecated:
Use Unpublish() instead.

◆ Exists()

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

Determines if the entry currently exists.

Returns
True if the entry exists, false otherwise.

◆ GetBoolean()

bool nt::NetworkTableEntry::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::NetworkTableEntry::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::NetworkTableEntry::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::NetworkTableEntry::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.

◆ GetFlags()

unsigned int nt::NetworkTableEntry::GetFlags ( ) const
inline

Returns the flags.

Returns
the flags (bitmask)
Deprecated:
Use IsPersistent() or topic properties instead

◆ GetFloat()

float nt::NetworkTableEntry::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::NetworkTableEntry::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.

◆ GetHandle()

NT_Entry nt::NetworkTableEntry::GetHandle ( ) const
inline

Gets the native handle for the entry.

Returns
Native handle

◆ GetInstance()

NetworkTableInstance nt::NetworkTableEntry::GetInstance ( ) const

Gets the instance for the entry.

Returns
Instance

◆ GetInteger()

int64_t nt::NetworkTableEntry::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::NetworkTableEntry::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.

◆ GetLastChange()

int64_t nt::NetworkTableEntry::GetLastChange ( ) const
inline

Gets the last time the entry's value was changed.

Returns
Entry last change time

◆ GetName()

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

Gets the name of the entry (the key).

Returns
the entry's name

◆ GetRaw()

std::vector< uint8_t > nt::NetworkTableEntry::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::NetworkTableEntry::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::NetworkTableEntry::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::NetworkTableEntry::GetTopic ( ) const

Gets the entry's topic.

Returns
Topic

◆ GetType()

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

Gets the type of the entry.

Returns
the entry's type

◆ GetValue()

Value nt::NetworkTableEntry::GetValue ( ) const
inline

Gets the entry's value.

If the entry does not exist, returns an empty value.

Returns
the entry's value or an empty value if it does not exist.

◆ IsPersistent()

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

Returns whether the value is persistent through program restarts.

Returns
True if the value is persistent.

◆ operator bool()

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

Determines if the native handle is valid.

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

◆ operator==()

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

Equality operator.

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

◆ ReadQueue()

std::vector< NetworkTableValue > nt::NetworkTableEntry::ReadQueue ( )
inline

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

The "poll storage" subscribe option can be used to set the queue depth.

Returns
Array of values; empty array if no new changes have been published since the previous call.

◆ SetBoolean()

bool nt::NetworkTableEntry::SetBoolean ( bool  value,
int64_t  time = 0 
)
inline

Sets the entry's value.

Parameters
valuethe value to set
timethe timestamp to set (0 = nt::Now())
Returns
False if the entry exists with a different type

◆ SetBooleanArray() [1/2]

bool nt::NetworkTableEntry::SetBooleanArray ( std::span< const bool >  value,
int64_t  time = 0 
)
inline

Sets the entry's value.

Parameters
valuethe value to set
timethe timestamp to set (0 = nt::Now())
Returns
False if the entry exists with a different type

◆ SetBooleanArray() [2/2]

bool nt::NetworkTableEntry::SetBooleanArray ( std::span< const int >  value,
int64_t  time = 0 
)
inline

Sets the entry's value.

Parameters
valuethe value to set
timethe timestamp to set (0 = nt::Now())
Returns
False if the entry exists with a different type

◆ SetDefaultBoolean()

bool nt::NetworkTableEntry::SetDefaultBoolean ( bool  defaultValue)
inline

Sets the entry's value if it does not exist.

Parameters
defaultValuethe default value to set
Returns
False if the entry exists with a different type

◆ SetDefaultBooleanArray()

bool nt::NetworkTableEntry::SetDefaultBooleanArray ( std::span< const int >  defaultValue)
inline

Sets the entry's value if it does not exist.

Parameters
defaultValuethe default value to set
Returns
False if the entry exists with a different type

◆ SetDefaultDouble()

bool nt::NetworkTableEntry::SetDefaultDouble ( double  defaultValue)
inline

Sets the entry's value if it does not exist.

Parameters
defaultValuethe default value to set
Returns
False if the entry exists with a different type

◆ SetDefaultDoubleArray()

bool nt::NetworkTableEntry::SetDefaultDoubleArray ( std::span< const double >  defaultValue)
inline

Sets the entry's value if it does not exist.

Parameters
defaultValuethe default value to set
Returns
False if the entry exists with a different type

◆ SetDefaultFloat()

bool nt::NetworkTableEntry::SetDefaultFloat ( float  defaultValue)
inline

Sets the entry's value if it does not exist.

Parameters
defaultValuethe default value to set
Returns
False if the entry exists with a different type

◆ SetDefaultFloatArray()

bool nt::NetworkTableEntry::SetDefaultFloatArray ( std::span< const float >  defaultValue)
inline

Sets the entry's value if it does not exist.

Parameters
defaultValuethe default value to set
Returns
False if the entry exists with a different type

◆ SetDefaultInteger()

bool nt::NetworkTableEntry::SetDefaultInteger ( int64_t  defaultValue)
inline

Sets the entry's value if it does not exist.

Parameters
defaultValuethe default value to set
Returns
False if the entry exists with a different type

◆ SetDefaultIntegerArray()

bool nt::NetworkTableEntry::SetDefaultIntegerArray ( std::span< const int64_t >  defaultValue)
inline

Sets the entry's value if it does not exist.

Parameters
defaultValuethe default value to set
Returns
False if the entry exists with a different type

◆ SetDefaultRaw()

bool nt::NetworkTableEntry::SetDefaultRaw ( std::span< const uint8_t >  defaultValue)
inline

Sets the entry's value if it does not exist.

Parameters
defaultValuethe default value to set
Returns
False if the entry exists with a different type

◆ SetDefaultString()

bool nt::NetworkTableEntry::SetDefaultString ( std::string_view  defaultValue)
inline

Sets the entry's value if it does not exist.

Parameters
defaultValuethe default value to set
Returns
False if the entry exists with a different type

◆ SetDefaultStringArray()

bool nt::NetworkTableEntry::SetDefaultStringArray ( std::span< const std::string >  defaultValue)
inline

Sets the entry's value if it does not exist.

Parameters
defaultValuethe default value to set
Returns
False if the entry exists with a different type

◆ SetDefaultValue()

bool nt::NetworkTableEntry::SetDefaultValue ( const Value defaultValue)
inline

Sets the entry's value if it does not exist.

Parameters
defaultValuethe default value to set
Returns
False if the entry exists with a different type

◆ SetDouble()

bool nt::NetworkTableEntry::SetDouble ( double  value,
int64_t  time = 0 
)
inline

Sets the entry's value.

Parameters
valuethe value to set
timethe timestamp to set (0 = nt::Now())
Returns
False if the entry exists with a different type

◆ SetDoubleArray()

bool nt::NetworkTableEntry::SetDoubleArray ( std::span< const double >  value,
int64_t  time = 0 
)
inline

Sets the entry's value.

Parameters
valuethe value to set
timethe timestamp to set (0 = nt::Now())
Returns
False if the entry exists with a different type

◆ SetFlags()

void nt::NetworkTableEntry::SetFlags ( unsigned int  flags)
inline

Sets flags.

Parameters
flagsthe flags to set (bitmask)
Deprecated:
Use SetPersistent() or topic properties instead

◆ SetFloat()

bool nt::NetworkTableEntry::SetFloat ( float  value,
int64_t  time = 0 
)
inline

Sets the entry's value.

Parameters
valuethe value to set
timethe timestamp to set (0 = nt::Now())
Returns
False if the entry exists with a different type

◆ SetFloatArray()

bool nt::NetworkTableEntry::SetFloatArray ( std::span< const float >  value,
int64_t  time = 0 
)
inline

Sets the entry's value.

Parameters
valuethe value to set
timethe timestamp to set (0 = nt::Now())
Returns
False if the entry exists with a different type

◆ SetInteger()

bool nt::NetworkTableEntry::SetInteger ( int64_t  value,
int64_t  time = 0 
)
inline

Sets the entry's value.

Parameters
valuethe value to set
timethe timestamp to set (0 = nt::Now())
Returns
False if the entry exists with a different type

◆ SetIntegerArray()

bool nt::NetworkTableEntry::SetIntegerArray ( std::span< const int64_t >  value,
int64_t  time = 0 
)
inline

Sets the entry's value.

Parameters
valuethe value to set
timethe timestamp to set (0 = nt::Now())
Returns
False if the entry exists with a different type

◆ SetPersistent()

void nt::NetworkTableEntry::SetPersistent ( )
inline

Make value persistent through program restarts.

◆ SetRaw()

bool nt::NetworkTableEntry::SetRaw ( std::span< const uint8_t >  value,
int64_t  time = 0 
)
inline

Sets the entry's value.

Parameters
valuethe value to set
timethe timestamp to set (0 = nt::Now())
Returns
False if the entry exists with a different type

◆ SetString()

bool nt::NetworkTableEntry::SetString ( std::string_view  value,
int64_t  time = 0 
)
inline

Sets the entry's value.

Parameters
valuethe value to set
timethe timestamp to set (0 = nt::Now())
Returns
False if the entry exists with a different type

◆ SetStringArray()

bool nt::NetworkTableEntry::SetStringArray ( std::span< const std::string >  value,
int64_t  time = 0 
)
inline

Sets the entry's value.

Parameters
valuethe value to set
timethe timestamp to set (0 = nt::Now())
Returns
False if the entry exists with a different type

◆ SetValue()

bool nt::NetworkTableEntry::SetValue ( const Value value)
inline

Sets the entry's value.

Parameters
valuethe value to set
Returns
False if the entry exists with a different type

◆ Unpublish()

void nt::NetworkTableEntry::Unpublish ( )
inline

Stops publishing the entry if it's been published.

Member Data Documentation

◆ m_handle

NT_Entry nt::NetworkTableEntry::m_handle {0}
protected

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