WPILibC++ 2024.3.2
|
A network table that knows its subtable path. More...
#include <networktables/NetworkTable.h>
Public Types | |
using | TableEventListener = std::function< void(NetworkTable *table, std::string_view key, const Event &event)> |
Called when an event occurs on a topic in a NetworkTable . More... | |
using | SubTableListener = std::function< void(NetworkTable *parent, std::string_view name, std::shared_ptr< NetworkTable > table)> |
Called when a new table is created within a NetworkTable. More... | |
Public Member Functions | |
NetworkTable (NT_Inst inst, std::string_view path, const private_init &) | |
Constructor. More... | |
~NetworkTable () | |
NetworkTableInstance | GetInstance () const |
Gets the instance for the table. More... | |
NetworkTableEntry | GetEntry (std::string_view key) const |
Gets the entry for a subkey. More... | |
Topic | GetTopic (std::string_view name) const |
Get (generic) topic. More... | |
BooleanTopic | GetBooleanTopic (std::string_view name) const |
Get boolean topic. More... | |
IntegerTopic | GetIntegerTopic (std::string_view name) const |
Get integer topic. More... | |
FloatTopic | GetFloatTopic (std::string_view name) const |
Get float topic. More... | |
DoubleTopic | GetDoubleTopic (std::string_view name) const |
Get double topic. More... | |
StringTopic | GetStringTopic (std::string_view name) const |
Get String topic. More... | |
RawTopic | GetRawTopic (std::string_view name) const |
Get raw topic. More... | |
BooleanArrayTopic | GetBooleanArrayTopic (std::string_view name) const |
Get boolean[] topic. More... | |
IntegerArrayTopic | GetIntegerArrayTopic (std::string_view name) const |
Get integer[] topic. More... | |
FloatArrayTopic | GetFloatArrayTopic (std::string_view name) const |
Get float[] topic. More... | |
DoubleArrayTopic | GetDoubleArrayTopic (std::string_view name) const |
Get double[] topic. More... | |
StringArrayTopic | GetStringArrayTopic (std::string_view name) const |
Get String[] topic. More... | |
template<wpi::ProtobufSerializable T> | |
ProtobufTopic< T > | GetProtobufTopic (std::string_view name) const |
Gets a protobuf serialized value topic. More... | |
template<typename T , typename... I> requires wpi::StructSerializable<T, I...> | |
StructTopic< T, I... > | GetStructTopic (std::string_view name, I... info) const |
Gets a raw struct serialized value topic. More... | |
template<typename T , typename... I> requires wpi::StructSerializable<T, I...> | |
StructArrayTopic< T, I... > | GetStructArrayTopic (std::string_view name, I... info) const |
Gets a raw struct serialized array topic. More... | |
std::shared_ptr< NetworkTable > | GetSubTable (std::string_view key) const |
Returns the table at the specified key. More... | |
bool | ContainsKey (std::string_view key) const |
Determines whether the given key is in this table. More... | |
bool | ContainsSubTable (std::string_view key) const |
Determines whether there exists a non-empty subtable for this key in this table. More... | |
std::vector< TopicInfo > | GetTopicInfo (int types=0) const |
Gets topic information for all keys in the table (not including sub-tables). More... | |
std::vector< Topic > | GetTopics (int types=0) const |
Gets all topics in the table (not including sub-tables). More... | |
std::vector< std::string > | GetKeys (int types=0) const |
Gets all keys in the table (not including sub-tables). More... | |
std::vector< std::string > | GetSubTables () const |
Gets the names of all subtables in the table. More... | |
void | SetPersistent (std::string_view key) |
Makes a key's value persistent through program restarts. More... | |
void | ClearPersistent (std::string_view key) |
Stop making a key's value persistent through program restarts. More... | |
bool | IsPersistent (std::string_view key) const |
Returns whether the value is persistent through program restarts. More... | |
bool | PutNumber (std::string_view key, double value) |
Put a number in the table. More... | |
bool | SetDefaultNumber (std::string_view key, double defaultValue) |
Gets the current value in the table, setting it if it does not exist. More... | |
double | GetNumber (std::string_view key, double defaultValue) const |
Gets the number associated with the given name. More... | |
bool | PutString (std::string_view key, std::string_view value) |
Put a string in the table. More... | |
bool | SetDefaultString (std::string_view key, std::string_view defaultValue) |
Gets the current value in the table, setting it if it does not exist. More... | |
std::string | GetString (std::string_view key, std::string_view defaultValue) const |
Gets the string associated with the given name. More... | |
bool | PutBoolean (std::string_view key, bool value) |
Put a boolean in the table. More... | |
bool | SetDefaultBoolean (std::string_view key, bool defaultValue) |
Gets the current value in the table, setting it if it does not exist. More... | |
bool | GetBoolean (std::string_view key, bool defaultValue) const |
Gets the boolean associated with the given name. More... | |
bool | PutBooleanArray (std::string_view key, std::span< const int > value) |
Put a boolean array in the table. More... | |
bool | SetDefaultBooleanArray (std::string_view key, std::span< const int > defaultValue) |
Gets the current value in the table, setting it if it does not exist. More... | |
std::vector< int > | GetBooleanArray (std::string_view key, std::span< const int > defaultValue) const |
Returns the boolean array the key maps to. More... | |
bool | PutNumberArray (std::string_view key, std::span< const double > value) |
Put a number array in the table. More... | |
bool | SetDefaultNumberArray (std::string_view key, std::span< const double > defaultValue) |
Gets the current value in the table, setting it if it does not exist. More... | |
std::vector< double > | GetNumberArray (std::string_view key, std::span< const double > defaultValue) const |
Returns the number array the key maps to. More... | |
bool | PutStringArray (std::string_view key, std::span< const std::string > value) |
Put a string array in the table. More... | |
bool | SetDefaultStringArray (std::string_view key, std::span< const std::string > defaultValue) |
Gets the current value in the table, setting it if it does not exist. More... | |
std::vector< std::string > | GetStringArray (std::string_view key, std::span< const std::string > defaultValue) const |
Returns the string array the key maps to. More... | |
bool | PutRaw (std::string_view key, std::span< const uint8_t > value) |
Put a raw value (byte array) in the table. More... | |
bool | SetDefaultRaw (std::string_view key, std::span< const uint8_t > defaultValue) |
Gets the current value in the table, setting it if it does not exist. More... | |
std::vector< uint8_t > | GetRaw (std::string_view key, std::span< const uint8_t > defaultValue) const |
Returns the raw value (byte array) the key maps to. More... | |
bool | PutValue (std::string_view key, const Value &value) |
Put a value in the table. More... | |
bool | SetDefaultValue (std::string_view key, const Value &defaultValue) |
Gets the current value in the table, setting it if it does not exist. More... | |
Value | GetValue (std::string_view key) const |
Gets the value associated with a key as an object. More... | |
std::string_view | GetPath () const |
Gets the full path of this table. More... | |
NT_Listener | AddListener (int eventMask, TableEventListener listener) |
Listen to topics only within this table. More... | |
NT_Listener | AddListener (std::string_view key, int eventMask, TableEventListener listener) |
Listen to a single key. More... | |
NT_Listener | AddSubTableListener (SubTableListener listener) |
Listen for sub-table creation. More... | |
void | RemoveListener (NT_Listener listener) |
Remove a listener. More... | |
Static Public Member Functions | |
static std::string_view | BasenameKey (std::string_view key) |
Gets the "base name" of a key. More... | |
static std::string | NormalizeKey (std::string_view key, bool withLeadingSlash=true) |
Normalizes an network table key to contain no consecutive slashes and optionally start with a leading slash. More... | |
static std::string_view | NormalizeKey (std::string_view key, wpi::SmallVectorImpl< char > &buf, bool withLeadingSlash=true) |
static std::vector< std::string > | GetHierarchy (std::string_view key) |
Gets a list of the names of all the super tables of a given key. More... | |
Static Public Attributes | |
static constexpr char | PATH_SEPARATOR_CHAR = '/' |
The path separator for sub-tables and keys. More... | |
Friends | |
class | NetworkTableInstance |
A network table that knows its subtable path.
using nt::NetworkTable::SubTableListener = std::function<void(NetworkTable* parent, std::string_view name, std::shared_ptr<NetworkTable> table)> |
Called when a new table is created within a NetworkTable.
parent | the parent of the table |
name | the name of the new table |
table | the new table |
using nt::NetworkTable::TableEventListener = std::function<void( NetworkTable* table, std::string_view key, const Event& event)> |
Called when an event occurs on a topic in a NetworkTable
.
table | the table the topic exists in |
key | the key associated with the topic that changed |
event | the event |
nt::NetworkTable::NetworkTable | ( | NT_Inst | inst, |
std::string_view | path, | ||
const private_init & | |||
) |
Constructor.
Use NetworkTableInstance::GetTable() or GetSubTable() instead.
nt::NetworkTable::~NetworkTable | ( | ) |
NT_Listener nt::NetworkTable::AddListener | ( | int | eventMask, |
TableEventListener | listener | ||
) |
Listen to topics only within this table.
eventMask | Bitmask of EventFlags values |
listener | listener to add |
NT_Listener nt::NetworkTable::AddListener | ( | std::string_view | key, |
int | eventMask, | ||
TableEventListener | listener | ||
) |
Listen to a single key.
key | the key name |
eventMask | Bitmask of EventFlags values |
listener | listener to add |
NT_Listener nt::NetworkTable::AddSubTableListener | ( | SubTableListener | listener | ) |
Listen for sub-table creation.
This calls the listener once for each newly created sub-table. It immediately calls the listener for any existing sub-tables.
listener | listener to add |
|
static |
Gets the "base name" of a key.
For example, "/foo/bar" becomes "bar". If the key has a trailing slash, returns an empty string.
key | key |
void nt::NetworkTable::ClearPersistent | ( | std::string_view | key | ) |
Stop making a key's value persistent through program restarts.
The key cannot be null.
key | the key name |
bool nt::NetworkTable::ContainsKey | ( | std::string_view | key | ) | const |
Determines whether the given key is in this table.
key | the key to search for |
bool nt::NetworkTable::ContainsSubTable | ( | std::string_view | key | ) | const |
Determines whether there exists a non-empty subtable for this key in this table.
key | the key to search for |
bool nt::NetworkTable::GetBoolean | ( | std::string_view | key, |
bool | defaultValue | ||
) | const |
Gets the boolean associated with the given name.
If the key does not exist or is of different type, it will return the default value.
key | the key to look up |
defaultValue | the value to be returned if no value is found |
std::vector< int > nt::NetworkTable::GetBooleanArray | ( | std::string_view | key, |
std::span< const int > | defaultValue | ||
) | const |
Returns the boolean array the key maps to.
If the key does not exist or is of different type, it will return the default value.
key | the key to look up |
defaultValue | the value to be returned if no value is found |
BooleanArrayTopic nt::NetworkTable::GetBooleanArrayTopic | ( | std::string_view | name | ) | const |
BooleanTopic nt::NetworkTable::GetBooleanTopic | ( | std::string_view | name | ) | const |
DoubleArrayTopic nt::NetworkTable::GetDoubleArrayTopic | ( | std::string_view | name | ) | const |
DoubleTopic nt::NetworkTable::GetDoubleTopic | ( | std::string_view | name | ) | const |
NetworkTableEntry nt::NetworkTable::GetEntry | ( | std::string_view | key | ) | const |
Gets the entry for a subkey.
key | the key name |
FloatArrayTopic nt::NetworkTable::GetFloatArrayTopic | ( | std::string_view | name | ) | const |
FloatTopic nt::NetworkTable::GetFloatTopic | ( | std::string_view | name | ) | const |
|
static |
Gets a list of the names of all the super tables of a given key.
For example, the key "/foo/bar/baz" has a hierarchy of "/", "/foo", "/foo/bar", and "/foo/bar/baz".
key | the key |
NetworkTableInstance nt::NetworkTable::GetInstance | ( | ) | const |
Gets the instance for the table.
IntegerArrayTopic nt::NetworkTable::GetIntegerArrayTopic | ( | std::string_view | name | ) | const |
IntegerTopic nt::NetworkTable::GetIntegerTopic | ( | std::string_view | name | ) | const |
std::vector< std::string > nt::NetworkTable::GetKeys | ( | int | types = 0 | ) | const |
Gets all keys in the table (not including sub-tables).
types | bitmask of types; 0 is treated as a "don't care". |
double nt::NetworkTable::GetNumber | ( | std::string_view | key, |
double | defaultValue | ||
) | const |
Gets the number associated with the given name.
key | the key to look up |
defaultValue | the value to be returned if no value is found |
std::vector< double > nt::NetworkTable::GetNumberArray | ( | std::string_view | key, |
std::span< const double > | defaultValue | ||
) | const |
Returns the number array the key maps to.
If the key does not exist or is of different type, it will return the default value.
key | the key to look up |
defaultValue | the value to be returned if no value is found |
std::string_view nt::NetworkTable::GetPath | ( | ) | const |
Gets the full path of this table.
Does not include the trailing "/".
|
inline |
std::vector< uint8_t > nt::NetworkTable::GetRaw | ( | std::string_view | key, |
std::span< const uint8_t > | defaultValue | ||
) | const |
Returns the raw value (byte array) the key maps to.
If the key does not exist or is of different type, it will return the default value.
key | the key to look up |
defaultValue | the value to be returned if no value is found |
RawTopic nt::NetworkTable::GetRawTopic | ( | std::string_view | name | ) | const |
std::string nt::NetworkTable::GetString | ( | std::string_view | key, |
std::string_view | defaultValue | ||
) | const |
Gets the string associated with the given name.
If the key does not exist or is of different type, it will return the default value.
key | the key to look up |
defaultValue | the value to be returned if no value is found |
std::vector< std::string > nt::NetworkTable::GetStringArray | ( | std::string_view | key, |
std::span< const std::string > | defaultValue | ||
) | const |
Returns the string array the key maps to.
If the key does not exist or is of different type, it will return the default value.
key | the key to look up |
defaultValue | the value to be returned if no value is found |
StringArrayTopic nt::NetworkTable::GetStringArrayTopic | ( | std::string_view | name | ) | const |
StringTopic nt::NetworkTable::GetStringTopic | ( | std::string_view | name | ) | const |
|
inline |
Gets a raw struct serialized array topic.
name | topic name |
info | optional struct type info |
|
inline |
Gets a raw struct serialized value topic.
name | topic name |
info | optional struct type info |
std::shared_ptr< NetworkTable > nt::NetworkTable::GetSubTable | ( | std::string_view | key | ) | const |
Returns the table at the specified key.
If there is no table at the specified key, it will create a new table
key | the key name |
std::vector< std::string > nt::NetworkTable::GetSubTables | ( | ) | const |
Gets the names of all subtables in the table.
Topic nt::NetworkTable::GetTopic | ( | std::string_view | name | ) | const |
std::vector< TopicInfo > nt::NetworkTable::GetTopicInfo | ( | int | types = 0 | ) | const |
Gets topic information for all keys in the table (not including sub-tables).
types | bitmask of types; 0 is treated as a "don't care". |
std::vector< Topic > nt::NetworkTable::GetTopics | ( | int | types = 0 | ) | const |
Gets all topics in the table (not including sub-tables).
types | bitmask of types; 0 is treated as a "don't care". |
Value nt::NetworkTable::GetValue | ( | std::string_view | key | ) | const |
Gets the value associated with a key as an object.
key | the key of the value to look up |
bool nt::NetworkTable::IsPersistent | ( | std::string_view | key | ) | const |
Returns whether the value is persistent through program restarts.
The key cannot be null.
key | the key name |
|
static |
Normalizes an network table key to contain no consecutive slashes and optionally start with a leading slash.
For example:
normalizeKey("/foo/bar", true) == "/foo/bar"
normalizeKey("foo/bar", true) == "/foo/bar"
normalizeKey("/foo/bar", false) == "foo/bar"
normalizeKey("foo//bar", false) == "foo/bar"
key | the key to normalize |
withLeadingSlash | whether or not the normalized key should begin with a leading slash |
|
static |
bool nt::NetworkTable::PutBoolean | ( | std::string_view | key, |
bool | value | ||
) |
Put a boolean in the table.
key | the key to be assigned to |
value | the value that will be assigned |
bool nt::NetworkTable::PutBooleanArray | ( | std::string_view | key, |
std::span< const int > | value | ||
) |
Put a boolean array in the table.
key | the key to be assigned to |
value | the value that will be assigned |
bool nt::NetworkTable::PutNumber | ( | std::string_view | key, |
double | value | ||
) |
Put a number in the table.
key | the key to be assigned to |
value | the value that will be assigned |
bool nt::NetworkTable::PutNumberArray | ( | std::string_view | key, |
std::span< const double > | value | ||
) |
Put a number array in the table.
key | the key to be assigned to |
value | the value that will be assigned |
bool nt::NetworkTable::PutRaw | ( | std::string_view | key, |
std::span< const uint8_t > | value | ||
) |
Put a raw value (byte array) in the table.
key | the key to be assigned to |
value | the value that will be assigned |
bool nt::NetworkTable::PutString | ( | std::string_view | key, |
std::string_view | value | ||
) |
Put a string in the table.
key | the key to be assigned to |
value | the value that will be assigned |
bool nt::NetworkTable::PutStringArray | ( | std::string_view | key, |
std::span< const std::string > | value | ||
) |
Put a string array in the table.
key | the key to be assigned to |
value | the value that will be assigned |
bool nt::NetworkTable::PutValue | ( | std::string_view | key, |
const Value & | value | ||
) |
Put a value in the table.
key | the key to be assigned to |
value | the value that will be assigned |
void nt::NetworkTable::RemoveListener | ( | NT_Listener | listener | ) |
Remove a listener.
listener | listener handle |
bool nt::NetworkTable::SetDefaultBoolean | ( | std::string_view | key, |
bool | defaultValue | ||
) |
Gets the current value in the table, setting it if it does not exist.
key | the key |
defaultValue | the default value to set if key doesn't exist. |
bool nt::NetworkTable::SetDefaultBooleanArray | ( | std::string_view | key, |
std::span< const int > | defaultValue | ||
) |
Gets the current value in the table, setting it if it does not exist.
key | the key |
defaultValue | the default value to set if key doesn't exist. |
bool nt::NetworkTable::SetDefaultNumber | ( | std::string_view | key, |
double | defaultValue | ||
) |
Gets the current value in the table, setting it if it does not exist.
key | the key |
defaultValue | the default value to set if key doesn't exist. |
bool nt::NetworkTable::SetDefaultNumberArray | ( | std::string_view | key, |
std::span< const double > | defaultValue | ||
) |
Gets the current value in the table, setting it if it does not exist.
key | the key |
defaultValue | the default value to set if key doesn't exist. |
bool nt::NetworkTable::SetDefaultRaw | ( | std::string_view | key, |
std::span< const uint8_t > | defaultValue | ||
) |
Gets the current value in the table, setting it if it does not exist.
key | the key |
defaultValue | the default value to set if key doesn't exist. |
bool nt::NetworkTable::SetDefaultString | ( | std::string_view | key, |
std::string_view | defaultValue | ||
) |
Gets the current value in the table, setting it if it does not exist.
key | the key |
defaultValue | the default value to set if key doesn't exist. |
bool nt::NetworkTable::SetDefaultStringArray | ( | std::string_view | key, |
std::span< const std::string > | defaultValue | ||
) |
Gets the current value in the table, setting it if it does not exist.
key | the key |
defaultValue | the default value to set if key doesn't exist. |
bool nt::NetworkTable::SetDefaultValue | ( | std::string_view | key, |
const Value & | defaultValue | ||
) |
Gets the current value in the table, setting it if it does not exist.
key | the key |
defaultValue | the default value to set if key doesn't exist. |
void nt::NetworkTable::SetPersistent | ( | std::string_view | key | ) |
Makes a key's value persistent through program restarts.
key | the key to make persistent |
|
friend |
|
staticconstexpr |
The path separator for sub-tables and keys.