WPILibC++  2019.3.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
nt::NetworkTable Class Referencefinal

A network table that knows its subtable path. More...

#include <NetworkTable.h>

Inheritance diagram for nt::NetworkTable:

Public Member Functions

 NetworkTable (NT_Inst inst, const Twine &path, const private_init &)
 Constructor. More...
 
NetworkTableInstance GetInstance () const
 Gets the instance for the table. More...
 
 WPI_DEPRECATED ("use NetworkTableInstance::StartServer() or ""NetworkTableInstance::StartClient() instead") static void Initialize()
 Initializes network tables.
 
 WPI_DEPRECATED ("use NetworkTableInstance::StopServer() or ""NetworkTableInstance::StopClient() instead") static void Shutdown()
 Shuts down network tables.
 
 WPI_DEPRECATED ("use NetworkTableInstance::SetServerTeam() or ""NetworkTableInstance::StartClientTeam() instead") static void SetTeam(int team)
 set the team the robot is configured for (this will set the mdns address that network tables will connect to in client mode) This must be called before initialize or GetTable More...
 
 WPI_DEPRECATED ("use NetworkTableInstance::SetServer() or ""NetworkTableInstance::StartClient() instead") static void SetIPAddress(StringRef address)
 
 WPI_DEPRECATED ("use NetworkTableInstance::StartDSClient() and ""NetworkTableInstance::StopDSClient() instead") static void SetDSClientEnabled(bool enabled)
 Enable requesting the server address from the Driver Station. More...
 
 WPI_DEPRECATED ("use the appropriate parameter to NetworkTableInstance::StartServer() ""instead") static void SetPersistentFilename(StringRef filename)
 Sets the persistent filename. More...
 
NT_EntryListener AddEntryListener (TableEntryListener listener, unsigned int flags) const
 Listen to keys only within this table. More...
 
NT_EntryListener AddEntryListener (const Twine &key, TableEntryListener listener, unsigned int flags) const
 Listen to a single key. More...
 
void RemoveEntryListener (NT_EntryListener listener) const
 Remove an entry listener. More...
 
NT_EntryListener AddSubTableListener (TableListener listener, bool localNotify=false)
 Listen for sub-table creation. More...
 
void RemoveTableListener (NT_EntryListener listener)
 Remove a sub-table listener. More...
 
 WPI_DEPRECATED ("use AddEntryListener() instead with flags value of NT_NOTIFY_NEW | ""NT_NOTIFY_UPDATE") void AddTableListener(ITableListener *listener) override
 
 WPI_DEPRECATED ("use AddEntryListener() instead with flags value of NT_NOTIFY_NEW | ""NT_NOTIFY_UPDATE | NT_NOTIFY_IMMEDIATE") void AddTableListener(ITableListener *listener
 
void AddTableListenerEx (ITableListener *listener, unsigned int flags) override
 
void AddTableListener (StringRef key, ITableListener *listener, bool immediateNotify) override
 
void AddTableListenerEx (StringRef key, ITableListener *listener, unsigned int flags) override
 
void AddSubTableListener (ITableListener *listener) override
 
void AddSubTableListener (ITableListener *listener, bool localNotify) override
 
void RemoveTableListener (ITableListener *listener) override
 
std::shared_ptr< NetworkTableGetSubTable (const Twine &key) const override
 Returns the table at the specified key. More...
 
bool ContainsKey (const Twine &key) const override
 Determines whether the given key is in this table. More...
 
bool ContainsSubTable (const Twine &key) const override
 Determines whether there exists a non-empty subtable for this key in this table. More...
 
std::vector< std::string > GetKeys (int types=0) const override
 Gets all keys in the table (not including sub-tables). More...
 
std::vector< std::string > GetSubTables () const override
 Gets the names of all subtables in the table. More...
 
void SetPersistent (StringRef key) override
 Makes a key's value persistent through program restarts. More...
 
void ClearPersistent (StringRef key) override
 Stop making a key's value persistent through program restarts. More...
 
bool IsPersistent (StringRef key) const override
 Returns whether the value is persistent through program restarts. More...
 
void SetFlags (StringRef key, unsigned int flags) override
 Sets flags on the specified key in this table. More...
 
void ClearFlags (StringRef key, unsigned int flags) override
 Clears flags on the specified key in this table. More...
 
unsigned int GetFlags (StringRef key) const override
 Returns the flags for the specified key. More...
 
void Delete (const Twine &key) override
 Deletes the specified key in this table. More...
 
bool PutNumber (StringRef key, double value) override
 Put a number in the table. More...
 
bool SetDefaultNumber (StringRef key, double defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
double GetNumber (StringRef key, double defaultValue) const override
 Gets the number associated with the given name. More...
 
bool PutString (StringRef key, StringRef value) override
 Put a string in the table. More...
 
bool SetDefaultString (StringRef key, StringRef defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
std::string GetString (StringRef key, StringRef defaultValue) const override
 Gets the string associated with the given name. More...
 
bool PutBoolean (StringRef key, bool value) override
 Put a boolean in the table. More...
 
bool SetDefaultBoolean (StringRef key, bool defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
bool GetBoolean (StringRef key, bool defaultValue) const override
 Gets the boolean associated with the given name. More...
 
bool PutBooleanArray (StringRef key, ArrayRef< int > value) override
 Put a boolean array in the table. More...
 
bool SetDefaultBooleanArray (StringRef key, ArrayRef< int > defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
std::vector< int > GetBooleanArray (StringRef key, ArrayRef< int > defaultValue) const override
 Returns the boolean array the key maps to. More...
 
bool PutNumberArray (StringRef key, ArrayRef< double > value) override
 Put a number array in the table. More...
 
bool SetDefaultNumberArray (StringRef key, ArrayRef< double > defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
std::vector< double > GetNumberArray (StringRef key, ArrayRef< double > defaultValue) const override
 Returns the number array the key maps to. More...
 
bool PutStringArray (StringRef key, ArrayRef< std::string > value) override
 Put a string array in the table. More...
 
bool SetDefaultStringArray (StringRef key, ArrayRef< std::string > defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
std::vector< std::string > GetStringArray (StringRef key, ArrayRef< std::string > defaultValue) const override
 Returns the string array the key maps to. More...
 
bool PutRaw (StringRef key, StringRef value) override
 Put a raw value (byte array) in the table. More...
 
bool SetDefaultRaw (StringRef key, StringRef defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
std::string GetRaw (StringRef key, StringRef defaultValue) const override
 Returns the raw value (byte array) the key maps to. More...
 
bool PutValue (const Twine &key, std::shared_ptr< Value > value) override
 Put a value in the table. More...
 
bool SetDefaultValue (const Twine &key, std::shared_ptr< Value > defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
std::shared_ptr< ValueGetValue (const Twine &key) const override
 Gets the value associated with a key as an object. More...
 
StringRef GetPath () const override
 Gets the full path of this table. More...
 
const char * SaveEntries (const Twine &filename) const
 Save table values to a file. More...
 
const char * LoadEntries (const Twine &filename, std::function< void(size_t line, const char *msg)> warn)
 Load table values from a file. More...
 

Static Public Member Functions

static StringRef BasenameKey (StringRef key)
 Gets the "base name" of a key. More...
 
static std::string NormalizeKey (const Twine &key, bool withLeadingSlash=true)
 Normalizes an network table key to contain no consecutive slashes and optionally start with a leading slash. More...
 
static StringRef NormalizeKey (const Twine &key, wpi::SmallVectorImpl< char > &buf, bool withLeadingSlash=true)
 
static std::vector< std::string > GetHierarchy (const Twine &key)
 Gets a list of the names of all the super tables of a given key. More...
 
static void SetClientMode ()
 set that network tables should be a client This must be called before initialize or GetTable
 
static void SetServerMode ()
 set that network tables should be a server This must be called before initialize or GetTable
 
static void SetNetworkIdentity (StringRef name)
 Sets the network identity. More...
 
static void GlobalDeleteAll ()
 Deletes ALL keys in ALL subtables. More...
 
static void Flush ()
 Flushes all updated values immediately to the network. More...
 
static void SetUpdateRate (double interval)
 Set the periodic update rate. More...
 
static const char * SavePersistent (StringRef filename)
 Saves persistent keys to a file. More...
 
static const char * LoadPersistent (StringRef filename, std::function< void(size_t line, const char *msg)> warn)
 Loads persistent keys from a file. More...
 

Public Attributes

bool immediateNotify override
 

Static Public Attributes

static const char PATH_SEPARATOR_CHAR
 The path separator for sub-tables and keys.
 

Friends

class NetworkTableInstance
 

Detailed Description

A network table that knows its subtable path.

Constructor & Destructor Documentation

nt::NetworkTable::NetworkTable ( NT_Inst  inst,
const Twine path,
const private_init &   
)

Constructor.

Use NetworkTableInstance::GetTable() or GetSubTable() instead.

Member Function Documentation

NT_EntryListener nt::NetworkTable::AddEntryListener ( TableEntryListener  listener,
unsigned int  flags 
) const

Listen to keys only within this table.

Parameters
listenerlistener to add
flagsEntryListenerFlags bitmask
Returns
Listener handle
NT_EntryListener nt::NetworkTable::AddEntryListener ( const Twine key,
TableEntryListener  listener,
unsigned int  flags 
) const

Listen to a single key.

Parameters
keythe key name
listenerlistener to add
flagsEntryListenerFlags bitmask
Returns
Listener handle
NT_EntryListener nt::NetworkTable::AddSubTableListener ( TableListener  listener,
bool  localNotify = false 
)

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.

Parameters
listenerlistener to add
localNotifynotify local changes as well as remote
Returns
Listener handle
static StringRef nt::NetworkTable::BasenameKey ( StringRef  key)
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.

Parameters
keykey
Returns
base name
void nt::NetworkTable::ClearFlags ( StringRef  key,
unsigned int  flags 
)
override

Clears flags on the specified key in this table.

The key can not be null.

Parameters
keythe key name
flagsthe flags to clear (bitmask)
void nt::NetworkTable::ClearPersistent ( StringRef  key)
override

Stop making a key's value persistent through program restarts.

The key cannot be null.

Parameters
keythe key name
bool nt::NetworkTable::ContainsKey ( const Twine key) const
override

Determines whether the given key is in this table.

Parameters
keythe key to search for
Returns
true if the table as a value assigned to the given key
bool nt::NetworkTable::ContainsSubTable ( const Twine key) const
override

Determines whether there exists a non-empty subtable for this key in this table.

Parameters
keythe key to search for
Returns
true if there is a subtable with the key which contains at least one key/subtable of its own
void nt::NetworkTable::Delete ( const Twine key)
override

Deletes the specified key in this table.

Parameters
keythe key name
static void nt::NetworkTable::Flush ( )
static

Flushes all updated values immediately to the network.

Note: This is rate-limited to protect the network from flooding. This is primarily useful for synchronizing network updates with user code.

bool nt::NetworkTable::GetBoolean ( StringRef  key,
bool  defaultValue 
) const
override

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.

Parameters
keythe key to look up
defaultValuethe value to be returned if no value is found
Returns
the value associated with the given key or the given default value if there is no value associated with the key
std::vector<int> nt::NetworkTable::GetBooleanArray ( StringRef  key,
ArrayRef< int >  defaultValue 
) const
override

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.

Parameters
keythe key to look up
defaultValuethe value to be returned if no value is found
Returns
the value associated with the given key or the given default value if there is no value associated with the key
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.
unsigned int nt::NetworkTable::GetFlags ( StringRef  key) const
override

Returns the flags for the specified key.

Parameters
keythe key name
Returns
the flags, or 0 if the key is not defined
static std::vector<std::string> nt::NetworkTable::GetHierarchy ( const Twine key)
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".

Parameters
keythe key
Returns
List of super tables
NetworkTableInstance nt::NetworkTable::GetInstance ( ) const

Gets the instance for the table.

Returns
Instance
std::vector<std::string> nt::NetworkTable::GetKeys ( int  types = 0) const
override

Gets all keys in the table (not including sub-tables).

Parameters
typesbitmask of types; 0 is treated as a "don't care".
Returns
keys currently in the table
double nt::NetworkTable::GetNumber ( StringRef  key,
double  defaultValue 
) const
override

Gets the number associated with the given name.

Parameters
keythe key to look up
defaultValuethe value to be returned if no value is found
Returns
the value associated with the given key or the given default value if there is no value associated with the key
std::vector<double> nt::NetworkTable::GetNumberArray ( StringRef  key,
ArrayRef< double >  defaultValue 
) const
override

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.

Parameters
keythe key to look up
defaultValuethe value to be returned if no value is found
Returns
the value associated with the given key or the given default value if there is no value associated with the key
Note
This makes a copy of the array. If the overhead of this is a concern, use GetValue() instead.
StringRef nt::NetworkTable::GetPath ( ) const
override

Gets the full path of this table.

Does not include the trailing "/".

Returns
The path (e.g "", "/foo").
std::string nt::NetworkTable::GetRaw ( StringRef  key,
StringRef  defaultValue 
) const
override

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.

Parameters
keythe key to look up
defaultValuethe value to be returned if no value is found
Returns
the value associated with the given key or the given default value if there is no value associated with the key
Note
This makes a copy of the raw contents. If the overhead of this is a concern, use GetValue() instead.
std::string nt::NetworkTable::GetString ( StringRef  key,
StringRef  defaultValue 
) const
override

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.

Parameters
keythe key to look up
defaultValuethe value to be returned if no value is found
Returns
the value associated with the given key or the given default value if there is no value associated with the key
std::vector<std::string> nt::NetworkTable::GetStringArray ( StringRef  key,
ArrayRef< std::string >  defaultValue 
) const
override

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.

Parameters
keythe key to look up
defaultValuethe value to be returned if no value is found
Returns
the value associated with the given key or the given default value if there is no value associated with the key
Note
This makes a copy of the array. If the overhead of this is a concern, use GetValue() instead.
std::shared_ptr<NetworkTable> nt::NetworkTable::GetSubTable ( const Twine key) const
override

Returns the table at the specified key.

If there is no table at the specified key, it will create a new table

Parameters
keythe key name
Returns
the networktable to be returned
std::vector<std::string> nt::NetworkTable::GetSubTables ( ) const
override

Gets the names of all subtables in the table.

Returns
subtables currently in the table
std::shared_ptr<Value> nt::NetworkTable::GetValue ( const Twine key) const
override

Gets the value associated with a key as an object.

Parameters
keythe key of the value to look up
Returns
the value associated with the given key, or nullptr if the key does not exist
static void nt::NetworkTable::GlobalDeleteAll ( )
static

Deletes ALL keys in ALL subtables.

Use with caution!

bool nt::NetworkTable::IsPersistent ( StringRef  key) const
override

Returns whether the value is persistent through program restarts.

The key cannot be null.

Parameters
keythe key name
const char* nt::NetworkTable::LoadEntries ( const Twine filename,
std::function< void(size_t line, const char *msg)>  warn 
)

Load table values from a file.

The file format used is identical to that used for SavePersistent / LoadPersistent.

Parameters
filenamefilename
warncallback function for warnings
Returns
error string, or nullptr if successful
static const char* nt::NetworkTable::LoadPersistent ( StringRef  filename,
std::function< void(size_t line, const char *msg)>  warn 
)
static

Loads persistent keys from a file.

The server does this automatically.

Parameters
filenamefile name
warncallback function called for warnings
Returns
Error (or nullptr).
static std::string nt::NetworkTable::NormalizeKey ( const Twine key,
bool  withLeadingSlash = true 
)
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"
Parameters
keythe key to normalize
withLeadingSlashwhether or not the normalized key should begin with a leading slash
Returns
normalized key
bool nt::NetworkTable::PutBoolean ( StringRef  key,
bool  value 
)
override

Put a boolean in the table.

Parameters
keythe key to be assigned to
valuethe value that will be assigned
Returns
False if the table key already exists with a different type
bool nt::NetworkTable::PutBooleanArray ( StringRef  key,
ArrayRef< int >  value 
)
override

Put a boolean array in the table.

Parameters
keythe key to be assigned to
valuethe value that will be assigned
Returns
False if the table key already exists with a different type
Note
The array must be of int's rather than of bool's because std::vector<bool> is special-cased in C++. 0 is false, any non-zero value is true.
bool nt::NetworkTable::PutNumber ( StringRef  key,
double  value 
)
override

Put a number in the table.

Parameters
keythe key to be assigned to
valuethe value that will be assigned
Returns
False if the table key already exists with a different type
bool nt::NetworkTable::PutNumberArray ( StringRef  key,
ArrayRef< double >  value 
)
override

Put a number array in the table.

Parameters
keythe key to be assigned to
valuethe value that will be assigned
Returns
False if the table key already exists with a different type
bool nt::NetworkTable::PutRaw ( StringRef  key,
StringRef  value 
)
override

Put a raw value (byte array) in the table.

Parameters
keythe key to be assigned to
valuethe value that will be assigned
Returns
False if the table key already exists with a different type
bool nt::NetworkTable::PutString ( StringRef  key,
StringRef  value 
)
override

Put a string in the table.

Parameters
keythe key to be assigned to
valuethe value that will be assigned
Returns
False if the table key already exists with a different type
bool nt::NetworkTable::PutStringArray ( StringRef  key,
ArrayRef< std::string >  value 
)
override

Put a string array in the table.

Parameters
keythe key to be assigned to
valuethe value that will be assigned
Returns
False if the table key already exists with a different type
bool nt::NetworkTable::PutValue ( const Twine key,
std::shared_ptr< Value value 
)
override

Put a value in the table.

Parameters
keythe key to be assigned to
valuethe value that will be assigned
Returns
False if the table key already exists with a different type
void nt::NetworkTable::RemoveEntryListener ( NT_EntryListener  listener) const

Remove an entry listener.

Parameters
listenerlistener handle
void nt::NetworkTable::RemoveTableListener ( NT_EntryListener  listener)

Remove a sub-table listener.

Parameters
listenerlistener handle
const char* nt::NetworkTable::SaveEntries ( const Twine filename) const

Save table values to a file.

The file format used is identical to that used for SavePersistent.

Parameters
filenamefilename
Returns
error string, or nullptr if successful
static const char* nt::NetworkTable::SavePersistent ( StringRef  filename)
static

Saves persistent keys to a file.

The server does this automatically.

Parameters
filenamefile name
Returns
Error (or nullptr).
bool nt::NetworkTable::SetDefaultBoolean ( StringRef  key,
bool  defaultValue 
)
override

Gets the current value in the table, setting it if it does not exist.

Parameters
keythe key
defaultValuethe default value to set if key doesn't exist.
Returns
False if the table key exists with a different type
bool nt::NetworkTable::SetDefaultBooleanArray ( StringRef  key,
ArrayRef< int >  defaultValue 
)
override

Gets the current value in the table, setting it if it does not exist.

Parameters
keythe key
defaultValuethe default value to set if key doesn't exist.
Returns
False if the table key exists with a different type
bool nt::NetworkTable::SetDefaultNumber ( StringRef  key,
double  defaultValue 
)
override

Gets the current value in the table, setting it if it does not exist.

Parameters
keythe key
defaultValuethe default value to set if key doesn't exist.
Returns
False if the table key exists with a different type
bool nt::NetworkTable::SetDefaultNumberArray ( StringRef  key,
ArrayRef< double >  defaultValue 
)
override

Gets the current value in the table, setting it if it does not exist.

Parameters
keythe key
defaultValuethe default value to set if key doesn't exist.
Returns
False if the table key exists with a different type
bool nt::NetworkTable::SetDefaultRaw ( StringRef  key,
StringRef  defaultValue 
)
override

Gets the current value in the table, setting it if it does not exist.

Parameters
keythe key
defaultValuethe default value to set if key doesn't exist.
Returns
False if the table key exists with a different type
bool nt::NetworkTable::SetDefaultString ( StringRef  key,
StringRef  defaultValue 
)
override

Gets the current value in the table, setting it if it does not exist.

Parameters
keythe key
defaultValuethe default value to set if key doesn't exist.
Returns
False if the table key exists with a different type
bool nt::NetworkTable::SetDefaultStringArray ( StringRef  key,
ArrayRef< std::string >  defaultValue 
)
override

Gets the current value in the table, setting it if it does not exist.

Parameters
keythe key
defaultValuethe default value to set if key doesn't exist.
Returns
False if the table key exists with a different type
bool nt::NetworkTable::SetDefaultValue ( const Twine key,
std::shared_ptr< Value defaultValue 
)
override

Gets the current value in the table, setting it if it does not exist.

Parameters
keythe key
defaultValuethe default value to set if key doesn't exist.
Returns
False if the table key exists with a different type
void nt::NetworkTable::SetFlags ( StringRef  key,
unsigned int  flags 
)
override

Sets flags on the specified key in this table.

The key can not be null.

Parameters
keythe key name
flagsthe flags to set (bitmask)
static void nt::NetworkTable::SetNetworkIdentity ( StringRef  name)
static

Sets the network identity.

This is provided in the connection info on the remote end.

Parameters
nameidentity
void nt::NetworkTable::SetPersistent ( StringRef  key)
override

Makes a key's value persistent through program restarts.

Parameters
keythe key to make persistent
static void nt::NetworkTable::SetUpdateRate ( double  interval)
static

Set the periodic update rate.

Sets how frequently updates are sent to other nodes over the network.

Parameters
intervalupdate interval in seconds (range 0.01 to 1.0)
nt::NetworkTable::WPI_DEPRECATED ( "use NetworkTableInstance::SetServerTeam() or ""NetworkTableInstance::StartClientTeam() instead"  )

set the team the robot is configured for (this will set the mdns address that network tables will connect to in client mode) This must be called before initialize or GetTable

Parameters
teamthe team number
nt::NetworkTable::WPI_DEPRECATED ( "use NetworkTableInstance::SetServer() or ""NetworkTableInstance::StartClient() instead"  )
Parameters
addressthe adress that network tables will connect to in client mode
nt::NetworkTable::WPI_DEPRECATED ( "use NetworkTableInstance::StartDSClient() and ""NetworkTableInstance::StopDSClient() instead"  )

Enable requesting the server address from the Driver Station.

Parameters
enabledwhether to enable the connection to the local DS
nt::NetworkTable::WPI_DEPRECATED ( "use the appropriate parameter to NetworkTableInstance::StartServer() ""instead"  )

Sets the persistent filename.

Parameters
filenamethe filename that the network tables server uses for automatic loading and saving of persistent values

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