mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
Use Twine instead of StringRef where appropriate. (#259)
Deprecated interfaces were not updated.
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "llvm/ArrayRef.h"
|
||||
#include "llvm/StringMap.h"
|
||||
#include "llvm/Twine.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
#include "networktables/TableEntryListener.h"
|
||||
#include "networktables/TableListener.h"
|
||||
@@ -24,6 +25,7 @@ namespace nt {
|
||||
|
||||
using llvm::ArrayRef;
|
||||
using llvm::StringRef;
|
||||
using llvm::Twine;
|
||||
|
||||
class NetworkTableInstance;
|
||||
|
||||
@@ -79,9 +81,11 @@ class NetworkTable final : public ITable {
|
||||
* with a leading slash
|
||||
* @return normalized key
|
||||
*/
|
||||
static std::string NormalizeKey(StringRef key, bool withLeadingSlash = true);
|
||||
static std::string NormalizeKey(const Twine& key,
|
||||
bool withLeadingSlash = true);
|
||||
|
||||
static StringRef NormalizeKey(StringRef key, llvm::SmallVectorImpl<char>& buf,
|
||||
static StringRef NormalizeKey(const Twine& key,
|
||||
llvm::SmallVectorImpl<char>& buf,
|
||||
bool withLeadingSlash = true);
|
||||
|
||||
/**
|
||||
@@ -91,13 +95,13 @@ class NetworkTable final : public ITable {
|
||||
* @param key the key
|
||||
* @return List of super tables
|
||||
*/
|
||||
static std::vector<std::string> GetHierarchy(StringRef key);
|
||||
static std::vector<std::string> GetHierarchy(const Twine& key);
|
||||
|
||||
/**
|
||||
* Constructor. Use NetworkTableInstance::GetTable() or GetSubTable()
|
||||
* instead.
|
||||
*/
|
||||
NetworkTable(NT_Inst inst, StringRef path, const private_init&);
|
||||
NetworkTable(NT_Inst inst, const Twine& path, const private_init&);
|
||||
virtual ~NetworkTable();
|
||||
|
||||
/**
|
||||
@@ -273,7 +277,7 @@ class NetworkTable final : public ITable {
|
||||
* @param key the key name
|
||||
* @return Network table entry.
|
||||
*/
|
||||
NetworkTableEntry GetEntry(StringRef key) const;
|
||||
NetworkTableEntry GetEntry(const Twine& key) const;
|
||||
|
||||
/**
|
||||
* Listen to keys only within this table.
|
||||
@@ -291,7 +295,8 @@ class NetworkTable final : public ITable {
|
||||
* @param flags EntryListenerFlags bitmask
|
||||
* @return Listener handle
|
||||
*/
|
||||
NT_EntryListener AddEntryListener(StringRef key, TableEntryListener listener,
|
||||
NT_EntryListener AddEntryListener(const Twine& key,
|
||||
TableEntryListener listener,
|
||||
unsigned int flags) const;
|
||||
|
||||
/**
|
||||
@@ -356,7 +361,7 @@ class NetworkTable final : public ITable {
|
||||
* @param key the key name
|
||||
* @return the networktable to be returned
|
||||
*/
|
||||
std::shared_ptr<NetworkTable> GetSubTable(StringRef key) const override;
|
||||
std::shared_ptr<NetworkTable> GetSubTable(const Twine& key) const override;
|
||||
|
||||
/**
|
||||
* Determines whether the given key is in this table.
|
||||
@@ -364,7 +369,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(StringRef key) const override;
|
||||
bool ContainsKey(const Twine& key) const override;
|
||||
|
||||
/**
|
||||
* Determines whether there exists a non-empty subtable for this key
|
||||
@@ -374,7 +379,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(StringRef key) const override;
|
||||
bool ContainsSubTable(const Twine& key) const override;
|
||||
|
||||
/**
|
||||
* Gets all keys in the table (not including sub-tables).
|
||||
@@ -443,7 +448,7 @@ class NetworkTable final : public ITable {
|
||||
*
|
||||
* @param key the key name
|
||||
*/
|
||||
void Delete(StringRef key) override;
|
||||
void Delete(const Twine& key) override;
|
||||
|
||||
/**
|
||||
* Put a number in the table
|
||||
@@ -665,7 +670,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(StringRef key, std::shared_ptr<Value> value) override;
|
||||
bool PutValue(const Twine& key, std::shared_ptr<Value> value) override;
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -673,7 +678,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 SetDefaultValue(StringRef key,
|
||||
bool SetDefaultValue(const Twine& key,
|
||||
std::shared_ptr<Value> defaultValue) override;
|
||||
|
||||
/**
|
||||
@@ -683,7 +688,7 @@ 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(StringRef key) const override;
|
||||
std::shared_ptr<Value> GetValue(const Twine& key) const override;
|
||||
|
||||
/**
|
||||
* Gets the full path of this table. Does not include the trailing "/".
|
||||
@@ -697,7 +702,7 @@ class NetworkTable final : public ITable {
|
||||
* @param filename filename
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* SaveEntries(StringRef filename) const;
|
||||
const char* SaveEntries(const Twine& filename) const;
|
||||
|
||||
/**
|
||||
* Load table values from a file. The file format used is identical to
|
||||
@@ -707,7 +712,7 @@ class NetworkTable final : public ITable {
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* LoadEntries(
|
||||
StringRef filename,
|
||||
const Twine& filename,
|
||||
std::function<void(size_t line, const char* msg)> warn);
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "llvm/StringRef.h"
|
||||
#include "llvm/Twine.h"
|
||||
|
||||
#include "networktables/NetworkTableType.h"
|
||||
#include "networktables/NetworkTableValue.h"
|
||||
@@ -23,6 +24,7 @@ namespace nt {
|
||||
|
||||
using llvm::ArrayRef;
|
||||
using llvm::StringRef;
|
||||
using llvm::Twine;
|
||||
|
||||
class NetworkTableInstance;
|
||||
|
||||
@@ -206,7 +208,7 @@ class NetworkTableEntry final {
|
||||
* @param defaultValue the default value to set
|
||||
* @return False if the entry exists with a different type
|
||||
*/
|
||||
bool SetDefaultString(StringRef defaultValue);
|
||||
bool SetDefaultString(const Twine& defaultValue);
|
||||
|
||||
/**
|
||||
* Sets the entry's value if it does not exist.
|
||||
@@ -262,7 +264,7 @@ class NetworkTableEntry final {
|
||||
* @param value the value to set
|
||||
* @return False if the entry exists with a different type
|
||||
*/
|
||||
bool SetString(StringRef value);
|
||||
bool SetString(const Twine& value);
|
||||
|
||||
/**
|
||||
* Sets the entry's value.
|
||||
@@ -318,7 +320,7 @@ class NetworkTableEntry final {
|
||||
* changed to match the new value.
|
||||
* @param value the value to set
|
||||
*/
|
||||
void ForceSetString(StringRef value);
|
||||
void ForceSetString(const Twine& value);
|
||||
|
||||
/**
|
||||
* Sets the entry's value. If the value is of different type, the type is
|
||||
|
||||
@@ -102,7 +102,7 @@ inline bool NetworkTableEntry::SetDefaultDouble(double defaultValue) {
|
||||
return SetDefaultEntryValue(m_handle, Value::MakeDouble(defaultValue));
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetDefaultString(StringRef defaultValue) {
|
||||
inline bool NetworkTableEntry::SetDefaultString(const Twine& defaultValue) {
|
||||
return SetDefaultEntryValue(m_handle, Value::MakeString(defaultValue));
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ inline bool NetworkTableEntry::SetDouble(double value) {
|
||||
return SetEntryValue(m_handle, Value::MakeDouble(value));
|
||||
}
|
||||
|
||||
inline bool NetworkTableEntry::SetString(StringRef value) {
|
||||
inline bool NetworkTableEntry::SetString(const Twine& value) {
|
||||
return SetEntryValue(m_handle, Value::MakeString(value));
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ inline void NetworkTableEntry::ForceSetDouble(double value) {
|
||||
SetEntryTypeValue(m_handle, Value::MakeDouble(value));
|
||||
}
|
||||
|
||||
inline void NetworkTableEntry::ForceSetString(StringRef value) {
|
||||
inline void NetworkTableEntry::ForceSetString(const Twine& value) {
|
||||
SetEntryTypeValue(m_handle, Value::MakeString(value));
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "llvm/ArrayRef.h"
|
||||
#include "llvm/StringRef.h"
|
||||
#include "llvm/Twine.h"
|
||||
|
||||
#include "networktables/NetworkTable.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
@@ -37,6 +38,7 @@ namespace nt {
|
||||
|
||||
using llvm::ArrayRef;
|
||||
using llvm::StringRef;
|
||||
using llvm::Twine;
|
||||
|
||||
/** NetworkTables Instance.
|
||||
*
|
||||
@@ -136,7 +138,7 @@ class NetworkTableInstance final {
|
||||
* @param name Key
|
||||
* @return Network table entry.
|
||||
*/
|
||||
NetworkTableEntry GetEntry(StringRef name);
|
||||
NetworkTableEntry GetEntry(const Twine& name);
|
||||
|
||||
/**
|
||||
* Get entries starting with the given prefix.
|
||||
@@ -148,7 +150,7 @@ class NetworkTableInstance final {
|
||||
* @param types bitmask of types; 0 is treated as a "don't care"
|
||||
* @return Array of entries.
|
||||
*/
|
||||
std::vector<NetworkTableEntry> GetEntries(StringRef prefix,
|
||||
std::vector<NetworkTableEntry> GetEntries(const Twine& prefix,
|
||||
unsigned int types);
|
||||
|
||||
/**
|
||||
@@ -161,7 +163,7 @@ class NetworkTableInstance final {
|
||||
* @param types bitmask of types; 0 is treated as a "don't care"
|
||||
* @return Array of entry information.
|
||||
*/
|
||||
std::vector<EntryInfo> GetEntryInfo(StringRef prefix,
|
||||
std::vector<EntryInfo> GetEntryInfo(const Twine& prefix,
|
||||
unsigned int types) const;
|
||||
|
||||
/**
|
||||
@@ -170,7 +172,7 @@ class NetworkTableInstance final {
|
||||
* @param key the key name
|
||||
* @return The network table
|
||||
*/
|
||||
std::shared_ptr<NetworkTable> GetTable(StringRef key) const;
|
||||
std::shared_ptr<NetworkTable> GetTable(const Twine& key) const;
|
||||
|
||||
/**
|
||||
* Deletes ALL keys in ALL subtables (except persistent values).
|
||||
@@ -192,7 +194,7 @@ class NetworkTableInstance final {
|
||||
* @return Listener handle
|
||||
*/
|
||||
NT_EntryListener AddEntryListener(
|
||||
StringRef prefix,
|
||||
const Twine& prefix,
|
||||
std::function<void(const EntryNotification& event)> callback,
|
||||
unsigned int flags) const;
|
||||
|
||||
@@ -279,7 +281,7 @@ class NetworkTableInstance final {
|
||||
* visible through ConnectionInfo on the remote node.
|
||||
* @param name identity to advertise
|
||||
*/
|
||||
void SetNetworkIdentity(StringRef name);
|
||||
void SetNetworkIdentity(const Twine& name);
|
||||
|
||||
/**
|
||||
* Get the current network mode.
|
||||
@@ -296,7 +298,7 @@ class NetworkTableInstance final {
|
||||
* address (UTF-8 string, null terminated)
|
||||
* @param port port to communicate over
|
||||
*/
|
||||
void StartServer(StringRef persist_filename = "networktables.ini",
|
||||
void StartServer(const Twine& persist_filename = "networktables.ini",
|
||||
const char* listen_address = "",
|
||||
unsigned int port = kDefaultPort);
|
||||
|
||||
@@ -441,7 +443,7 @@ class NetworkTableInstance final {
|
||||
* @param filename filename
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* SavePersistent(StringRef filename) const;
|
||||
const char* SavePersistent(const Twine& filename) const;
|
||||
|
||||
/**
|
||||
* Load persistent values from a file. The server automatically does this
|
||||
@@ -452,7 +454,7 @@ class NetworkTableInstance final {
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* LoadPersistent(
|
||||
StringRef filename,
|
||||
const Twine& filename,
|
||||
std::function<void(size_t line, const char* msg)> warn);
|
||||
|
||||
/**
|
||||
@@ -462,7 +464,7 @@ class NetworkTableInstance final {
|
||||
* @param prefix save only keys starting with this prefix
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* SaveEntries(StringRef filename, StringRef prefix) const;
|
||||
const char* SaveEntries(const Twine& filename, const Twine& prefix) const;
|
||||
|
||||
/**
|
||||
* Load table values from a file. The file format used is identical to
|
||||
@@ -473,7 +475,7 @@ class NetworkTableInstance final {
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* LoadEntries(
|
||||
StringRef filename, StringRef prefix,
|
||||
const Twine& filename, const Twine& prefix,
|
||||
std::function<void(size_t line, const char* msg)> warn);
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -29,12 +29,12 @@ inline void NetworkTableInstance::Destroy(NetworkTableInstance inst) {
|
||||
|
||||
inline NT_Inst NetworkTableInstance::GetHandle() const { return m_handle; }
|
||||
|
||||
inline NetworkTableEntry NetworkTableInstance::GetEntry(StringRef name) {
|
||||
inline NetworkTableEntry NetworkTableInstance::GetEntry(const Twine& name) {
|
||||
return NetworkTableEntry{::nt::GetEntry(m_handle, name)};
|
||||
}
|
||||
|
||||
inline std::vector<NetworkTableEntry> NetworkTableInstance::GetEntries(
|
||||
StringRef prefix, unsigned int types) {
|
||||
const Twine& prefix, unsigned int types) {
|
||||
std::vector<NetworkTableEntry> entries;
|
||||
for (auto entry : ::nt::GetEntries(m_handle, prefix, types))
|
||||
entries.emplace_back(entry);
|
||||
@@ -42,7 +42,7 @@ inline std::vector<NetworkTableEntry> NetworkTableInstance::GetEntries(
|
||||
}
|
||||
|
||||
inline std::vector<EntryInfo> NetworkTableInstance::GetEntryInfo(
|
||||
StringRef prefix, unsigned int types) const {
|
||||
const Twine& prefix, unsigned int types) const {
|
||||
return ::nt::GetEntryInfo(m_handle, prefix, types);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ inline bool NetworkTableInstance::WaitForRpcCallQueue(double timeout) {
|
||||
return ::nt::WaitForRpcCallQueue(m_handle, timeout);
|
||||
}
|
||||
|
||||
inline void NetworkTableInstance::SetNetworkIdentity(StringRef name) {
|
||||
inline void NetworkTableInstance::SetNetworkIdentity(const Twine& name) {
|
||||
::nt::SetNetworkIdentity(m_handle, name);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ inline unsigned int NetworkTableInstance::GetNetworkMode() const {
|
||||
return ::nt::GetNetworkMode(m_handle);
|
||||
}
|
||||
|
||||
inline void NetworkTableInstance::StartServer(StringRef persist_filename,
|
||||
inline void NetworkTableInstance::StartServer(const Twine& persist_filename,
|
||||
const char* listen_address,
|
||||
unsigned int port) {
|
||||
::nt::StartServer(m_handle, persist_filename, listen_address, port);
|
||||
@@ -147,23 +147,23 @@ inline bool NetworkTableInstance::IsConnected() const {
|
||||
}
|
||||
|
||||
inline const char* NetworkTableInstance::SavePersistent(
|
||||
StringRef filename) const {
|
||||
const Twine& filename) const {
|
||||
return ::nt::SavePersistent(m_handle, filename);
|
||||
}
|
||||
|
||||
inline const char* NetworkTableInstance::LoadPersistent(
|
||||
StringRef filename,
|
||||
const Twine& filename,
|
||||
std::function<void(size_t line, const char* msg)> warn) {
|
||||
return ::nt::LoadPersistent(m_handle, filename, warn);
|
||||
}
|
||||
|
||||
inline const char* NetworkTableInstance::SaveEntries(
|
||||
StringRef filename, StringRef prefix) const {
|
||||
const Twine& filename, const Twine& prefix) const {
|
||||
return ::nt::SaveEntries(m_handle, filename, prefix);
|
||||
}
|
||||
|
||||
inline const char* NetworkTableInstance::LoadEntries(
|
||||
StringRef filename, StringRef prefix,
|
||||
const Twine& filename, const Twine& prefix,
|
||||
std::function<void(size_t line, const char* msg)> warn) {
|
||||
return ::nt::LoadEntries(m_handle, filename, prefix, warn);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "llvm/ArrayRef.h"
|
||||
#include "llvm/StringRef.h"
|
||||
#include "llvm/Twine.h"
|
||||
|
||||
#include "ntcore_c.h"
|
||||
|
||||
@@ -23,6 +24,7 @@ namespace nt {
|
||||
|
||||
using llvm::ArrayRef;
|
||||
using llvm::StringRef;
|
||||
using llvm::Twine;
|
||||
|
||||
/**
|
||||
* A network table entry value.
|
||||
@@ -241,10 +243,10 @@ class Value final {
|
||||
* time)
|
||||
* @return The entry value
|
||||
*/
|
||||
static std::shared_ptr<Value> MakeString(StringRef value,
|
||||
static std::shared_ptr<Value> MakeString(const Twine& value,
|
||||
unsigned long long time = 0) {
|
||||
auto val = std::make_shared<Value>(NT_STRING, time, private_init());
|
||||
val->m_string = value;
|
||||
val->m_string = value.str();
|
||||
val->m_val.data.v_string.str = const_cast<char*>(val->m_string.c_str());
|
||||
val->m_val.data.v_string.len = val->m_string.size();
|
||||
return val;
|
||||
|
||||
Reference in New Issue
Block a user