diff --git a/include/networktables/NetworkTable.h b/include/networktables/NetworkTable.h index dbf6081137..d2c7f8eda3 100644 --- a/include/networktables/NetworkTable.h +++ b/include/networktables/NetworkTable.h @@ -83,7 +83,7 @@ class NetworkTable : public ITable { * the key name * @return the networktable to be returned */ - std::shared_ptr GetSubTable(llvm::StringRef key); + std::shared_ptr GetSubTable(llvm::StringRef key) const; /** * Checks the table and tells if it contains the specified key @@ -91,9 +91,9 @@ class NetworkTable : public ITable { * @param key * the key to be checked */ - bool ContainsKey(llvm::StringRef key); + bool ContainsKey(llvm::StringRef key) const; - bool ContainsSubTable(llvm::StringRef key); + bool ContainsSubTable(llvm::StringRef key) const; /** * Maps the specified key to the specified value in this table. The key can @@ -117,7 +117,7 @@ class NetworkTable : public ITable { * the default value if the key is null * @return the key */ - double GetNumber(llvm::StringRef key, double defaultValue); + double GetNumber(llvm::StringRef key, double defaultValue) const; /** * Maps the specified key to the specified value in this table. The key can @@ -141,7 +141,8 @@ class NetworkTable : public ITable { * the default value if the key is null * @return the key */ - std::string GetString(llvm::StringRef key, llvm::StringRef defaultValue); + std::string GetString(llvm::StringRef key, + llvm::StringRef defaultValue) const; /** * Maps the specified key to the specified value in this table. The key can @@ -165,7 +166,7 @@ class NetworkTable : public ITable { * the default value if the key is null * @return the key */ - bool GetBoolean(llvm::StringRef key, bool defaultValue); + bool GetBoolean(llvm::StringRef key, bool defaultValue) const; /** * Maps the specified key to the specified value in this table. The key can @@ -186,7 +187,7 @@ class NetworkTable : public ITable { * the key name * @return the key, or nullptr if the key is not defined */ - std::shared_ptr GetValue(llvm::StringRef key); + std::shared_ptr GetValue(llvm::StringRef key) const; }; #endif diff --git a/include/tables/ITable.h b/include/tables/ITable.h index 754ff12c9a..d458d45ac4 100644 --- a/include/tables/ITable.h +++ b/include/tables/ITable.h @@ -23,7 +23,7 @@ class ITable { * @param key the key to search for * @return true if the table as a value assigned to the given key */ - virtual bool ContainsKey(llvm::StringRef key) = 0; + virtual bool ContainsKey(llvm::StringRef key) const = 0; /** * Determines whether there exists a non-empty subtable for this key @@ -33,7 +33,7 @@ class ITable { * @return true if there is a subtable with the key which contains at least * one key/subtable of its own */ - virtual bool ContainsSubTable(llvm::StringRef key) = 0; + virtual bool ContainsSubTable(llvm::StringRef key) const = 0; /** * Gets the subtable in this table for the given name. @@ -41,7 +41,7 @@ class ITable { * @param key the name of the table relative to this one * @return a sub table relative to this one */ - virtual std::shared_ptr GetSubTable(llvm::StringRef key) = 0; + virtual std::shared_ptr GetSubTable(llvm::StringRef key) const = 0; /** * Gets the value associated with a key as an object @@ -51,7 +51,7 @@ class ITable { * @throws TableKeyNotDefinedException if there is no value associated with * the given key */ - virtual std::shared_ptr GetValue(llvm::StringRef key) = 0; + virtual std::shared_ptr GetValue(llvm::StringRef key) const = 0; /** * Put a value in the table @@ -80,7 +80,7 @@ class ITable { * @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(llvm::StringRef key, double defaultValue) = 0; + virtual double GetNumber(llvm::StringRef key, double defaultValue) const = 0; /** * Put a string in the table @@ -99,7 +99,7 @@ class ITable { * if there is no value associated with the key */ virtual std::string GetString(llvm::StringRef key, - llvm::StringRef defaultValue) = 0; + llvm::StringRef defaultValue) const = 0; /** * Put a boolean in the table @@ -117,7 +117,7 @@ class ITable { * @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(llvm::StringRef key, bool defaultValue) = 0; + virtual bool GetBoolean(llvm::StringRef key, bool defaultValue) const = 0; /** * Add a listener for changes to the table diff --git a/src/networktables/NetworkTable.cpp b/src/networktables/NetworkTable.cpp index 2cf19bd222..24a49e77b0 100644 --- a/src/networktables/NetworkTable.cpp +++ b/src/networktables/NetworkTable.cpp @@ -99,21 +99,21 @@ void NetworkTable::RemoveTableListener(ITableListener* listener) { m_listeners.erase(matches_begin, m_listeners.end()); } -std::shared_ptr NetworkTable::GetSubTable(StringRef key) { +std::shared_ptr NetworkTable::GetSubTable(StringRef key) const { llvm::SmallString<128> path(m_path); path += PATH_SEPARATOR_CHAR; path += key; return std::make_shared(path, private_init()); } -bool NetworkTable::ContainsKey(StringRef key) { +bool NetworkTable::ContainsKey(StringRef key) const { llvm::SmallString<128> path(m_path); path += PATH_SEPARATOR_CHAR; path += key; return !nt::GetEntryValue(path); } -bool NetworkTable::ContainsSubTable(StringRef key) { +bool NetworkTable::ContainsSubTable(StringRef key) const { llvm::SmallString<128> path(m_path); path += PATH_SEPARATOR_CHAR; path += key; @@ -128,7 +128,7 @@ void NetworkTable::PutNumber(StringRef key, double value) { nt::SetEntryValue(path, nt::Value::MakeDouble(value)); } -double NetworkTable::GetNumber(StringRef key, double defaultValue) { +double NetworkTable::GetNumber(StringRef key, double defaultValue) const { llvm::SmallString<128> path(m_path); path += PATH_SEPARATOR_CHAR; path += key; @@ -145,7 +145,8 @@ void NetworkTable::PutString(StringRef key, StringRef value) { nt::SetEntryValue(path, nt::Value::MakeString(value)); } -std::string NetworkTable::GetString(StringRef key, StringRef defaultValue) { +std::string NetworkTable::GetString(StringRef key, + StringRef defaultValue) const { llvm::SmallString<128> path(m_path); path += PATH_SEPARATOR_CHAR; path += key; @@ -162,7 +163,7 @@ void NetworkTable::PutBoolean(StringRef key, bool value) { nt::SetEntryValue(path, nt::Value::MakeBoolean(value)); } -bool NetworkTable::GetBoolean(StringRef key, bool defaultValue) { +bool NetworkTable::GetBoolean(StringRef key, bool defaultValue) const { llvm::SmallString<128> path(m_path); path += PATH_SEPARATOR_CHAR; path += key; @@ -179,7 +180,7 @@ void NetworkTable::PutValue(StringRef key, std::shared_ptr value) { nt::SetEntryValue(path, value); } -std::shared_ptr NetworkTable::GetValue(StringRef key) { +std::shared_ptr NetworkTable::GetValue(StringRef key) const { llvm::SmallString<128> path(m_path); path += PATH_SEPARATOR_CHAR; path += key;