diff --git a/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp b/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp index f4a9bd52ac..5178b2ad4b 100644 --- a/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp +++ b/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp @@ -12,23 +12,9 @@ #include "networktables/NetworkTableInstance.h" #include "ntcore.h" -#include "tables/ITableListener.h" using namespace nt; -#ifdef __GNUC__ -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#elif _WIN32 -#pragma warning(disable : 4996) -#endif - -const char NetworkTable::PATH_SEPARATOR_CHAR = '/'; -std::string NetworkTable::s_persistent_filename = "networktables.ini"; -bool NetworkTable::s_client = false; -bool NetworkTable::s_enable_ds = true; -bool NetworkTable::s_running = false; -unsigned int NetworkTable::s_port = NT_DEFAULT_PORT; - StringRef NetworkTable::BasenameKey(StringRef key) { size_t slash = key.rfind(PATH_SEPARATOR_CHAR); if (slash == StringRef::npos) { @@ -90,141 +76,11 @@ std::vector NetworkTable::GetHierarchy(const Twine& key) { return hierarchy; } -void NetworkTable::Initialize() { - if (s_running) { - Shutdown(); - } - auto inst = NetworkTableInstance::GetDefault(); - if (s_client) { - inst.StartClient(); - if (s_enable_ds) { - inst.StartDSClient(s_port); - } - } else { - inst.StartServer(s_persistent_filename, "", s_port); - } - s_running = true; -} - -void NetworkTable::Shutdown() { - if (!s_running) { - return; - } - auto inst = NetworkTableInstance::GetDefault(); - if (s_client) { - inst.StopDSClient(); - inst.StopClient(); - } else { - inst.StopServer(); - } - s_running = false; -} - -void NetworkTable::SetClientMode() { - s_client = true; -} - -void NetworkTable::SetServerMode() { - s_client = false; -} - -void NetworkTable::SetTeam(int team) { - auto inst = NetworkTableInstance::GetDefault(); - inst.SetServerTeam(team, s_port); - if (s_enable_ds) { - inst.StartDSClient(s_port); - } -} - -void NetworkTable::SetIPAddress(StringRef address) { - auto inst = NetworkTableInstance::GetDefault(); - wpi::SmallString<32> addr_copy{address}; - inst.SetServer(addr_copy.c_str(), s_port); - - // Stop the DS client if we're explicitly connecting to localhost - if (address == "localhost" || address == "127.0.0.1") { - inst.StopDSClient(); - } else if (s_enable_ds) { - inst.StartDSClient(s_port); - } -} - -void NetworkTable::SetIPAddress(ArrayRef addresses) { - auto inst = NetworkTableInstance::GetDefault(); - wpi::SmallVector servers; - for (const auto& ip_address : addresses) { - servers.emplace_back(ip_address); - } - inst.SetServer(servers, s_port); - - // Stop the DS client if we're explicitly connecting to localhost - if (!addresses.empty() && - (addresses[0] == "localhost" || addresses[0] == "127.0.0.1")) { - inst.StopDSClient(); - } else if (s_enable_ds) { - inst.StartDSClient(s_port); - } -} - -void NetworkTable::SetPort(unsigned int port) { - s_port = port; -} - -void NetworkTable::SetDSClientEnabled(bool enabled) { - auto inst = NetworkTableInstance::GetDefault(); - s_enable_ds = enabled; - if (s_enable_ds) { - inst.StartDSClient(s_port); - } else { - inst.StopDSClient(); - } -} - -void NetworkTable::SetPersistentFilename(StringRef filename) { - s_persistent_filename = filename; -} - -void NetworkTable::SetNetworkIdentity(StringRef name) { - NetworkTableInstance::GetDefault().SetNetworkIdentity(name); -} - -void NetworkTable::GlobalDeleteAll() { - NetworkTableInstance::GetDefault().DeleteAllEntries(); -} - -void NetworkTable::Flush() { - NetworkTableInstance::GetDefault().Flush(); -} - -void NetworkTable::SetUpdateRate(double interval) { - NetworkTableInstance::GetDefault().SetUpdateRate(interval); -} - -const char* NetworkTable::SavePersistent(StringRef filename) { - return NetworkTableInstance::GetDefault().SavePersistent(filename); -} - -const char* NetworkTable::LoadPersistent( - StringRef filename, - std::function warn) { - return NetworkTableInstance::GetDefault().LoadPersistent(filename, warn); -} - -std::shared_ptr NetworkTable::GetTable(StringRef key) { - if (!s_running) { - Initialize(); - } - return NetworkTableInstance::GetDefault().GetTable(key); -} - NetworkTable::NetworkTable(NT_Inst inst, const Twine& path, const private_init&) : m_inst(inst), m_path(path.str()) {} NetworkTable::~NetworkTable() { - for (auto& i : m_listeners) { - RemoveEntryListener(i.second); - } - for (auto i : m_lambdaListeners) { + for (auto i : m_listeners) { RemoveEntryListener(i); } } @@ -278,66 +134,6 @@ void NetworkTable::RemoveEntryListener(NT_EntryListener listener) const { nt::RemoveEntryListener(listener); } -void NetworkTable::AddTableListener(ITableListener* listener) { - AddTableListenerEx(listener, NT_NOTIFY_NEW | NT_NOTIFY_UPDATE); -} - -void NetworkTable::AddTableListener(ITableListener* listener, - bool immediateNotify) { - unsigned int flags = NT_NOTIFY_NEW | NT_NOTIFY_UPDATE; - if (immediateNotify) { - flags |= NT_NOTIFY_IMMEDIATE; - } - AddTableListenerEx(listener, flags); -} - -void NetworkTable::AddTableListenerEx(ITableListener* listener, - unsigned int flags) { - std::scoped_lock lock(m_mutex); - wpi::SmallString<128> path(m_path); - path += PATH_SEPARATOR_CHAR; - size_t prefix_len = path.size(); - NT_EntryListener id = nt::AddEntryListener( - m_inst, path, - [=](const EntryNotification& event) { - StringRef relative_key = event.name.substr(prefix_len); - if (relative_key.find(PATH_SEPARATOR_CHAR) != StringRef::npos) { - return; - } - listener->ValueChangedEx(this, relative_key, event.value, event.flags); - }, - flags); - m_listeners.emplace_back(listener, id); -} - -void NetworkTable::AddTableListener(StringRef key, ITableListener* listener, - bool immediateNotify) { - unsigned int flags = NT_NOTIFY_NEW | NT_NOTIFY_UPDATE; - if (immediateNotify) { - flags |= NT_NOTIFY_IMMEDIATE; - } - AddTableListenerEx(key, listener, flags); -} - -void NetworkTable::AddTableListenerEx(StringRef key, ITableListener* listener, - unsigned int flags) { - std::scoped_lock lock(m_mutex); - size_t prefix_len = m_path.size() + 1; - auto entry = GetEntry(key); - NT_EntryListener id = nt::AddEntryListener( - entry.GetHandle(), - [=](const EntryNotification& event) { - listener->ValueChangedEx(this, event.name.substr(prefix_len), - event.value, event.flags); - }, - flags); - m_listeners.emplace_back(listener, id); -} - -void NetworkTable::AddSubTableListener(ITableListener* listener) { - AddSubTableListener(listener, false); -} - NT_EntryListener NetworkTable::AddSubTableListener(TableListener listener, bool localNotify) { size_t prefix_len = m_path.size() + 1; @@ -366,58 +162,14 @@ NT_EntryListener NetworkTable::AddSubTableListener(TableListener listener, listener(this, sub_table_key, this->GetSubTable(sub_table_key)); }, flags); - m_lambdaListeners.emplace_back(id); + m_listeners.emplace_back(id); return id; } void NetworkTable::RemoveTableListener(NT_EntryListener listener) { nt::RemoveEntryListener(listener); auto matches_begin = - std::remove(m_lambdaListeners.begin(), m_lambdaListeners.end(), listener); - m_lambdaListeners.erase(matches_begin, m_lambdaListeners.end()); -} - -void NetworkTable::AddSubTableListener(ITableListener* listener, - bool localNotify) { - std::scoped_lock lock(m_mutex); - size_t prefix_len = m_path.size() + 1; - - // The lambda needs to be copyable, but StringMap is not, so use - // a shared_ptr to it. - auto notified_tables = std::make_shared>(); - - unsigned int flags = NT_NOTIFY_NEW | NT_NOTIFY_IMMEDIATE; - if (localNotify) { - flags |= NT_NOTIFY_LOCAL; - } - NT_EntryListener id = nt::AddEntryListener( - m_inst, m_path + Twine(PATH_SEPARATOR_CHAR), - [=](const EntryNotification& event) { - StringRef relative_key = event.name.substr(prefix_len); - auto end_sub_table = relative_key.find(PATH_SEPARATOR_CHAR); - if (end_sub_table == StringRef::npos) { - return; - } - StringRef sub_table_key = relative_key.substr(0, end_sub_table); - if (notified_tables->find(sub_table_key) == notified_tables->end()) { - return; - } - notified_tables->insert(std::make_pair(sub_table_key, '\0')); - listener->ValueChangedEx(this, sub_table_key, nullptr, event.flags); - }, - flags); - m_listeners.emplace_back(listener, id); -} - -void NetworkTable::RemoveTableListener(ITableListener* listener) { - std::scoped_lock lock(m_mutex); - auto matches_begin = - std::remove_if(m_listeners.begin(), m_listeners.end(), - [=](const Listener& x) { return x.first == listener; }); - - for (auto i = matches_begin; i != m_listeners.end(); ++i) { - RemoveEntryListener(i->second); - } + std::remove(m_listeners.begin(), m_listeners.end(), listener); m_listeners.erase(matches_begin, m_listeners.end()); } diff --git a/ntcore/src/main/native/cpp/tables/ITableListener.cpp b/ntcore/src/main/native/cpp/tables/ITableListener.cpp deleted file mode 100644 index a6dd569b5c..0000000000 --- a/ntcore/src/main/native/cpp/tables/ITableListener.cpp +++ /dev/null @@ -1,13 +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. - -#include "tables/ITableListener.h" - -#include "ntcore_c.h" - -void ITableListener::ValueChangedEx(ITable* source, wpi::StringRef key, - std::shared_ptr value, - unsigned int flags) { - ValueChanged(source, key, value, (flags & NT_NOTIFY_NEW) != 0); -} diff --git a/ntcore/src/main/native/include/networktables/NetworkTable.h b/ntcore/src/main/native/include/networktables/NetworkTable.h index 91d1aa28aa..3c32d7d1f3 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTable.h +++ b/ntcore/src/main/native/include/networktables/NetworkTable.h @@ -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 m_entries; - typedef std::pair Listener; - std::vector m_listeners; - std::vector m_lambdaListeners; - - static std::vector 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 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 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 warn); - - /** - * 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. - * - * @param key the key name - * @return the network table requested - */ - WPI_DEPRECATED( - "use NetworkTableInstance::GetTable() or " - "NetworkTableInstance::GetEntry() instead") - static std::shared_ptr 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 GetSubTable(const Twine& key) const override; + std::shared_ptr 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 GetKeys(int types = 0) const override; + std::vector GetKeys(int types = 0) const; /** * Gets the names of all subtables in the table. * * @return subtables currently in the table */ - std::vector GetSubTables() const override; + std::vector 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 is special-cased in C++. 0 is false, any * non-zero value is true. */ - bool PutBooleanArray(StringRef key, ArrayRef value) override; + bool PutBooleanArray(StringRef key, ArrayRef 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 defaultValue) override; + bool SetDefaultBooleanArray(StringRef key, ArrayRef 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 GetBooleanArray(StringRef key, - ArrayRef defaultValue) const override; + ArrayRef 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 value) override; + bool PutNumberArray(StringRef key, ArrayRef 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 defaultValue) override; + bool SetDefaultNumberArray(StringRef key, ArrayRef 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 GetNumberArray( - StringRef key, ArrayRef defaultValue) const override; + std::vector GetNumberArray(StringRef key, + ArrayRef 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 value) override; + bool PutStringArray(StringRef key, ArrayRef 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 defaultValue) override; + bool SetDefaultStringArray(StringRef key, ArrayRef 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 GetStringArray( - StringRef key, ArrayRef defaultValue) const override; + StringRef key, ArrayRef 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) override; + bool PutValue(const Twine& key, std::shared_ptr 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 defaultValue) override; + bool SetDefaultValue(const Twine& key, std::shared_ptr 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 GetValue(const Twine& key) const override; + std::shared_ptr 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 warn); }; -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#elif _WIN32 -#pragma warning(pop) -#endif - } // namespace nt // For backwards compatibility diff --git a/ntcore/src/main/native/include/tables/ITable.h b/ntcore/src/main/native/include/tables/ITable.h deleted file mode 100644 index 5cd365cb76..0000000000 --- a/ntcore/src/main/native/include/tables/ITable.h +++ /dev/null @@ -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 -#include -#include - -#include -#include -#include - -#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 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 GetKeys(int types = 0) const = 0; - - /** - * @return subtables currently in the table - */ - virtual std::vector 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 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 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 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 is special-cased in C++. 0 is false, any - * non-zero value is true. - */ - virtual bool PutBooleanArray(wpi::StringRef key, - wpi::ArrayRef 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 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 instead of std::vector - * because std::vector is special-cased in C++. 0 is false, any - * non-zero value is true. - */ - virtual std::vector GetBooleanArray( - wpi::StringRef key, wpi::ArrayRef 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 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 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 GetNumberArray( - wpi::StringRef key, wpi::ArrayRef 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 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 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 GetStringArray( - wpi::StringRef key, wpi::ArrayRef 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_ diff --git a/ntcore/src/main/native/include/tables/ITableListener.h b/ntcore/src/main/native/include/tables/ITableListener.h deleted file mode 100644 index 29a693adf3..0000000000 --- a/ntcore/src/main/native/include/tables/ITableListener.h +++ /dev/null @@ -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 - -#include -#include - -#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 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 value, - unsigned int flags); -}; - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#elif _WIN32 -#pragma warning(pop) -#endif - -#endif // NTCORE_TABLES_ITABLELISTENER_H_