WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
NetworkTable Class Reference

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

#include <NetworkTable.h>

Inheritance diagram for NetworkTable:
ITable

Public Member Functions

 NetworkTable (llvm::StringRef path, const private_init &)
 
void AddTableListener (ITableListener *listener) override
 Add a listener for changes to the table. More...
 
void AddTableListener (ITableListener *listener, bool immediateNotify) override
 Add a listener for changes to the table. More...
 
void AddTableListenerEx (ITableListener *listener, unsigned int flags) override
 Add a listener for changes to the table. More...
 
void AddTableListener (llvm::StringRef key, ITableListener *listener, bool immediateNotify) override
 Add a listener for changes to a specific key the table. More...
 
void AddTableListenerEx (llvm::StringRef key, ITableListener *listener, unsigned int flags) override
 Add a listener for changes to a specific key the table. More...
 
void AddSubTableListener (ITableListener *listener) override
 This will immediately notify the listener of all current sub tables. More...
 
void AddSubTableListener (ITableListener *listener, bool localNotify) override
 This will immediately notify the listener of all current sub tables. More...
 
void RemoveTableListener (ITableListener *listener) override
 Remove a listener from receiving table events. More...
 
std::shared_ptr< ITableGetSubTable (llvm::StringRef key) const override
 Returns the table at the specified key. More...
 
bool ContainsKey (llvm::StringRef key) const override
 Determines whether the given key is in this table. More...
 
bool ContainsSubTable (llvm::StringRef 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
 
std::vector< std::string > GetSubTables () const override
 
void SetPersistent (llvm::StringRef key) override
 Makes a key's value persistent through program restarts. More...
 
void ClearPersistent (llvm::StringRef key) override
 Stop making a key's value persistent through program restarts. More...
 
bool IsPersistent (llvm::StringRef key) const override
 Returns whether the value is persistent through program restarts. More...
 
void SetFlags (llvm::StringRef key, unsigned int flags) override
 Sets flags on the specified key in this table. More...
 
void ClearFlags (llvm::StringRef key, unsigned int flags) override
 Clears flags on the specified key in this table. More...
 
unsigned int GetFlags (llvm::StringRef key) const override
 Returns the flags for the specified key. More...
 
void Delete (llvm::StringRef key) override
 Deletes the specified key in this table. More...
 
bool PutNumber (llvm::StringRef key, double value) override
 Put a number in the table. More...
 
virtual bool SetDefaultNumber (llvm::StringRef key, double defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
virtual bool PutString (llvm::StringRef key, llvm::StringRef value) override
 Put a string in the table. More...
 
virtual bool SetDefaultString (llvm::StringRef key, llvm::StringRef defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
virtual bool PutBoolean (llvm::StringRef key, bool value) override
 Put a boolean in the table. More...
 
virtual bool SetDefaultBoolean (llvm::StringRef key, bool defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
virtual bool PutBooleanArray (llvm::StringRef key, llvm::ArrayRef< int > value) override
 Put a boolean array in the table. More...
 
virtual bool SetDefaultBooleanArray (llvm::StringRef key, llvm::ArrayRef< int > defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
virtual std::vector< int > GetBooleanArray (llvm::StringRef key, llvm::ArrayRef< int > defaultValue) const override
 Returns the boolean array the key maps to. More...
 
virtual bool PutNumberArray (llvm::StringRef key, llvm::ArrayRef< double > value) override
 Put a number array in the table. More...
 
virtual bool SetDefaultNumberArray (llvm::StringRef key, llvm::ArrayRef< double > defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
virtual std::vector< double > GetNumberArray (llvm::StringRef key, llvm::ArrayRef< double > defaultValue) const override
 Returns the number array the key maps to. More...
 
virtual bool PutStringArray (llvm::StringRef key, llvm::ArrayRef< std::string > value) override
 Put a string array in the table. More...
 
virtual bool SetDefaultStringArray (llvm::StringRef key, llvm::ArrayRef< std::string > defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
virtual std::vector< std::string > GetStringArray (llvm::StringRef key, llvm::ArrayRef< std::string > defaultValue) const override
 Returns the string array the key maps to. More...
 
virtual bool PutRaw (llvm::StringRef key, llvm::StringRef value) override
 Put a raw value (byte array) in the table. More...
 
virtual bool SetDefaultRaw (llvm::StringRef key, llvm::StringRef defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
virtual std::string GetRaw (llvm::StringRef key, llvm::StringRef defaultValue) const override
 Returns the raw value (byte array) the key maps to. More...
 
bool PutValue (llvm::StringRef key, std::shared_ptr< nt::Value > value) override
 Put a value in the table. More...
 
virtual bool SetDefaultValue (llvm::StringRef key, std::shared_ptr< nt::Value > defaultValue) override
 Gets the current value in the table, setting it if it does not exist. More...
 
std::shared_ptr< nt::ValueGetValue (llvm::StringRef key) const override
 Gets the value associated with a key as an object. More...
 

Static Public Member Functions

static void Initialize ()
 
static void Shutdown ()
 
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 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...
 
static void SetIPAddress (llvm::StringRef address)
 
static void SetIPAddress (llvm::ArrayRef< std::string > addresses)
 
static void SetPort (unsigned int port)
 
static void SetDSClientEnabled (bool enabled)
 
static void SetPersistentFilename (llvm::StringRef filename)
 Sets the persistent filename. More...
 
static void SetNetworkIdentity (llvm::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 (llvm::StringRef filename)
 Saves persistent keys to a file. More...
 
static const char * LoadPersistent (llvm::StringRef filename, std::function< void(size_t line, const char *msg)> warn)
 Loads persistent keys from a file. More...
 
static std::shared_ptr
< NetworkTable
GetTable (llvm::StringRef key)
 Gets the table with the specified key. More...
 

Static Public Attributes

static const char PATH_SEPARATOR_CHAR = '/'
 The path separator for sub-tables and keys. More...
 

Detailed Description

A network table that knows its subtable path.

Member Function Documentation

void NetworkTable::AddSubTableListener ( ITableListener listener)
overridevirtual

This will immediately notify the listener of all current sub tables.

Parameters
listenerthe listener to add

Implements ITable.

void NetworkTable::AddSubTableListener ( ITableListener listener,
bool  localNotify 
)
overridevirtual

This will immediately notify the listener of all current sub tables.

Parameters
listenerthe listener to add
localNotifyif true then this listener will be notified of all local changes in addition to all remote changes

Implements ITable.

void NetworkTable::AddTableListener ( ITableListener listener)
overridevirtual

Add a listener for changes to the table.

Parameters
listenerthe listener to add

Implements ITable.

void NetworkTable::AddTableListener ( ITableListener listener,
bool  immediateNotify 
)
overridevirtual

Add a listener for changes to the table.

Parameters
listenerthe listener to add
immediateNotifyif true then this listener will be notified of all current entries (marked as new)

Implements ITable.

void NetworkTable::AddTableListener ( llvm::StringRef  key,
ITableListener listener,
bool  immediateNotify 
)
overridevirtual

Add a listener for changes to a specific key the table.

Parameters
keythe key to listen for
listenerthe listener to add
immediateNotifyif true then this listener will be notified of all current entries (marked as new)

Implements ITable.

void NetworkTable::AddTableListenerEx ( ITableListener listener,
unsigned int  flags 
)
overridevirtual

Add a listener for changes to the table.

Parameters
listenerthe listener to add
immediateNotifyif true then this listener will be notified of all current entries (marked as new)
flagsbitmask of NT_NotifyKind specifying desired notifications

Implements ITable.

void NetworkTable::AddTableListenerEx ( llvm::StringRef  key,
ITableListener listener,
unsigned int  flags 
)
overridevirtual

Add a listener for changes to a specific key the table.

Parameters
keythe key to listen for
listenerthe listener to add
immediateNotifyif true then this listener will be notified of all current entries (marked as new)
flagsbitmask of NT_NotifyKind specifying desired notifications

Implements ITable.

void NetworkTable::ClearFlags ( llvm::StringRef  key,
unsigned int  flags 
)
overridevirtual

Clears flags on the specified key in this table.

The key can not be null.

Parameters
keythe key name
flagsthe flags to clear (bitmask)

Implements ITable.

void NetworkTable::ClearPersistent ( llvm::StringRef  key)
overridevirtual

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

The key cannot be null.

Parameters
keythe key name

Implements ITable.

bool NetworkTable::ContainsKey ( llvm::StringRef  key) const
overridevirtual

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

Implements ITable.

bool NetworkTable::ContainsSubTable ( llvm::StringRef  key) const
overridevirtual

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

Implements ITable.

void NetworkTable::Delete ( llvm::StringRef  key)
overridevirtual

Deletes the specified key in this table.

Parameters
keythe key name

Implements ITable.

void 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.

std::vector< int > NetworkTable::GetBooleanArray ( llvm::StringRef  key,
llvm::ArrayRef< int >  defaultValue 
) const
overridevirtual

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.

Implements ITable.

unsigned int NetworkTable::GetFlags ( llvm::StringRef  key) const
overridevirtual

Returns the flags for the specified key.

Parameters
keythe key name
Returns
the flags, or 0 if the key is not defined

Implements ITable.

std::vector< std::string > NetworkTable::GetKeys ( int  types = 0) const
overridevirtual
Parameters
typesbitmask of types; 0 is treated as a "don't care".
Returns
keys currently in the table

Implements ITable.

std::vector< double > NetworkTable::GetNumberArray ( llvm::StringRef  key,
llvm::ArrayRef< double >  defaultValue 
) const
overridevirtual

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.

Implements ITable.

std::string NetworkTable::GetRaw ( llvm::StringRef  key,
llvm::StringRef  defaultValue 
) const
overridevirtual

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.

Implements ITable.

std::vector< std::string > NetworkTable::GetStringArray ( llvm::StringRef  key,
llvm::ArrayRef< std::string >  defaultValue 
) const
overridevirtual

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.

Implements ITable.

std::shared_ptr< ITable > NetworkTable::GetSubTable ( llvm::StringRef  key) const
overridevirtual

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

Implements ITable.

std::vector< std::string > NetworkTable::GetSubTables ( ) const
overridevirtual
Returns
subtables currently in the table

Implements ITable.

std::shared_ptr< NetworkTable > NetworkTable::GetTable ( llvm::StringRef  key)
static

Gets the table with the specified key.

If the table does not exist, a new table will be created.
This will automatically initialize network tables if it has not been already.

Parameters
keythe key name
Returns
the network table requested
std::shared_ptr< nt::Value > NetworkTable::GetValue ( llvm::StringRef  key) const
overridevirtual

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

Implements ITable.

void NetworkTable::GlobalDeleteAll ( )
static

Deletes ALL keys in ALL subtables.

Use with caution!

void NetworkTable::Initialize ( )
static
Exceptions
IOException
bool NetworkTable::IsPersistent ( llvm::StringRef  key) const
overridevirtual

Returns whether the value is persistent through program restarts.

The key cannot be null.

Parameters
keythe key name

Implements ITable.

const char * NetworkTable::LoadPersistent ( llvm::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).
bool NetworkTable::PutBoolean ( llvm::StringRef  key,
bool  value 
)
overridevirtual

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

Implements ITable.

bool NetworkTable::PutBooleanArray ( llvm::StringRef  key,
llvm::ArrayRef< int >  value 
)
overridevirtual

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.

Implements ITable.

bool NetworkTable::PutNumber ( llvm::StringRef  key,
double  value 
)
overridevirtual

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

Implements ITable.

bool NetworkTable::PutNumberArray ( llvm::StringRef  key,
llvm::ArrayRef< double >  value 
)
overridevirtual

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

Implements ITable.

bool NetworkTable::PutRaw ( llvm::StringRef  key,
llvm::StringRef  value 
)
overridevirtual

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

Implements ITable.

bool NetworkTable::PutString ( llvm::StringRef  key,
llvm::StringRef  value 
)
overridevirtual

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

Implements ITable.

bool NetworkTable::PutStringArray ( llvm::StringRef  key,
llvm::ArrayRef< std::string >  value 
)
overridevirtual

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

Implements ITable.

bool NetworkTable::PutValue ( llvm::StringRef  key,
std::shared_ptr< nt::Value value 
)
overridevirtual

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

Implements ITable.

void NetworkTable::RemoveTableListener ( ITableListener listener)
overridevirtual

Remove a listener from receiving table events.

Parameters
listenerthe listener to be removed

Implements ITable.

const char * NetworkTable::SavePersistent ( llvm::StringRef  filename)
static

Saves persistent keys to a file.

The server does this automatically.

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

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

Implements ITable.

bool NetworkTable::SetDefaultBooleanArray ( llvm::StringRef  key,
llvm::ArrayRef< int >  defaultValue 
)
overridevirtual

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

Implements ITable.

bool NetworkTable::SetDefaultNumber ( llvm::StringRef  key,
double  defaultValue 
)
overridevirtual

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

Implements ITable.

bool NetworkTable::SetDefaultNumberArray ( llvm::StringRef  key,
llvm::ArrayRef< double >  defaultValue 
)
overridevirtual

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

Implements ITable.

bool NetworkTable::SetDefaultRaw ( llvm::StringRef  key,
llvm::StringRef  defaultValue 
)
overridevirtual

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

Implements ITable.

bool NetworkTable::SetDefaultString ( llvm::StringRef  key,
llvm::StringRef  defaultValue 
)
overridevirtual

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

Implements ITable.

bool NetworkTable::SetDefaultStringArray ( llvm::StringRef  key,
llvm::ArrayRef< std::string >  defaultValue 
)
overridevirtual

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

Implements ITable.

bool NetworkTable::SetDefaultValue ( llvm::StringRef  key,
std::shared_ptr< nt::Value defaultValue 
)
overridevirtual

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

Implements ITable.

void NetworkTable::SetDSClientEnabled ( bool  enabled)
static
Parameters
enabledwhether to enable the connection to the local DS to get the robot IP address (defaults to enabled)
void NetworkTable::SetFlags ( llvm::StringRef  key,
unsigned int  flags 
)
overridevirtual

Sets flags on the specified key in this table.

The key can not be null.

Parameters
keythe key name
flagsthe flags to set (bitmask)

Implements ITable.

static void NetworkTable::SetIPAddress ( llvm::StringRef  address)
static
Parameters
addressthe adress that network tables will connect to in client mode
void NetworkTable::SetIPAddress ( llvm::ArrayRef< std::string >  addresses)
static
Parameters
addressesthe addresses that network tables will connect to in client mode (in round robin order)
void NetworkTable::SetNetworkIdentity ( llvm::StringRef  name)
static

Sets the network identity.

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

Parameters
nameidentity
void NetworkTable::SetPersistent ( llvm::StringRef  key)
overridevirtual

Makes a key's value persistent through program restarts.

Parameters
keythe key to make persistent

Implements ITable.

void NetworkTable::SetPersistentFilename ( llvm::StringRef  filename)
static

Sets the persistent filename.

Parameters
filenamethe filename that the network tables server uses for automatic loading and saving of persistent values
void NetworkTable::SetPort ( unsigned int  port)
static
Parameters
portthe port number that network tables will connect to in client mode or listen to in server mode
void NetworkTable::SetTeam ( int  team)
static

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
void NetworkTable::SetUpdateRate ( double  interval)
static

Set the periodic update rate.

Parameters
intervalupdate interval in seconds (range 0.01 to 1.0)

Member Data Documentation

const char NetworkTable::PATH_SEPARATOR_CHAR = '/'
static

The path separator for sub-tables and keys.


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