[ntcore] Remove deprecated ITable interfaces

This commit is contained in:
Peter Johnson
2021-04-04 13:53:42 -07:00
parent 36608a283b
commit c2064c78b2
5 changed files with 44 additions and 1045 deletions

View File

@@ -20,7 +20,6 @@
#include "networktables/TableEntryListener.h"
#include "networktables/TableListener.h"
#include "ntcore_c.h"
#include "tables/ITable.h"
namespace nt {
@@ -30,14 +29,6 @@ using wpi::Twine;
class NetworkTableInstance;
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif _WIN32
#pragma warning(push)
#pragma warning(disable : 4996)
#endif
/**
* @defgroup ntcore_cpp_api ntcore C++ object-oriented API
*
@@ -48,22 +39,13 @@ class NetworkTableInstance;
* A network table that knows its subtable path.
* @ingroup ntcore_cpp_api
*/
class NetworkTable final : public ITable {
class NetworkTable final {
private:
NT_Inst m_inst;
std::string m_path;
mutable wpi::mutex m_mutex;
mutable wpi::StringMap<NT_Entry> m_entries;
typedef std::pair<ITableListener*, NT_EntryListener> Listener;
std::vector<Listener> m_listeners;
std::vector<NT_EntryListener> m_lambdaListeners;
static std::vector<std::string> s_ip_addresses;
static std::string s_persistent_filename;
static bool s_client;
static bool s_enable_ds;
static bool s_running;
static unsigned int s_port;
std::vector<NT_EntryListener> m_listeners;
struct private_init {};
friend class NetworkTableInstance;
@@ -128,169 +110,7 @@ class NetworkTable final : public ITable {
/**
* The path separator for sub-tables and keys
*/
static const char PATH_SEPARATOR_CHAR;
/**
* Initializes network tables
*/
WPI_DEPRECATED(
"use NetworkTableInstance::StartServer() or "
"NetworkTableInstance::StartClient() instead")
static void Initialize();
/**
* Shuts down network tables
*/
WPI_DEPRECATED(
"use NetworkTableInstance::StopServer() or "
"NetworkTableInstance::StopClient() instead")
static void Shutdown();
/**
* set that network tables should be a client
* This must be called before initialize or GetTable
*/
WPI_DEPRECATED("use NetworkTableInstance::StartClient() instead")
static void SetClientMode();
/**
* set that network tables should be a server
* This must be called before initialize or GetTable
*/
WPI_DEPRECATED("use NetworkTableInstance::StartServer() instead")
static void SetServerMode();
/**
* 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
*
* @param team the team number
*/
WPI_DEPRECATED(
"use NetworkTableInstance::SetServerTeam() or "
"NetworkTableInstance::StartClientTeam() instead")
static void SetTeam(int team);
/**
* @param address the address that network tables will connect to in client
* mode
*/
WPI_DEPRECATED(
"use NetworkTableInstance::SetServer() or "
"NetworkTableInstance::StartClient() instead")
static void SetIPAddress(StringRef address);
/**
* @param addresses the addresses that network tables will connect to in
* client mode (in round robin order)
*/
WPI_DEPRECATED(
"use NetworkTableInstance::SetServer() or "
"NetworkTableInstance::StartClient() instead")
static void SetIPAddress(ArrayRef<std::string> addresses);
/**
* Set the port number that network tables will connect to in client
* mode or listen to in server mode.
*
* @param port the port number
*/
WPI_DEPRECATED(
"use the appropriate parameters to NetworkTableInstance::SetServer(), "
"NetworkTableInstance::StartClient(), "
"NetworkTableInstance::StartServer(), and "
"NetworkTableInstance::StartDSClient() instead")
static void SetPort(unsigned int port);
/**
* Enable requesting the server address from the Driver Station.
*
* @param enabled whether to enable the connection to the local DS
*/
WPI_DEPRECATED(
"use NetworkTableInstance::StartDSClient() and "
"NetworkTableInstance::StopDSClient() instead")
static void SetDSClientEnabled(bool enabled);
/**
* Sets the persistent filename.
*
* @param filename the filename that the network tables server uses for
* automatic loading and saving of persistent values
*/
WPI_DEPRECATED(
"use the appropriate parameter to NetworkTableInstance::StartServer() "
"instead")
static void SetPersistentFilename(StringRef filename);
/**
* Sets the network identity.
* This is provided in the connection info on the remote end.
*
* @param name identity
*/
WPI_DEPRECATED("use NetworkTableInstance::SetNetworkIdentity() instead")
static void SetNetworkIdentity(StringRef name);
/**
* Deletes ALL keys in ALL subtables. Use with caution!
*/
WPI_DEPRECATED("use NetworkTableInstance::DeleteAllEntries() instead")
static void GlobalDeleteAll();
/**
* 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.
*/
WPI_DEPRECATED("use NetworkTableInstance::Flush() instead")
static void Flush();
/**
* Set the periodic update rate.
* Sets how frequently updates are sent to other nodes over the network.
*
* @param interval update interval in seconds (range 0.01 to 1.0)
*/
WPI_DEPRECATED("use NetworkTableInstance::SetUpdateRate() instead")
static void SetUpdateRate(double interval);
/**
* Saves persistent keys to a file. The server does this automatically.
*
* @param filename file name
* @return Error (or nullptr).
*/
WPI_DEPRECATED("use NetworkTableInstance::SavePersistent() instead")
static const char* SavePersistent(StringRef filename);
/**
* Loads persistent keys from a file. The server does this automatically.
*
* @param filename file name
* @param warn callback function called for warnings
* @return Error (or nullptr).
*/
WPI_DEPRECATED("use NetworkTableInstance::LoadPersistent() instead")
static const char* LoadPersistent(
StringRef filename,
std::function<void(size_t line, const char* msg)> warn);
/**
* Gets the table with the specified key. If the table does not exist, a new
* table will be created.<br>
* This will automatically initialize network tables if it has not been
* already.
*
* @param key the key name
* @return the network table requested
*/
WPI_DEPRECATED(
"use NetworkTableInstance::GetTable() or "
"NetworkTableInstance::GetEntry() instead")
static std::shared_ptr<NetworkTable> GetTable(StringRef key);
static constexpr char PATH_SEPARATOR_CHAR = '/';
/**
* Gets the entry for a subkey.
@@ -348,38 +168,6 @@ class NetworkTable final : public ITable {
*/
void RemoveTableListener(NT_EntryListener listener);
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,
bool immediateNotify) override;
WPI_DEPRECATED("use AddEntryListener() instead")
void AddTableListenerEx(ITableListener* listener,
unsigned int flags) override;
WPI_DEPRECATED("use AddEntryListener() instead")
void AddTableListener(StringRef key, ITableListener* listener,
bool immediateNotify) override;
WPI_DEPRECATED("use AddEntryListener() instead")
void AddTableListenerEx(StringRef key, ITableListener* listener,
unsigned int flags) override;
WPI_DEPRECATED("use AddSubTableListener(TableListener, bool) instead")
void AddSubTableListener(ITableListener* listener) override;
WPI_DEPRECATED("use AddSubTableListener(TableListener, bool) instead")
void AddSubTableListener(ITableListener* listener, bool localNotify) override;
WPI_DEPRECATED("use RemoveTableListener(NT_EntryListener) instead")
void RemoveTableListener(ITableListener* listener) override;
/**
* Returns the table at the specified key. If there is no table at the
* specified key, it will create a new table
@@ -387,7 +175,7 @@ class NetworkTable final : public ITable {
* @param key the key name
* @return the networktable to be returned
*/
std::shared_ptr<NetworkTable> GetSubTable(const Twine& key) const override;
std::shared_ptr<NetworkTable> GetSubTable(const Twine& key) const;
/**
* Determines whether the given key is in this table.
@@ -395,7 +183,7 @@ class NetworkTable final : public ITable {
* @param key the key to search for
* @return true if the table as a value assigned to the given key
*/
bool ContainsKey(const Twine& key) const override;
bool ContainsKey(const Twine& key) const;
/**
* Determines whether there exists a non-empty subtable for this key
@@ -405,7 +193,7 @@ class NetworkTable final : public ITable {
* @return true if there is a subtable with the key which contains at least
* one key/subtable of its own
*/
bool ContainsSubTable(const Twine& key) const override;
bool ContainsSubTable(const Twine& key) const;
/**
* Gets all keys in the table (not including sub-tables).
@@ -413,21 +201,21 @@ class NetworkTable final : public ITable {
* @param types bitmask of types; 0 is treated as a "don't care".
* @return keys currently in the table
*/
std::vector<std::string> GetKeys(int types = 0) const override;
std::vector<std::string> GetKeys(int types = 0) const;
/**
* Gets the names of all subtables in the table.
*
* @return subtables currently in the table
*/
std::vector<std::string> GetSubTables() const override;
std::vector<std::string> GetSubTables() const;
/**
* Makes a key's value persistent through program restarts.
*
* @param key the key to make persistent
*/
void SetPersistent(StringRef key) override;
void SetPersistent(StringRef key);
/**
* Stop making a key's value persistent through program restarts.
@@ -435,7 +223,7 @@ class NetworkTable final : public ITable {
*
* @param key the key name
*/
void ClearPersistent(StringRef key) override;
void ClearPersistent(StringRef key);
/**
* Returns whether the value is persistent through program restarts.
@@ -443,7 +231,7 @@ class NetworkTable final : public ITable {
*
* @param key the key name
*/
bool IsPersistent(StringRef key) const override;
bool IsPersistent(StringRef key) const;
/**
* Sets flags on the specified key in this table. The key can
@@ -452,7 +240,7 @@ class NetworkTable final : public ITable {
* @param key the key name
* @param flags the flags to set (bitmask)
*/
void SetFlags(StringRef key, unsigned int flags) override;
void SetFlags(StringRef key, unsigned int flags);
/**
* Clears flags on the specified key in this table. The key can
@@ -461,7 +249,7 @@ class NetworkTable final : public ITable {
* @param key the key name
* @param flags the flags to clear (bitmask)
*/
void ClearFlags(StringRef key, unsigned int flags) override;
void ClearFlags(StringRef key, unsigned int flags);
/**
* Returns the flags for the specified key.
@@ -469,14 +257,14 @@ class NetworkTable final : public ITable {
* @param key the key name
* @return the flags, or 0 if the key is not defined
*/
unsigned int GetFlags(StringRef key) const override;
unsigned int GetFlags(StringRef key) const;
/**
* Deletes the specified key in this table.
*
* @param key the key name
*/
void Delete(const Twine& key) override;
void Delete(const Twine& key);
/**
* Put a number in the table
@@ -485,7 +273,7 @@ class NetworkTable final : public ITable {
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
bool PutNumber(StringRef key, double value) override;
bool PutNumber(StringRef key, double value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -494,7 +282,7 @@ class NetworkTable final : public ITable {
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
bool SetDefaultNumber(StringRef key, double defaultValue) override;
bool SetDefaultNumber(StringRef key, double defaultValue);
/**
* Gets the number associated with the given name.
@@ -504,7 +292,7 @@ class NetworkTable final : public ITable {
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*/
double GetNumber(StringRef key, double defaultValue) const override;
double GetNumber(StringRef key, double defaultValue) const;
/**
* Put a string in the table
@@ -513,7 +301,7 @@ class NetworkTable final : public ITable {
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
bool PutString(StringRef key, StringRef value) override;
bool PutString(StringRef key, StringRef value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -522,7 +310,7 @@ class NetworkTable final : public ITable {
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
bool SetDefaultString(StringRef key, StringRef defaultValue) override;
bool SetDefaultString(StringRef key, StringRef defaultValue);
/**
* Gets the string associated with the given name. If the key does not
@@ -533,7 +321,7 @@ class NetworkTable final : public ITable {
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*/
std::string GetString(StringRef key, StringRef defaultValue) const override;
std::string GetString(StringRef key, StringRef defaultValue) const;
/**
* Put a boolean in the table
@@ -542,7 +330,7 @@ class NetworkTable final : public ITable {
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
bool PutBoolean(StringRef key, bool value) override;
bool PutBoolean(StringRef key, bool value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -551,7 +339,7 @@ class NetworkTable final : public ITable {
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
bool SetDefaultBoolean(StringRef key, bool defaultValue) override;
bool SetDefaultBoolean(StringRef key, bool defaultValue);
/**
* Gets the boolean associated with the given name. If the key does not
@@ -562,7 +350,7 @@ class NetworkTable final : public ITable {
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*/
bool GetBoolean(StringRef key, bool defaultValue) const override;
bool GetBoolean(StringRef key, bool defaultValue) const;
/**
* Put a boolean array in the table
@@ -575,7 +363,7 @@ class NetworkTable final : public ITable {
* std::vector<bool> is special-cased in C++. 0 is false, any
* non-zero value is true.
*/
bool PutBooleanArray(StringRef key, ArrayRef<int> value) override;
bool PutBooleanArray(StringRef key, ArrayRef<int> value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -584,8 +372,7 @@ class NetworkTable final : public ITable {
* @param defaultValue the default value to set if key doesn't exist.
* @return False if the table key exists with a different type
*/
bool SetDefaultBooleanArray(StringRef key,
ArrayRef<int> defaultValue) override;
bool SetDefaultBooleanArray(StringRef key, ArrayRef<int> defaultValue);
/**
* Returns the boolean array the key maps to. If the key does not exist or is
@@ -604,7 +391,7 @@ class NetworkTable final : public ITable {
* non-zero value is true.
*/
std::vector<int> GetBooleanArray(StringRef key,
ArrayRef<int> defaultValue) const override;
ArrayRef<int> defaultValue) const;
/**
* Put a number array in the table
@@ -613,7 +400,7 @@ class NetworkTable final : public ITable {
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
bool PutNumberArray(StringRef key, ArrayRef<double> value) override;
bool PutNumberArray(StringRef key, ArrayRef<double> value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -622,8 +409,7 @@ class NetworkTable final : public ITable {
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
bool SetDefaultNumberArray(StringRef key,
ArrayRef<double> defaultValue) override;
bool SetDefaultNumberArray(StringRef key, ArrayRef<double> defaultValue);
/**
* Returns the number array the key maps to. If the key does not exist or is
@@ -637,8 +423,8 @@ class NetworkTable final : public ITable {
* @note This makes a copy of the array. If the overhead of this is a
* concern, use GetValue() instead.
*/
std::vector<double> GetNumberArray(
StringRef key, ArrayRef<double> defaultValue) const override;
std::vector<double> GetNumberArray(StringRef key,
ArrayRef<double> defaultValue) const;
/**
* Put a string array in the table
@@ -647,7 +433,7 @@ class NetworkTable final : public ITable {
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
bool PutStringArray(StringRef key, ArrayRef<std::string> value) override;
bool PutStringArray(StringRef key, ArrayRef<std::string> value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -656,8 +442,7 @@ class NetworkTable final : public ITable {
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
bool SetDefaultStringArray(StringRef key,
ArrayRef<std::string> defaultValue) override;
bool SetDefaultStringArray(StringRef key, ArrayRef<std::string> defaultValue);
/**
* Returns the string array the key maps to. If the key does not exist or is
@@ -672,7 +457,7 @@ class NetworkTable final : public ITable {
* concern, use GetValue() instead.
*/
std::vector<std::string> GetStringArray(
StringRef key, ArrayRef<std::string> defaultValue) const override;
StringRef key, ArrayRef<std::string> defaultValue) const;
/**
* Put a raw value (byte array) in the table
@@ -681,7 +466,7 @@ class NetworkTable final : public ITable {
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
bool PutRaw(StringRef key, StringRef value) override;
bool PutRaw(StringRef key, StringRef value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -690,7 +475,7 @@ class NetworkTable final : public ITable {
* @param defaultValue the default value to set if key doesn't exist.
* @return False if the table key exists with a different type
*/
bool SetDefaultRaw(StringRef key, StringRef defaultValue) override;
bool SetDefaultRaw(StringRef key, StringRef defaultValue);
/**
* Returns the raw value (byte array) the key maps to. If the key does not
@@ -704,7 +489,7 @@ class NetworkTable final : public ITable {
* @note This makes a copy of the raw contents. If the overhead of this is a
* concern, use GetValue() instead.
*/
std::string GetRaw(StringRef key, StringRef defaultValue) const override;
std::string GetRaw(StringRef key, StringRef defaultValue) const;
/**
* Put a value in the table
@@ -713,7 +498,7 @@ class NetworkTable final : public ITable {
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
bool PutValue(const Twine& key, std::shared_ptr<Value> value) override;
bool PutValue(const Twine& key, std::shared_ptr<Value> value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -722,8 +507,7 @@ class NetworkTable final : public ITable {
* @param defaultValue the default value to set if key doesn't exist.
* @return False if the table key exists with a different type
*/
bool SetDefaultValue(const Twine& key,
std::shared_ptr<Value> defaultValue) override;
bool SetDefaultValue(const Twine& key, std::shared_ptr<Value> defaultValue);
/**
* Gets the value associated with a key as an object
@@ -732,14 +516,14 @@ class NetworkTable final : public ITable {
* @return the value associated with the given key, or nullptr if the key
* does not exist
*/
std::shared_ptr<Value> GetValue(const Twine& key) const override;
std::shared_ptr<Value> GetValue(const Twine& key) const;
/**
* Gets the full path of this table. Does not include the trailing "/".
*
* @return The path (e.g "", "/foo").
*/
StringRef GetPath() const override;
StringRef GetPath() const;
/**
* Save table values to a file. The file format used is identical to
@@ -763,12 +547,6 @@ class NetworkTable final : public ITable {
std::function<void(size_t line, const char* msg)> warn);
};
#ifdef __GNUC__
#pragma GCC diagnostic pop
#elif _WIN32
#pragma warning(pop)
#endif
} // namespace nt
// For backwards compatibility

View File

@@ -1,453 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#ifndef NTCORE_TABLES_ITABLE_H_
#define NTCORE_TABLES_ITABLE_H_
#include <memory>
#include <string>
#include <vector>
#include <wpi/StringRef.h>
#include <wpi/Twine.h>
#include <wpi/deprecated.h>
#include "networktables/NetworkTableValue.h"
namespace nt {
class NetworkTable;
} // namespace nt
class ITableListener;
/**
* A table whose values can be read and written to
*/
class WPI_DEPRECATED("Use NetworkTable directly") ITable {
public:
/**
* Determines whether the given key is in this table.
*
* @param key the key to search for
* @return true if the table as a value assigned to the given key
*/
virtual bool ContainsKey(const wpi::Twine& key) const = 0;
/**
* Determines whether there exists a non-empty subtable for this key
* in this table.
*
* @param key the key to search for
* @return true if there is a subtable with the key which contains at least
* one key/subtable of its own
*/
virtual bool ContainsSubTable(const wpi::Twine& key) const = 0;
/**
* Gets the subtable in this table for the given name.
*
* @param key the name of the table relative to this one
* @return a sub table relative to this one
*/
virtual std::shared_ptr<nt::NetworkTable> GetSubTable(
const wpi::Twine& key) const = 0;
/**
* @param types bitmask of types; 0 is treated as a "don't care".
* @return keys currently in the table
*/
virtual std::vector<std::string> GetKeys(int types = 0) const = 0;
/**
* @return subtables currently in the table
*/
virtual std::vector<std::string> GetSubTables() const = 0;
/**
* Makes a key's value persistent through program restarts.
*
* @param key the key to make persistent
*/
virtual void SetPersistent(wpi::StringRef key) = 0;
/**
* Stop making a key's value persistent through program restarts.
* The key cannot be null.
*
* @param key the key name
*/
virtual void ClearPersistent(wpi::StringRef key) = 0;
/**
* Returns whether the value is persistent through program restarts.
* The key cannot be null.
*
* @param key the key name
*/
virtual bool IsPersistent(wpi::StringRef key) const = 0;
/**
* Sets flags on the specified key in this table. The key can
* not be null.
*
* @param key the key name
* @param flags the flags to set (bitmask)
*/
virtual void SetFlags(wpi::StringRef key, unsigned int flags) = 0;
/**
* Clears flags on the specified key in this table. The key can
* not be null.
*
* @param key the key name
* @param flags the flags to clear (bitmask)
*/
virtual void ClearFlags(wpi::StringRef key, unsigned int flags) = 0;
/**
* Returns the flags for the specified key.
*
* @param key the key name
* @return the flags, or 0 if the key is not defined
*/
virtual unsigned int GetFlags(wpi::StringRef key) const = 0;
/**
* Deletes the specified key in this table.
*
* @param key the key name
*/
virtual void Delete(const wpi::Twine& key) = 0;
/**
* Gets the value associated with a key as an object
*
* @param key the key of the value to look up
* @return the value associated with the given key, or nullptr if the key
* does not exist
*/
virtual std::shared_ptr<nt::Value> GetValue(const wpi::Twine& key) const = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultValue(const wpi::Twine& key,
std::shared_ptr<nt::Value> defaultValue) = 0;
/**
* Put a value in the table
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
virtual bool PutValue(const wpi::Twine& key,
std::shared_ptr<nt::Value> value) = 0;
/**
* Put a number in the table
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
virtual bool PutNumber(wpi::StringRef key, double value) = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultNumber(wpi::StringRef key, double defaultValue) = 0;
/**
* Gets the number associated with the given name.
*
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*/
virtual double GetNumber(wpi::StringRef key, double defaultValue) const = 0;
/**
* Put a string in the table
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
virtual bool PutString(wpi::StringRef key, wpi::StringRef value) = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultString(wpi::StringRef key,
wpi::StringRef defaultValue) = 0;
/**
* 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.
*
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return 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 string. If the overhead of this is a
* concern, use GetValue() instead.
*/
virtual std::string GetString(wpi::StringRef key,
wpi::StringRef defaultValue) const = 0;
/**
* Put a boolean in the table
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
virtual bool PutBoolean(wpi::StringRef key, bool value) = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultBoolean(wpi::StringRef key, bool defaultValue) = 0;
/**
* 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.
*
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*/
virtual bool GetBoolean(wpi::StringRef key, bool defaultValue) const = 0;
/**
* Put a boolean array in the table
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return 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.
*/
virtual bool PutBooleanArray(wpi::StringRef key,
wpi::ArrayRef<int> value) = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultBooleanArray(wpi::StringRef key,
wpi::ArrayRef<int> defaultValue) = 0;
/**
* 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.
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return 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.
*
* @note 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.
*/
virtual std::vector<int> GetBooleanArray(
wpi::StringRef key, wpi::ArrayRef<int> defaultValue) const = 0;
/**
* Put a number array in the table
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
virtual bool PutNumberArray(wpi::StringRef key,
wpi::ArrayRef<double> value) = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultNumberArray(wpi::StringRef key,
wpi::ArrayRef<double> defaultValue) = 0;
/**
* 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.
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return 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.
*/
virtual std::vector<double> GetNumberArray(
wpi::StringRef key, wpi::ArrayRef<double> defaultValue) const = 0;
/**
* Put a string array in the table
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
virtual bool PutStringArray(wpi::StringRef key,
wpi::ArrayRef<std::string> value) = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultStringArray(
wpi::StringRef key, wpi::ArrayRef<std::string> defaultValue) = 0;
/**
* 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.
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return 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.
*/
virtual std::vector<std::string> GetStringArray(
wpi::StringRef key, wpi::ArrayRef<std::string> defaultValue) const = 0;
/**
* Put a raw value (byte array) in the table
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
virtual bool PutRaw(wpi::StringRef key, wpi::StringRef value) = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultRaw(wpi::StringRef key,
wpi::StringRef defaultValue) = 0;
/**
* 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.
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return 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.
*/
virtual std::string GetRaw(wpi::StringRef key,
wpi::StringRef defaultValue) const = 0;
/**
* Add a listener for changes to the table
*
* @param listener the listener to add
*/
virtual void AddTableListener(ITableListener* listener) = 0;
/**
* Add a listener for changes to the table
*
* @param listener the listener to add
* @param immediateNotify if true then this listener will be notified of all
* current entries (marked as new)
*/
virtual void AddTableListener(ITableListener* listener,
bool immediateNotify) = 0;
/**
* Add a listener for changes to the table
*
* @param listener the listener to add
* @param immediateNotify if true then this listener will be notified of all
* current entries (marked as new)
* @param flags bitmask of NT_NotifyKind specifying desired notifications
*/
virtual void AddTableListenerEx(ITableListener* listener,
unsigned int flags) = 0;
/**
* Add a listener for changes to a specific key the table
*
* @param key the key to listen for
* @param listener the listener to add
* @param immediateNotify if true then this listener will be notified of all
* current entries (marked as new)
*/
virtual void AddTableListener(wpi::StringRef key, ITableListener* listener,
bool immediateNotify) = 0;
/**
* Add a listener for changes to a specific key the table
*
* @param key the key to listen for
* @param listener the listener to add
* @param immediateNotify if true then this listener will be notified of all
* current entries (marked as new)
* @param flags bitmask of NT_NotifyKind specifying desired notifications
*/
virtual void AddTableListenerEx(wpi::StringRef key, ITableListener* listener,
unsigned int flags) = 0;
/**
* This will immediately notify the listener of all current sub tables
* @param listener the listener to add
*/
virtual void AddSubTableListener(ITableListener* listener) = 0;
/**
* This will immediately notify the listener of all current sub tables
* @param listener the listener to add
* @param localNotify if true then this listener will be notified of all
* local changes in addition to all remote changes
*/
virtual void AddSubTableListener(ITableListener* listener,
bool localNotify) = 0;
/**
* Remove a listener from receiving table events
*
* @param listener the listener to be removed
*/
virtual void RemoveTableListener(ITableListener* listener) = 0;
/**
* Gets the full path of this table.
*/
virtual wpi::StringRef GetPath() const = 0;
};
#endif // NTCORE_TABLES_ITABLE_H_

View File

@@ -1,65 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#ifndef NTCORE_TABLES_ITABLELISTENER_H_
#define NTCORE_TABLES_ITABLELISTENER_H_
#include <memory>
#include <wpi/StringRef.h>
#include <wpi/deprecated.h>
#include "networktables/NetworkTableValue.h"
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif _WIN32
#pragma warning(push)
#pragma warning(disable : 4996)
#endif
class ITable;
/**
* A listener that listens to changes in values in a {@link ITable}
*/
class WPI_DEPRECATED(
"Use EntryListener, TableEntryListener, or TableListener as appropriate")
ITableListener {
public:
virtual ~ITableListener() = default;
/**
* Called when a key-value pair is changed in a {@link ITable}
* @param source the table the key-value pair exists in
* @param key the key associated with the value that changed
* @param value the new value
* @param isNew true if the key did not previously exist in the table,
* otherwise it is false
*/
virtual void ValueChanged(ITable* source, wpi::StringRef key,
std::shared_ptr<nt::Value> value, bool isNew) = 0;
/**
* Extended version of ValueChanged. Called when a key-value pair is
* changed in a {@link ITable}. The default implementation simply calls
* ValueChanged(). If this is overridden, ValueChanged() will not be called.
* @param source the table the key-value pair exists in
* @param key the key associated with the value that changed
* @param value the new value
* @param flags update flags; for example, NT_NOTIFY_NEW if the key did not
* previously exist in the table
*/
virtual void ValueChangedEx(ITable* source, wpi::StringRef key,
std::shared_ptr<nt::Value> value,
unsigned int flags);
};
#ifdef __GNUC__
#pragma GCC diagnostic pop
#elif _WIN32
#pragma warning(pop)
#endif
#endif // NTCORE_TABLES_ITABLELISTENER_H_