WPILibC++
2019.1.1-beta-2-17-g6f0c185
|
A network table that knows its subtable path. More...
#include <NetworkTable.h>
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) const |
Listen for sub-table creation. More... | |
void | RemoveTableListener (NT_EntryListener listener) const |
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< NetworkTable > | GetSubTable (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< Value > | GetValue (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 |
A network table that knows its subtable path.
nt::NetworkTable::NetworkTable | ( | NT_Inst | inst, |
const Twine & | path, | ||
const private_init & | |||
) |
Constructor.
Use NetworkTableInstance::GetTable() or GetSubTable() instead.
NT_EntryListener nt::NetworkTable::AddEntryListener | ( | TableEntryListener | listener, |
unsigned int | flags | ||
) | const |
Listen to keys only within this table.
listener | listener to add |
flags | EntryListenerFlags bitmask |
NT_EntryListener nt::NetworkTable::AddEntryListener | ( | const Twine & | key, |
TableEntryListener | listener, | ||
unsigned int | flags | ||
) | const |
Listen to a single key.
key | the key name |
listener | listener to add |
flags | EntryListenerFlags bitmask |
NT_EntryListener nt::NetworkTable::AddSubTableListener | ( | TableListener | listener, |
bool | localNotify = false |
||
) | const |
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 |
localNotify | notify local changes as well as remote |
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 |
|
override |
Clears flags on the specified key in this table.
The key can not be null.
key | the key name |
flags | the flags to clear (bitmask) |
|
override |
Stop making a key's value persistent through program restarts.
The key cannot be null.
key | the key name |
|
override |
Determines whether the given key is in this table.
key | the key to search for |
|
override |
Determines whether there exists a non-empty subtable for this key in this table.
key | the key to search for |
|
override |
Deletes the specified key in this table.
key | the key name |
|
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.
|
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.
key | the key to look up |
defaultValue | the value to be returned if no value is found |
|
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.
key | the key to look up |
defaultValue | the value to be returned if no value is found |
|
override |
Returns the flags for the specified key.
key | the key name |
|
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.
|
override |
Gets all keys in the table (not including sub-tables).
types | bitmask of types; 0 is treated as a "don't care". |
|
override |
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 |
|
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.
key | the key to look up |
defaultValue | the value to be returned if no value is found |
|
override |
Gets the full path of this table.
Does not include the trailing "/".
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 |
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 |
|
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.
key | the key to look up |
defaultValue | the value to be returned if no value is found |
|
override |
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 |
|
override |
Gets the names of all subtables in the table.
Gets the value associated with a key as an object.
key | the key of the value to look up |
|
static |
Deletes ALL keys in ALL subtables.
Use with caution!
|
override |
Returns whether the value is persistent through program restarts.
The key cannot be null.
key | the 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.
filename | filename |
warn | callback function for warnings |
|
static |
Loads persistent keys from a file.
The server does this automatically.
filename | file name |
warn | callback function called for warnings |
|
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 |
|
override |
Put a boolean in the table.
key | the key to be assigned to |
value | the value that will be assigned |
Put a boolean array in the table.
key | the key to be assigned to |
value | the value that will be assigned |
|
override |
Put a number in the table.
key | the key to be assigned to |
value | the value that will be assigned |
Put a number array in the table.
key | the key to be assigned to |
value | the value that will be assigned |
Put a raw value (byte array) in the table.
key | the key to be assigned to |
value | the value that will be assigned |
Put a string in the table.
key | the key to be assigned to |
value | the value that will be assigned |
Put a string array in the table.
key | the key to be assigned to |
value | the value that will be assigned |
Put a value in the table.
key | the key to be assigned to |
value | the value that will be assigned |
void nt::NetworkTable::RemoveEntryListener | ( | NT_EntryListener | listener | ) | const |
Remove an entry listener.
listener | listener handle |
void nt::NetworkTable::RemoveTableListener | ( | NT_EntryListener | listener | ) | const |
Remove a sub-table listener.
listener | listener 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.
filename | filename |
|
static |
Saves persistent keys to a file.
The server does this automatically.
filename | file name |
|
override |
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. |
|
override |
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. |
|
override |
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. |
|
override |
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. |
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. |
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. |
|
override |
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. |
|
override |
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. |
|
override |
Sets flags on the specified key in this table.
The key can not be null.
key | the key name |
flags | the flags to set (bitmask) |
|
static |
Sets the network identity.
This is provided in the connection info on the remote end.
name | identity |
|
override |
Makes a key's value persistent through program restarts.
key | the key to make persistent |
|
static |
Set the periodic update rate.
Sets how frequently updates are sent to other nodes over the network.
interval | update 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
team | the team number |
nt::NetworkTable::WPI_DEPRECATED | ( | "use NetworkTableInstance::SetServer() or ""NetworkTableInstance::StartClient() instead" | ) |
address | the 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.
enabled | whether to enable the connection to the local DS |
nt::NetworkTable::WPI_DEPRECATED | ( | "use the appropriate parameter to NetworkTableInstance::StartServer() ""instead" | ) |
Sets the persistent filename.
filename | the filename that the network tables server uses for automatic loading and saving of persistent values |