mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Use Twine instead of StringRef where appropriate. (#259)
Deprecated interfaces were not updated.
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
|
||||
using namespace nt;
|
||||
|
||||
void Dispatcher::StartServer(llvm::StringRef persist_filename,
|
||||
void Dispatcher::StartServer(const Twine& persist_filename,
|
||||
const char* listen_address, unsigned int port) {
|
||||
DispatcherBase::StartServer(
|
||||
persist_filename,
|
||||
@@ -115,7 +115,7 @@ DispatcherBase::~DispatcherBase() { Stop(); }
|
||||
unsigned int DispatcherBase::GetNetworkMode() const { return m_networkMode; }
|
||||
|
||||
void DispatcherBase::StartServer(
|
||||
StringRef persist_filename,
|
||||
const Twine& persist_filename,
|
||||
std::unique_ptr<wpi::NetworkAcceptor> acceptor) {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_user_mutex);
|
||||
@@ -123,11 +123,13 @@ void DispatcherBase::StartServer(
|
||||
m_active = true;
|
||||
}
|
||||
m_networkMode = NT_NET_MODE_SERVER | NT_NET_MODE_STARTING;
|
||||
m_persist_filename = persist_filename;
|
||||
m_persist_filename = persist_filename.str();
|
||||
m_server_acceptor = std::move(acceptor);
|
||||
|
||||
// Load persistent file. Ignore errors, but pass along warnings.
|
||||
if (!persist_filename.empty()) {
|
||||
if (!persist_filename.isTriviallyEmpty() &&
|
||||
(!persist_filename.isSingleStringRef() ||
|
||||
!persist_filename.getSingleStringRef().empty())) {
|
||||
bool first = true;
|
||||
m_storage.LoadPersistent(
|
||||
persist_filename, [&](std::size_t line, const char* msg) {
|
||||
@@ -198,9 +200,9 @@ void DispatcherBase::SetUpdateRate(double interval) {
|
||||
m_update_rate = static_cast<unsigned int>(interval * 1000);
|
||||
}
|
||||
|
||||
void DispatcherBase::SetIdentity(llvm::StringRef name) {
|
||||
void DispatcherBase::SetIdentity(const Twine& name) {
|
||||
std::lock_guard<wpi::mutex> lock(m_user_mutex);
|
||||
m_identity = name;
|
||||
m_identity = name.str();
|
||||
}
|
||||
|
||||
void DispatcherBase::Flush() {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "llvm/StringRef.h"
|
||||
#include "llvm/Twine.h"
|
||||
#include "support/condition_variable.h"
|
||||
#include "support/mutex.h"
|
||||
|
||||
@@ -46,12 +47,12 @@ class DispatcherBase : public IDispatcher {
|
||||
virtual ~DispatcherBase();
|
||||
|
||||
unsigned int GetNetworkMode() const;
|
||||
void StartServer(llvm::StringRef persist_filename,
|
||||
void StartServer(const Twine& persist_filename,
|
||||
std::unique_ptr<wpi::NetworkAcceptor> acceptor);
|
||||
void StartClient();
|
||||
void Stop();
|
||||
void SetUpdateRate(double interval);
|
||||
void SetIdentity(llvm::StringRef name);
|
||||
void SetIdentity(const Twine& name);
|
||||
void Flush();
|
||||
std::vector<ConnectionInfo> GetConnections() const;
|
||||
bool IsConnected() const;
|
||||
@@ -133,7 +134,7 @@ class Dispatcher : public DispatcherBase {
|
||||
wpi::Logger& logger)
|
||||
: DispatcherBase(storage, notifier, logger) {}
|
||||
|
||||
void StartServer(StringRef persist_filename, const char* listen_address,
|
||||
void StartServer(const Twine& persist_filename, const char* listen_address,
|
||||
unsigned int port);
|
||||
|
||||
void SetServer(const char* server_name, unsigned int port);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "llvm/ArrayRef.h"
|
||||
#include "llvm/StringRef.h"
|
||||
#include "llvm/Twine.h"
|
||||
|
||||
#include "Message.h"
|
||||
#include "ntcore_cpp.h"
|
||||
@@ -53,10 +53,10 @@ class IStorage {
|
||||
|
||||
// Filename-based save/load functions. Used both by periodic saves and
|
||||
// accessible directly via the user API.
|
||||
virtual const char* SavePersistent(StringRef filename,
|
||||
virtual const char* SavePersistent(const Twine& filename,
|
||||
bool periodic) const = 0;
|
||||
virtual const char* LoadPersistent(
|
||||
StringRef filename,
|
||||
const Twine& filename,
|
||||
std::function<void(std::size_t line, const char* msg)> warn) = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -757,30 +757,36 @@ void Storage::DeleteAllEntries() {
|
||||
dispatcher->QueueOutgoing(Message::ClearEntries(), nullptr, nullptr);
|
||||
}
|
||||
|
||||
Storage::Entry* Storage::GetOrNew(StringRef name) {
|
||||
auto& entry = m_entries[name];
|
||||
Storage::Entry* Storage::GetOrNew(const Twine& name) {
|
||||
llvm::SmallString<128> nameBuf;
|
||||
StringRef nameStr = name.toStringRef(nameBuf);
|
||||
auto& entry = m_entries[nameStr];
|
||||
if (!entry) {
|
||||
m_localmap.emplace_back(new Entry(name));
|
||||
m_localmap.emplace_back(new Entry(nameStr));
|
||||
entry = m_localmap.back().get();
|
||||
entry->local_id = m_localmap.size() - 1;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
unsigned int Storage::GetEntry(StringRef name) {
|
||||
if (name.empty()) return UINT_MAX;
|
||||
unsigned int Storage::GetEntry(const Twine& name) {
|
||||
if (name.isTriviallyEmpty() ||
|
||||
(name.isSingleStringRef() && name.getSingleStringRef().empty()))
|
||||
return UINT_MAX;
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
return GetOrNew(name)->local_id;
|
||||
}
|
||||
|
||||
std::vector<unsigned int> Storage::GetEntries(StringRef prefix,
|
||||
std::vector<unsigned int> Storage::GetEntries(const Twine& prefix,
|
||||
unsigned int types) {
|
||||
llvm::SmallString<128> prefixBuf;
|
||||
StringRef prefixStr = prefix.toStringRef(prefixBuf);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::vector<unsigned int> ids;
|
||||
for (auto& i : m_entries) {
|
||||
Entry* entry = i.getValue();
|
||||
auto value = entry->value.get();
|
||||
if (!value || !i.getKey().startswith(prefix)) continue;
|
||||
if (!value || !i.getKey().startswith(prefixStr)) continue;
|
||||
if (types != 0 && (types & value->type()) == 0) continue;
|
||||
ids.push_back(entry->local_id);
|
||||
}
|
||||
@@ -829,14 +835,16 @@ unsigned long long Storage::GetEntryLastChange(unsigned int local_id) const {
|
||||
return entry->value->last_change();
|
||||
}
|
||||
|
||||
std::vector<EntryInfo> Storage::GetEntryInfo(int inst, StringRef prefix,
|
||||
std::vector<EntryInfo> Storage::GetEntryInfo(int inst, const Twine& prefix,
|
||||
unsigned int types) {
|
||||
llvm::SmallString<128> prefixBuf;
|
||||
StringRef prefixStr = prefix.toStringRef(prefixBuf);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::vector<EntryInfo> infos;
|
||||
for (auto& i : m_entries) {
|
||||
Entry* entry = i.getValue();
|
||||
auto value = entry->value.get();
|
||||
if (!value || !i.getKey().startswith(prefix)) continue;
|
||||
if (!value || !i.getKey().startswith(prefixStr)) continue;
|
||||
if (types != 0 && (types & value->type()) == 0) continue;
|
||||
EntryInfo info;
|
||||
info.entry = Handle(inst, entry->local_id, Handle::kEntry);
|
||||
@@ -850,16 +858,18 @@ std::vector<EntryInfo> Storage::GetEntryInfo(int inst, StringRef prefix,
|
||||
}
|
||||
|
||||
unsigned int Storage::AddListener(
|
||||
StringRef prefix,
|
||||
const Twine& prefix,
|
||||
std::function<void(const EntryNotification& event)> callback,
|
||||
unsigned int flags) const {
|
||||
llvm::SmallString<128> prefixBuf;
|
||||
StringRef prefixStr = prefix.toStringRef(prefixBuf);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
unsigned int uid = m_notifier.Add(callback, prefix, flags);
|
||||
unsigned int uid = m_notifier.Add(callback, prefixStr, flags);
|
||||
// perform immediate notifications
|
||||
if ((flags & NT_NOTIFY_IMMEDIATE) != 0 && (flags & NT_NOTIFY_NEW) != 0) {
|
||||
for (auto& i : m_entries) {
|
||||
Entry* entry = i.getValue();
|
||||
if (!entry->value || !i.getKey().startswith(prefix)) continue;
|
||||
if (!entry->value || !i.getKey().startswith(prefixStr)) continue;
|
||||
m_notifier.NotifyEntry(entry->local_id, i.getKey(), entry->value,
|
||||
NT_NOTIFY_IMMEDIATE | NT_NOTIFY_NEW, uid);
|
||||
}
|
||||
@@ -885,14 +895,17 @@ unsigned int Storage::AddListener(
|
||||
return uid;
|
||||
}
|
||||
|
||||
unsigned int Storage::AddPolledListener(unsigned int poller, StringRef prefix,
|
||||
unsigned int Storage::AddPolledListener(unsigned int poller,
|
||||
const Twine& prefix,
|
||||
unsigned int flags) const {
|
||||
llvm::SmallString<128> prefixBuf;
|
||||
StringRef prefixStr = prefix.toStringRef(prefixBuf);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
unsigned int uid = m_notifier.AddPolled(poller, prefix, flags);
|
||||
unsigned int uid = m_notifier.AddPolled(poller, prefixStr, flags);
|
||||
// perform immediate notifications
|
||||
if ((flags & NT_NOTIFY_IMMEDIATE) != 0 && (flags & NT_NOTIFY_NEW) != 0) {
|
||||
for (auto& i : m_entries) {
|
||||
if (!i.getKey().startswith(prefix)) continue;
|
||||
if (!i.getKey().startswith(prefixStr)) continue;
|
||||
Entry* entry = i.getValue();
|
||||
if (!entry->value) continue;
|
||||
m_notifier.NotifyEntry(entry->local_id, i.getKey(), entry->value,
|
||||
@@ -949,9 +962,11 @@ bool Storage::GetPersistentEntries(
|
||||
}
|
||||
|
||||
bool Storage::GetEntries(
|
||||
StringRef prefix,
|
||||
const Twine& prefix,
|
||||
std::vector<std::pair<std::string, std::shared_ptr<Value>>>* entries)
|
||||
const {
|
||||
llvm::SmallString<128> prefixBuf;
|
||||
StringRef prefixStr = prefix.toStringRef(prefixBuf);
|
||||
// copy values out of storage as quickly as possible so lock isn't held
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
@@ -959,7 +974,7 @@ bool Storage::GetEntries(
|
||||
for (auto& i : m_entries) {
|
||||
Entry* entry = i.getValue();
|
||||
// only write values with given prefix
|
||||
if (!entry->value || !i.getKey().startswith(prefix)) continue;
|
||||
if (!entry->value || !i.getKey().startswith(prefixStr)) continue;
|
||||
entries->emplace_back(i.getKey(), entry->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,11 +97,11 @@ class Storage : public IStorage {
|
||||
|
||||
void DeleteAllEntries();
|
||||
|
||||
std::vector<EntryInfo> GetEntryInfo(int inst, StringRef prefix,
|
||||
std::vector<EntryInfo> GetEntryInfo(int inst, const Twine& prefix,
|
||||
unsigned int types);
|
||||
|
||||
unsigned int AddListener(
|
||||
StringRef prefix,
|
||||
const Twine& prefix,
|
||||
std::function<void(const EntryNotification& event)> callback,
|
||||
unsigned int flags) const;
|
||||
unsigned int AddListener(
|
||||
@@ -109,14 +109,14 @@ class Storage : public IStorage {
|
||||
std::function<void(const EntryNotification& event)> callback,
|
||||
unsigned int flags) const;
|
||||
|
||||
unsigned int AddPolledListener(unsigned int poller_uid, StringRef prefix,
|
||||
unsigned int AddPolledListener(unsigned int poller_uid, const Twine& prefix,
|
||||
unsigned int flags) const;
|
||||
unsigned int AddPolledListener(unsigned int poller_uid, unsigned int local_id,
|
||||
unsigned int flags) const;
|
||||
|
||||
// Index-only
|
||||
unsigned int GetEntry(StringRef name);
|
||||
std::vector<unsigned int> GetEntries(StringRef prefix, unsigned int types);
|
||||
unsigned int GetEntry(const Twine& name);
|
||||
std::vector<unsigned int> GetEntries(const Twine& prefix, unsigned int types);
|
||||
EntryInfo GetEntryInfo(int inst, unsigned int local_id) const;
|
||||
std::string GetEntryName(unsigned int local_id) const;
|
||||
NT_Type GetEntryType(unsigned int local_id) const;
|
||||
@@ -124,23 +124,24 @@ class Storage : public IStorage {
|
||||
|
||||
// Filename-based save/load functions. Used both by periodic saves and
|
||||
// accessible directly via the user API.
|
||||
const char* SavePersistent(StringRef filename, bool periodic) const override;
|
||||
const char* SavePersistent(const Twine& filename,
|
||||
bool periodic) const override;
|
||||
const char* LoadPersistent(
|
||||
StringRef filename,
|
||||
const Twine& filename,
|
||||
std::function<void(std::size_t line, const char* msg)> warn) override;
|
||||
|
||||
const char* SaveEntries(StringRef filename, StringRef prefix) const;
|
||||
const char* SaveEntries(const Twine& filename, const Twine& prefix) const;
|
||||
const char* LoadEntries(
|
||||
StringRef filename, StringRef prefix,
|
||||
const Twine& filename, const Twine& prefix,
|
||||
std::function<void(std::size_t line, const char* msg)> warn);
|
||||
|
||||
// Stream-based save/load functions (exposed for testing purposes). These
|
||||
// implement the guts of the filename-based functions.
|
||||
void SavePersistent(llvm::raw_ostream& os, bool periodic) const;
|
||||
bool LoadEntries(wpi::raw_istream& is, StringRef prefix, bool persistent,
|
||||
bool LoadEntries(wpi::raw_istream& is, const Twine& prefix, bool persistent,
|
||||
std::function<void(std::size_t line, const char* msg)> warn);
|
||||
|
||||
void SaveEntries(llvm::raw_ostream& os, StringRef prefix) const;
|
||||
void SaveEntries(llvm::raw_ostream& os, const Twine& prefix) const;
|
||||
|
||||
// RPC configuration needs to come through here as RPC definitions are
|
||||
// actually special Storage value types.
|
||||
@@ -237,7 +238,7 @@ class Storage : public IStorage {
|
||||
bool periodic,
|
||||
std::vector<std::pair<std::string, std::shared_ptr<Value>>>* entries)
|
||||
const;
|
||||
bool GetEntries(StringRef prefix,
|
||||
bool GetEntries(const Twine& prefix,
|
||||
std::vector<std::pair<std::string, std::shared_ptr<Value>>>*
|
||||
entries) const;
|
||||
void SetEntryValueImpl(Entry* entry, std::shared_ptr<Value> value,
|
||||
@@ -251,7 +252,7 @@ class Storage : public IStorage {
|
||||
template <typename F>
|
||||
void DeleteAllEntriesImpl(bool local, F should_delete);
|
||||
void DeleteAllEntriesImpl(bool local);
|
||||
Entry* GetOrNew(StringRef name);
|
||||
Entry* GetOrNew(const Twine& name);
|
||||
};
|
||||
|
||||
} // namespace nt
|
||||
|
||||
@@ -362,13 +362,16 @@ std::shared_ptr<Value> LoadPersistentImpl::ReadStringArrayValue() {
|
||||
}
|
||||
|
||||
bool Storage::LoadEntries(
|
||||
wpi::raw_istream& is, StringRef prefix, bool persistent,
|
||||
wpi::raw_istream& is, const Twine& prefix, bool persistent,
|
||||
std::function<void(std::size_t line, const char* msg)> warn) {
|
||||
llvm::SmallString<128> prefixBuf;
|
||||
StringRef prefixStr = prefix.toStringRef(prefixBuf);
|
||||
|
||||
// entries to add
|
||||
std::vector<LoadPersistentImpl::Entry> entries;
|
||||
|
||||
// load file
|
||||
if (!LoadPersistentImpl(is, warn).Load(prefix, &entries)) return false;
|
||||
if (!LoadPersistentImpl(is, warn).Load(prefixStr, &entries)) return false;
|
||||
|
||||
// copy values into storage as quickly as possible so lock isn't held
|
||||
std::vector<std::shared_ptr<Message>> msgs;
|
||||
@@ -431,7 +434,7 @@ bool Storage::LoadEntries(
|
||||
}
|
||||
|
||||
const char* Storage::LoadPersistent(
|
||||
StringRef filename,
|
||||
const Twine& filename,
|
||||
std::function<void(std::size_t line, const char* msg)> warn) {
|
||||
std::error_code ec;
|
||||
wpi::raw_fd_istream is(filename, ec);
|
||||
@@ -441,7 +444,7 @@ const char* Storage::LoadPersistent(
|
||||
}
|
||||
|
||||
const char* Storage::LoadEntries(
|
||||
StringRef filename, StringRef prefix,
|
||||
const Twine& filename, const Twine& prefix,
|
||||
std::function<void(std::size_t line, const char* msg)> warn) {
|
||||
std::error_code ec;
|
||||
wpi::raw_fd_istream is(filename, ec);
|
||||
|
||||
@@ -181,11 +181,13 @@ void Storage::SavePersistent(llvm::raw_ostream& os, bool periodic) const {
|
||||
SavePersistentImpl(os).Save(entries);
|
||||
}
|
||||
|
||||
const char* Storage::SavePersistent(StringRef filename, bool periodic) const {
|
||||
llvm::SmallString<128> fn = filename;
|
||||
llvm::SmallString<128> tmp = filename;
|
||||
const char* Storage::SavePersistent(const Twine& filename,
|
||||
bool periodic) const {
|
||||
llvm::SmallString<128> fn;
|
||||
filename.toVector(fn);
|
||||
llvm::SmallString<128> tmp = fn;
|
||||
tmp += ".tmp";
|
||||
llvm::SmallString<128> bak = filename;
|
||||
llvm::SmallString<128> bak = fn;
|
||||
bak += ".bak";
|
||||
|
||||
// Get entries before creating file
|
||||
@@ -225,17 +227,19 @@ done:
|
||||
return err;
|
||||
}
|
||||
|
||||
void Storage::SaveEntries(llvm::raw_ostream& os, StringRef prefix) const {
|
||||
void Storage::SaveEntries(llvm::raw_ostream& os, const Twine& prefix) const {
|
||||
std::vector<SavePersistentImpl::Entry> entries;
|
||||
if (!GetEntries(prefix, &entries)) return;
|
||||
SavePersistentImpl(os).Save(entries);
|
||||
}
|
||||
|
||||
const char* Storage::SaveEntries(StringRef filename, StringRef prefix) const {
|
||||
llvm::SmallString<128> fn = filename;
|
||||
llvm::SmallString<128> tmp = filename;
|
||||
const char* Storage::SaveEntries(const Twine& filename,
|
||||
const Twine& prefix) const {
|
||||
llvm::SmallString<128> fn;
|
||||
filename.toVector(fn);
|
||||
llvm::SmallString<128> tmp = fn;
|
||||
tmp += ".tmp";
|
||||
llvm::SmallString<128> bak = filename;
|
||||
llvm::SmallString<128> bak = fn;
|
||||
bak += ".bak";
|
||||
|
||||
// Get entries before creating file
|
||||
|
||||
@@ -387,7 +387,7 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_networktables_NetworkTablesJNI_getEntr
|
||||
nullPointerEx.Throw(env, "key cannot be null");
|
||||
return false;
|
||||
}
|
||||
return nt::GetEntry(inst, JStringRef{env, key});
|
||||
return nt::GetEntry(inst, JStringRef{env, key}.str());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -402,8 +402,8 @@ JNIEXPORT jintArray JNICALL Java_edu_wpi_first_networktables_NetworkTablesJNI_ge
|
||||
nullPointerEx.Throw(env, "prefix cannot be null");
|
||||
return nullptr;
|
||||
}
|
||||
return MakeJIntArray(env,
|
||||
nt::GetEntries(inst, JStringRef{env, prefix}, types));
|
||||
return MakeJIntArray(
|
||||
env, nt::GetEntries(inst, JStringRef{env, prefix}.str(), types));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -484,12 +484,12 @@ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_networktables_NetworkTablesJNI_set
|
||||
return false;
|
||||
}
|
||||
if (force) {
|
||||
nt::SetEntryTypeValue(entry,
|
||||
nt::Value::MakeString(JStringRef{env, value}, time));
|
||||
nt::SetEntryTypeValue(
|
||||
entry, nt::Value::MakeString(JStringRef{env, value}.str(), time));
|
||||
return JNI_TRUE;
|
||||
}
|
||||
return nt::SetEntryValue(entry,
|
||||
nt::Value::MakeString(JStringRef{env, value}, time));
|
||||
return nt::SetEntryValue(
|
||||
entry, nt::Value::MakeString(JStringRef{env, value}.str(), time));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -737,7 +737,7 @@ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_networktables_NetworkTablesJNI_set
|
||||
return false;
|
||||
}
|
||||
return nt::SetDefaultEntryValue(
|
||||
entry, nt::Value::MakeString(JStringRef{env, defaultValue}, time));
|
||||
entry, nt::Value::MakeString(JStringRef{env, defaultValue}.str(), time));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -871,7 +871,7 @@ JNIEXPORT jobjectArray JNICALL Java_edu_wpi_first_networktables_NetworkTablesJNI
|
||||
nullPointerEx.Throw(env, "prefix cannot be null");
|
||||
return nullptr;
|
||||
}
|
||||
auto arr = nt::GetEntryInfo(inst, JStringRef{env, prefix}, types);
|
||||
auto arr = nt::GetEntryInfo(inst, JStringRef{env, prefix}.str(), types);
|
||||
jobjectArray jarr = env->NewObjectArray(arr.size(), entryInfoCls, nullptr);
|
||||
if (!jarr) return nullptr;
|
||||
for (size_t i = 0; i < arr.size(); ++i) {
|
||||
@@ -915,7 +915,8 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_networktables_NetworkTablesJNI_addPoll
|
||||
nullPointerEx.Throw(env, "prefix cannot be null");
|
||||
return 0;
|
||||
}
|
||||
return nt::AddPolledEntryListener(poller, JStringRef{env, prefix}, flags);
|
||||
return nt::AddPolledEntryListener(poller, JStringRef{env, prefix}.str(),
|
||||
flags);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1280,7 +1281,7 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_networktables_NetworkTablesJNI_setNetw
|
||||
nullPointerEx.Throw(env, "name cannot be null");
|
||||
return;
|
||||
}
|
||||
nt::SetNetworkIdentity(inst, JStringRef{env, name});
|
||||
nt::SetNetworkIdentity(inst, JStringRef{env, name}.str());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1310,7 +1311,7 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_networktables_NetworkTablesJNI_startSe
|
||||
nullPointerEx.Throw(env, "listenAddress cannot be null");
|
||||
return;
|
||||
}
|
||||
nt::StartServer(inst, JStringRef{env, persistFilename},
|
||||
nt::StartServer(inst, JStringRef{env, persistFilename}.str(),
|
||||
JStringRef{env, listenAddress}.c_str(), port);
|
||||
}
|
||||
|
||||
@@ -1573,7 +1574,7 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_networktables_NetworkTablesJNI_savePer
|
||||
nullPointerEx.Throw(env, "filename cannot be null");
|
||||
return;
|
||||
}
|
||||
const char *err = nt::SavePersistent(inst, JStringRef{env, filename});
|
||||
const char *err = nt::SavePersistent(inst, JStringRef{env, filename}.str());
|
||||
if (err) persistentEx.Throw(env, err);
|
||||
}
|
||||
|
||||
@@ -1590,7 +1591,7 @@ JNIEXPORT jobjectArray JNICALL Java_edu_wpi_first_networktables_NetworkTablesJNI
|
||||
return nullptr;
|
||||
}
|
||||
std::vector<std::string> warns;
|
||||
const char* err = nt::LoadPersistent(inst, JStringRef{env, filename},
|
||||
const char* err = nt::LoadPersistent(inst, JStringRef{env, filename}.str(),
|
||||
[&](size_t line, const char* msg) {
|
||||
llvm::SmallString<128> warn;
|
||||
llvm::raw_svector_ostream oss(warn);
|
||||
@@ -1620,8 +1621,8 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_networktables_NetworkTablesJNI_saveEnt
|
||||
nullPointerEx.Throw(env, "prefix cannot be null");
|
||||
return;
|
||||
}
|
||||
const char* err =
|
||||
nt::SaveEntries(inst, JStringRef{env, filename}, JStringRef{env, prefix});
|
||||
const char* err = nt::SaveEntries(inst, JStringRef{env, filename}.str(),
|
||||
JStringRef{env, prefix}.str());
|
||||
if (err) persistentEx.Throw(env, err);
|
||||
}
|
||||
|
||||
@@ -1642,14 +1643,14 @@ JNIEXPORT jobjectArray JNICALL Java_edu_wpi_first_networktables_NetworkTablesJNI
|
||||
return nullptr;
|
||||
}
|
||||
std::vector<std::string> warns;
|
||||
const char* err =
|
||||
nt::LoadEntries(inst, JStringRef{env, filename}, JStringRef{env, prefix},
|
||||
[&](size_t line, const char* msg) {
|
||||
llvm::SmallString<128> warn;
|
||||
llvm::raw_svector_ostream oss(warn);
|
||||
oss << line << ": " << msg;
|
||||
warns.emplace_back(oss.str());
|
||||
});
|
||||
const char* err = nt::LoadEntries(inst, JStringRef{env, filename}.str(),
|
||||
JStringRef{env, prefix}.str(),
|
||||
[&](size_t line, const char* msg) {
|
||||
llvm::SmallString<128> warn;
|
||||
llvm::raw_svector_ostream oss(warn);
|
||||
oss << line << ": " << msg;
|
||||
warns.emplace_back(oss.str());
|
||||
});
|
||||
if (err) {
|
||||
persistentEx.Throw(env, err);
|
||||
return nullptr;
|
||||
|
||||
@@ -28,35 +28,40 @@ StringRef NetworkTable::BasenameKey(StringRef key) {
|
||||
return key.substr(slash + 1);
|
||||
}
|
||||
|
||||
std::string NetworkTable::NormalizeKey(StringRef key, bool withLeadingSlash) {
|
||||
std::string NetworkTable::NormalizeKey(const Twine& key,
|
||||
bool withLeadingSlash) {
|
||||
llvm::SmallString<128> buf;
|
||||
return NormalizeKey(key, buf, withLeadingSlash);
|
||||
}
|
||||
|
||||
StringRef NetworkTable::NormalizeKey(StringRef key,
|
||||
StringRef NetworkTable::NormalizeKey(const Twine& key,
|
||||
llvm::SmallVectorImpl<char>& buf,
|
||||
bool withLeadingSlash) {
|
||||
buf.clear();
|
||||
if (withLeadingSlash) buf.push_back(PATH_SEPARATOR_CHAR);
|
||||
// for each path element, add it with a slash following
|
||||
llvm::SmallString<128> keyBuf;
|
||||
StringRef keyStr = key.toStringRef(keyBuf);
|
||||
llvm::SmallVector<StringRef, 16> parts;
|
||||
key.split(parts, PATH_SEPARATOR_CHAR, -1, false);
|
||||
keyStr.split(parts, PATH_SEPARATOR_CHAR, -1, false);
|
||||
for (auto i = parts.begin(); i != parts.end(); ++i) {
|
||||
buf.append(i->begin(), i->end());
|
||||
buf.push_back(PATH_SEPARATOR_CHAR);
|
||||
}
|
||||
// remove trailing slash if the input key didn't have one
|
||||
if (!key.empty() && key.back() != PATH_SEPARATOR_CHAR) buf.pop_back();
|
||||
if (!keyStr.empty() && keyStr.back() != PATH_SEPARATOR_CHAR) buf.pop_back();
|
||||
return StringRef(buf.data(), buf.size());
|
||||
}
|
||||
|
||||
std::vector<std::string> NetworkTable::GetHierarchy(StringRef key) {
|
||||
std::vector<std::string> NetworkTable::GetHierarchy(const Twine& key) {
|
||||
std::vector<std::string> hierarchy;
|
||||
hierarchy.emplace_back(1, PATH_SEPARATOR_CHAR);
|
||||
// for each path element, add it to the end of what we built previously
|
||||
llvm::SmallString<128> keyBuf;
|
||||
StringRef keyStr = key.toStringRef(keyBuf);
|
||||
llvm::SmallString<128> path;
|
||||
llvm::SmallVector<StringRef, 16> parts;
|
||||
key.split(parts, PATH_SEPARATOR_CHAR, -1, false);
|
||||
keyStr.split(parts, PATH_SEPARATOR_CHAR, -1, false);
|
||||
if (!parts.empty()) {
|
||||
for (auto i = parts.begin(); i != parts.end(); ++i) {
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
@@ -64,7 +69,7 @@ std::vector<std::string> NetworkTable::GetHierarchy(StringRef key) {
|
||||
hierarchy.emplace_back(path.str());
|
||||
}
|
||||
// handle trailing slash
|
||||
if (key.back() == PATH_SEPARATOR_CHAR) {
|
||||
if (keyStr.back() == PATH_SEPARATOR_CHAR) {
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
hierarchy.emplace_back(path.str());
|
||||
}
|
||||
@@ -116,7 +121,7 @@ void NetworkTable::SetIPAddress(StringRef address) {
|
||||
inst.StartDSClient(s_port);
|
||||
}
|
||||
|
||||
void NetworkTable::SetIPAddress(llvm::ArrayRef<std::string> addresses) {
|
||||
void NetworkTable::SetIPAddress(ArrayRef<std::string> addresses) {
|
||||
auto inst = NetworkTableInstance::GetDefault();
|
||||
llvm::SmallVector<StringRef, 8> servers;
|
||||
for (const auto& ip_address : addresses) servers.emplace_back(ip_address);
|
||||
@@ -159,12 +164,12 @@ void NetworkTable::SetUpdateRate(double interval) {
|
||||
NetworkTableInstance::GetDefault().SetUpdateRate(interval);
|
||||
}
|
||||
|
||||
const char* NetworkTable::SavePersistent(llvm::StringRef filename) {
|
||||
const char* NetworkTable::SavePersistent(StringRef filename) {
|
||||
return NetworkTableInstance::GetDefault().SavePersistent(filename);
|
||||
}
|
||||
|
||||
const char* NetworkTable::LoadPersistent(
|
||||
llvm::StringRef filename,
|
||||
StringRef filename,
|
||||
std::function<void(size_t line, const char* msg)> warn) {
|
||||
return NetworkTableInstance::GetDefault().LoadPersistent(filename, warn);
|
||||
}
|
||||
@@ -174,8 +179,8 @@ std::shared_ptr<NetworkTable> NetworkTable::GetTable(StringRef key) {
|
||||
return NetworkTableInstance::GetDefault().GetTable(key);
|
||||
}
|
||||
|
||||
NetworkTable::NetworkTable(NT_Inst inst, StringRef path, const private_init&)
|
||||
: m_inst(inst), m_path(path) {}
|
||||
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);
|
||||
@@ -185,25 +190,22 @@ NetworkTableInstance NetworkTable::GetInstance() const {
|
||||
return NetworkTableInstance{m_inst};
|
||||
}
|
||||
|
||||
NetworkTableEntry NetworkTable::GetEntry(llvm::StringRef key) const {
|
||||
NetworkTableEntry NetworkTable::GetEntry(const Twine& key) const {
|
||||
llvm::SmallString<128> keyBuf;
|
||||
StringRef keyStr = key.toStringRef(keyBuf);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
NT_Entry& entry = m_entries[key];
|
||||
NT_Entry& entry = m_entries[keyStr];
|
||||
if (entry == 0) {
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
path += key;
|
||||
entry = nt::GetEntry(m_inst, path);
|
||||
entry = nt::GetEntry(m_inst, m_path + Twine(PATH_SEPARATOR_CHAR) + keyStr);
|
||||
}
|
||||
return NetworkTableEntry{entry};
|
||||
}
|
||||
|
||||
NT_EntryListener NetworkTable::AddEntryListener(TableEntryListener listener,
|
||||
unsigned int flags) const {
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
std::size_t prefix_len = path.size();
|
||||
std::size_t prefix_len = m_path.size() + 1;
|
||||
return nt::AddEntryListener(
|
||||
m_inst, path,
|
||||
m_inst, m_path + Twine(PATH_SEPARATOR_CHAR),
|
||||
[=](const EntryNotification& event) {
|
||||
StringRef relative_key = event.name.substr(prefix_len);
|
||||
if (relative_key.find(PATH_SEPARATOR_CHAR) != StringRef::npos) return;
|
||||
@@ -213,7 +215,7 @@ NT_EntryListener NetworkTable::AddEntryListener(TableEntryListener listener,
|
||||
flags);
|
||||
}
|
||||
|
||||
NT_EntryListener NetworkTable::AddEntryListener(StringRef key,
|
||||
NT_EntryListener NetworkTable::AddEntryListener(const Twine& key,
|
||||
TableEntryListener listener,
|
||||
unsigned int flags) const {
|
||||
std::size_t prefix_len = m_path.size() + 1;
|
||||
@@ -269,14 +271,11 @@ void NetworkTable::AddTableListener(StringRef key, ITableListener* listener,
|
||||
void NetworkTable::AddTableListenerEx(StringRef key, ITableListener* listener,
|
||||
unsigned int flags) {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
std::size_t prefix_len = path.size();
|
||||
path += key;
|
||||
std::size_t prefix_len = m_path.size() + 1;
|
||||
auto entry = GetEntry(key);
|
||||
NT_EntryListener id = nt::AddEntryListener(
|
||||
m_inst, path,
|
||||
entry.GetHandle(),
|
||||
[=](const EntryNotification& event) {
|
||||
if (event.name != path) return;
|
||||
listener->ValueChangedEx(this, event.name.substr(prefix_len),
|
||||
event.value, event.flags);
|
||||
},
|
||||
@@ -291,9 +290,7 @@ void NetworkTable::AddSubTableListener(ITableListener* listener) {
|
||||
void NetworkTable::AddSubTableListener(ITableListener* listener,
|
||||
bool localNotify) {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
std::size_t prefix_len = path.size();
|
||||
std::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.
|
||||
@@ -302,7 +299,7 @@ void NetworkTable::AddSubTableListener(ITableListener* listener,
|
||||
unsigned int flags = NT_NOTIFY_NEW | NT_NOTIFY_IMMEDIATE;
|
||||
if (localNotify) flags |= NT_NOTIFY_LOCAL;
|
||||
NT_EntryListener id = nt::AddEntryListener(
|
||||
m_inst, path,
|
||||
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);
|
||||
@@ -328,33 +325,34 @@ void NetworkTable::RemoveTableListener(ITableListener* listener) {
|
||||
m_listeners.erase(matches_begin, m_listeners.end());
|
||||
}
|
||||
|
||||
std::shared_ptr<NetworkTable> NetworkTable::GetSubTable(StringRef key) const {
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
path += key;
|
||||
return std::make_shared<NetworkTable>(m_inst, path, private_init{});
|
||||
std::shared_ptr<NetworkTable> NetworkTable::GetSubTable(
|
||||
const Twine& key) const {
|
||||
return std::make_shared<NetworkTable>(
|
||||
m_inst, m_path + Twine(PATH_SEPARATOR_CHAR) + key, private_init{});
|
||||
}
|
||||
|
||||
bool NetworkTable::ContainsKey(StringRef key) const {
|
||||
return !key.empty() && GetEntry(key).Exists();
|
||||
bool NetworkTable::ContainsKey(const Twine& key) const {
|
||||
if (key.isTriviallyEmpty() ||
|
||||
(key.isSingleStringRef() && key.getSingleStringRef().empty()))
|
||||
return false;
|
||||
return GetEntry(key).Exists();
|
||||
}
|
||||
|
||||
bool NetworkTable::ContainsSubTable(StringRef key) const {
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
path += key;
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
return !GetEntryInfo(m_inst, path, 0).empty();
|
||||
bool NetworkTable::ContainsSubTable(const Twine& key) const {
|
||||
return !GetEntryInfo(m_inst,
|
||||
m_path + Twine(PATH_SEPARATOR_CHAR) + key +
|
||||
Twine(PATH_SEPARATOR_CHAR),
|
||||
0)
|
||||
.empty();
|
||||
}
|
||||
|
||||
std::vector<std::string> NetworkTable::GetKeys(int types) const {
|
||||
std::vector<std::string> keys;
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
auto infos = GetEntryInfo(m_inst, path, types);
|
||||
size_t prefix_len = m_path.size() + 1;
|
||||
auto infos = GetEntryInfo(m_inst, m_path + Twine(PATH_SEPARATOR_CHAR), types);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
for (auto& info : infos) {
|
||||
auto relative_key = StringRef(info.name).substr(path.size());
|
||||
auto relative_key = StringRef(info.name).substr(prefix_len);
|
||||
if (relative_key.find(PATH_SEPARATOR_CHAR) != StringRef::npos) continue;
|
||||
keys.push_back(relative_key);
|
||||
m_entries[relative_key] = info.entry;
|
||||
@@ -364,10 +362,10 @@ std::vector<std::string> NetworkTable::GetKeys(int types) const {
|
||||
|
||||
std::vector<std::string> NetworkTable::GetSubTables() const {
|
||||
std::vector<std::string> keys;
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
for (auto& entry : GetEntryInfo(m_inst, path, 0)) {
|
||||
auto relative_key = StringRef(entry.name).substr(path.size());
|
||||
size_t prefix_len = m_path.size() + 1;
|
||||
for (auto& entry :
|
||||
GetEntryInfo(m_inst, m_path + Twine(PATH_SEPARATOR_CHAR), 0)) {
|
||||
auto relative_key = StringRef(entry.name).substr(prefix_len);
|
||||
std::size_t end_subtable = relative_key.find(PATH_SEPARATOR_CHAR);
|
||||
if (end_subtable == StringRef::npos) continue;
|
||||
keys.push_back(relative_key.substr(0, end_subtable));
|
||||
@@ -399,7 +397,7 @@ unsigned int NetworkTable::GetFlags(StringRef key) const {
|
||||
return GetEntry(key).GetFlags();
|
||||
}
|
||||
|
||||
void NetworkTable::Delete(StringRef key) { GetEntry(key).Delete(); }
|
||||
void NetworkTable::Delete(const Twine& key) { GetEntry(key).Delete(); }
|
||||
|
||||
bool NetworkTable::PutNumber(StringRef key, double value) {
|
||||
return GetEntry(key).SetDouble(value);
|
||||
@@ -438,52 +436,49 @@ bool NetworkTable::GetBoolean(StringRef key, bool defaultValue) const {
|
||||
return GetEntry(key).GetBoolean(defaultValue);
|
||||
}
|
||||
|
||||
bool NetworkTable::PutBooleanArray(llvm::StringRef key,
|
||||
llvm::ArrayRef<int> value) {
|
||||
bool NetworkTable::PutBooleanArray(StringRef key, ArrayRef<int> value) {
|
||||
return GetEntry(key).SetBooleanArray(value);
|
||||
}
|
||||
|
||||
bool NetworkTable::SetDefaultBooleanArray(StringRef key,
|
||||
llvm::ArrayRef<int> defaultValue) {
|
||||
ArrayRef<int> defaultValue) {
|
||||
return GetEntry(key).SetDefaultBooleanArray(defaultValue);
|
||||
}
|
||||
|
||||
std::vector<int> NetworkTable::GetBooleanArray(
|
||||
llvm::StringRef key, llvm::ArrayRef<int> defaultValue) const {
|
||||
StringRef key, ArrayRef<int> defaultValue) const {
|
||||
return GetEntry(key).GetBooleanArray(defaultValue);
|
||||
}
|
||||
|
||||
bool NetworkTable::PutNumberArray(llvm::StringRef key,
|
||||
llvm::ArrayRef<double> value) {
|
||||
bool NetworkTable::PutNumberArray(StringRef key, ArrayRef<double> value) {
|
||||
return GetEntry(key).SetDoubleArray(value);
|
||||
}
|
||||
|
||||
bool NetworkTable::SetDefaultNumberArray(StringRef key,
|
||||
llvm::ArrayRef<double> defaultValue) {
|
||||
ArrayRef<double> defaultValue) {
|
||||
return GetEntry(key).SetDefaultDoubleArray(defaultValue);
|
||||
}
|
||||
|
||||
std::vector<double> NetworkTable::GetNumberArray(
|
||||
llvm::StringRef key, llvm::ArrayRef<double> defaultValue) const {
|
||||
StringRef key, ArrayRef<double> defaultValue) const {
|
||||
return GetEntry(key).GetDoubleArray(defaultValue);
|
||||
}
|
||||
|
||||
bool NetworkTable::PutStringArray(llvm::StringRef key,
|
||||
llvm::ArrayRef<std::string> value) {
|
||||
bool NetworkTable::PutStringArray(StringRef key, ArrayRef<std::string> value) {
|
||||
return GetEntry(key).SetStringArray(value);
|
||||
}
|
||||
|
||||
bool NetworkTable::SetDefaultStringArray(
|
||||
StringRef key, llvm::ArrayRef<std::string> defaultValue) {
|
||||
StringRef key, ArrayRef<std::string> defaultValue) {
|
||||
return GetEntry(key).SetDefaultStringArray(defaultValue);
|
||||
}
|
||||
|
||||
std::vector<std::string> NetworkTable::GetStringArray(
|
||||
llvm::StringRef key, llvm::ArrayRef<std::string> defaultValue) const {
|
||||
StringRef key, ArrayRef<std::string> defaultValue) const {
|
||||
return GetEntry(key).GetStringArray(defaultValue);
|
||||
}
|
||||
|
||||
bool NetworkTable::PutRaw(llvm::StringRef key, llvm::StringRef value) {
|
||||
bool NetworkTable::PutRaw(StringRef key, StringRef value) {
|
||||
return GetEntry(key).SetRaw(value);
|
||||
}
|
||||
|
||||
@@ -491,36 +486,32 @@ bool NetworkTable::SetDefaultRaw(StringRef key, StringRef defaultValue) {
|
||||
return GetEntry(key).SetDefaultRaw(defaultValue);
|
||||
}
|
||||
|
||||
std::string NetworkTable::GetRaw(llvm::StringRef key,
|
||||
llvm::StringRef defaultValue) const {
|
||||
std::string NetworkTable::GetRaw(StringRef key, StringRef defaultValue) const {
|
||||
return GetEntry(key).GetRaw(defaultValue);
|
||||
}
|
||||
|
||||
bool NetworkTable::PutValue(StringRef key, std::shared_ptr<Value> value) {
|
||||
bool NetworkTable::PutValue(const Twine& key, std::shared_ptr<Value> value) {
|
||||
return GetEntry(key).SetValue(value);
|
||||
}
|
||||
|
||||
bool NetworkTable::SetDefaultValue(StringRef key,
|
||||
bool NetworkTable::SetDefaultValue(const Twine& key,
|
||||
std::shared_ptr<Value> defaultValue) {
|
||||
return GetEntry(key).SetDefaultValue(defaultValue);
|
||||
}
|
||||
|
||||
std::shared_ptr<Value> NetworkTable::GetValue(StringRef key) const {
|
||||
std::shared_ptr<Value> NetworkTable::GetValue(const Twine& key) const {
|
||||
return GetEntry(key).GetValue();
|
||||
}
|
||||
|
||||
StringRef NetworkTable::GetPath() const { return m_path; }
|
||||
|
||||
const char* NetworkTable::SaveEntries(StringRef filename) const {
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
return nt::SaveEntries(m_inst, filename, path);
|
||||
const char* NetworkTable::SaveEntries(const Twine& filename) const {
|
||||
return nt::SaveEntries(m_inst, filename, m_path + Twine(PATH_SEPARATOR_CHAR));
|
||||
}
|
||||
|
||||
const char* NetworkTable::LoadEntries(
|
||||
StringRef filename,
|
||||
const Twine& filename,
|
||||
std::function<void(size_t line, const char* msg)> warn) {
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
return nt::LoadEntries(m_inst, filename, path, warn);
|
||||
return nt::LoadEntries(m_inst, filename, m_path + Twine(PATH_SEPARATOR_CHAR),
|
||||
warn);
|
||||
}
|
||||
|
||||
@@ -11,19 +11,20 @@
|
||||
using namespace nt;
|
||||
|
||||
std::shared_ptr<NetworkTable> NetworkTableInstance::GetTable(
|
||||
StringRef key) const {
|
||||
if (key.empty() || key == "/") {
|
||||
const Twine& key) const {
|
||||
StringRef simple;
|
||||
bool isSimple = key.isSingleStringRef();
|
||||
if (isSimple) simple = key.getSingleStringRef();
|
||||
if (isSimple && (simple.empty() || simple == "/")) {
|
||||
return std::make_shared<NetworkTable>(m_handle, "",
|
||||
NetworkTable::private_init{});
|
||||
} else if (key[0] == NetworkTable::PATH_SEPARATOR_CHAR) {
|
||||
} else if (isSimple && simple[0] == NetworkTable::PATH_SEPARATOR_CHAR) {
|
||||
return std::make_shared<NetworkTable>(m_handle, key,
|
||||
NetworkTable::private_init{});
|
||||
} else {
|
||||
llvm::SmallString<128> path;
|
||||
path += NetworkTable::PATH_SEPARATOR_CHAR;
|
||||
path += key;
|
||||
return std::make_shared<NetworkTable>(m_handle, path,
|
||||
NetworkTable::private_init{});
|
||||
return std::make_shared<NetworkTable>(
|
||||
m_handle, Twine(NetworkTable::PATH_SEPARATOR_CHAR) + key,
|
||||
NetworkTable::private_init{});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +45,7 @@ void NetworkTableInstance::SetServer(ArrayRef<StringRef> servers,
|
||||
}
|
||||
|
||||
NT_EntryListener NetworkTableInstance::AddEntryListener(
|
||||
StringRef prefix,
|
||||
const Twine& prefix,
|
||||
std::function<void(const EntryNotification& event)> callback,
|
||||
unsigned int flags) const {
|
||||
return ::nt::AddEntryListener(m_handle, prefix, callback, flags);
|
||||
|
||||
@@ -52,7 +52,7 @@ NT_Inst GetInstanceFromHandle(NT_Handle handle) {
|
||||
* Table Functions
|
||||
*/
|
||||
|
||||
NT_Entry GetEntry(NT_Inst inst, StringRef name) {
|
||||
NT_Entry GetEntry(NT_Inst inst, const Twine& name) {
|
||||
int i = Handle{inst}.GetTypedInst(Handle::kInstance);
|
||||
auto ii = InstanceImpl::Get(i);
|
||||
if (!ii) return 0;
|
||||
@@ -62,7 +62,7 @@ NT_Entry GetEntry(NT_Inst inst, StringRef name) {
|
||||
return Handle(i, id, Handle::kEntry);
|
||||
}
|
||||
|
||||
std::vector<NT_Entry> GetEntries(NT_Inst inst, StringRef prefix,
|
||||
std::vector<NT_Entry> GetEntries(NT_Inst inst, const Twine& prefix,
|
||||
unsigned int types) {
|
||||
int i = Handle{inst}.GetTypedInst(Handle::kInstance);
|
||||
auto ii = InstanceImpl::Get(i);
|
||||
@@ -208,7 +208,7 @@ std::vector<EntryInfo> GetEntryInfo(StringRef prefix, unsigned int types) {
|
||||
return InstanceImpl::GetDefault()->storage.GetEntryInfo(0, prefix, types);
|
||||
}
|
||||
|
||||
std::vector<EntryInfo> GetEntryInfo(NT_Inst inst, StringRef prefix,
|
||||
std::vector<EntryInfo> GetEntryInfo(NT_Inst inst, const Twine& prefix,
|
||||
unsigned int types) {
|
||||
int i = Handle{inst}.GetTypedInst(Handle::kInstance);
|
||||
auto ii = InstanceImpl::Get(i);
|
||||
@@ -250,7 +250,7 @@ NT_EntryListener AddEntryListener(StringRef prefix,
|
||||
}
|
||||
|
||||
NT_EntryListener AddEntryListener(
|
||||
NT_Inst inst, StringRef prefix,
|
||||
NT_Inst inst, const Twine& prefix,
|
||||
std::function<void(const EntryNotification& event)> callback,
|
||||
unsigned int flags) {
|
||||
int i = Handle{inst}.GetTypedInst(Handle::kInstance);
|
||||
@@ -294,7 +294,8 @@ void DestroyEntryListenerPoller(NT_EntryListenerPoller poller) {
|
||||
}
|
||||
|
||||
NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller,
|
||||
StringRef prefix, unsigned int flags) {
|
||||
const Twine& prefix,
|
||||
unsigned int flags) {
|
||||
Handle handle{poller};
|
||||
int id = handle.GetTypedIndex(Handle::kEntryListenerPoller);
|
||||
int i = handle.GetInst();
|
||||
@@ -722,7 +723,7 @@ void SetNetworkIdentity(StringRef name) {
|
||||
InstanceImpl::GetDefault()->dispatcher.SetIdentity(name);
|
||||
}
|
||||
|
||||
void SetNetworkIdentity(NT_Inst inst, StringRef name) {
|
||||
void SetNetworkIdentity(NT_Inst inst, const Twine& name) {
|
||||
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
|
||||
if (!ii) return;
|
||||
|
||||
@@ -746,7 +747,7 @@ void StartServer(StringRef persist_filename, const char* listen_address,
|
||||
ii->dispatcher.StartServer(persist_filename, listen_address, port);
|
||||
}
|
||||
|
||||
void StartServer(NT_Inst inst, StringRef persist_filename,
|
||||
void StartServer(NT_Inst inst, const Twine& persist_filename,
|
||||
const char* listen_address, unsigned int port) {
|
||||
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
|
||||
if (!ii) return;
|
||||
@@ -914,7 +915,7 @@ const char* SavePersistent(StringRef filename) {
|
||||
return InstanceImpl::GetDefault()->storage.SavePersistent(filename, false);
|
||||
}
|
||||
|
||||
const char* SavePersistent(NT_Inst inst, StringRef filename) {
|
||||
const char* SavePersistent(NT_Inst inst, const Twine& filename) {
|
||||
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
|
||||
if (!ii) return "invalid instance handle";
|
||||
|
||||
@@ -928,7 +929,7 @@ const char* LoadPersistent(
|
||||
}
|
||||
|
||||
const char* LoadPersistent(
|
||||
NT_Inst inst, StringRef filename,
|
||||
NT_Inst inst, const Twine& filename,
|
||||
std::function<void(size_t line, const char* msg)> warn) {
|
||||
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
|
||||
if (!ii) return "invalid instance handle";
|
||||
@@ -936,7 +937,8 @@ const char* LoadPersistent(
|
||||
return ii->storage.LoadPersistent(filename, warn);
|
||||
}
|
||||
|
||||
const char* SaveEntries(NT_Inst inst, StringRef filename, StringRef prefix) {
|
||||
const char* SaveEntries(NT_Inst inst, const Twine& filename,
|
||||
const Twine& prefix) {
|
||||
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
|
||||
if (!ii) return "invalid instance handle";
|
||||
|
||||
@@ -944,7 +946,7 @@ const char* SaveEntries(NT_Inst inst, StringRef filename, StringRef prefix) {
|
||||
}
|
||||
|
||||
const char* LoadEntries(
|
||||
NT_Inst inst, StringRef filename, StringRef prefix,
|
||||
NT_Inst inst, const Twine& filename, const Twine& prefix,
|
||||
std::function<void(size_t line, const char* msg)> warn) {
|
||||
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
|
||||
if (!ii) return "invalid instance handle";
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "llvm/ArrayRef.h"
|
||||
#include "llvm/StringRef.h"
|
||||
#include "llvm/Twine.h"
|
||||
#include "support/deprecated.h"
|
||||
|
||||
#include "networktables/NetworkTableValue.h"
|
||||
@@ -25,6 +26,7 @@ namespace nt {
|
||||
|
||||
using llvm::ArrayRef;
|
||||
using llvm::StringRef;
|
||||
using llvm::Twine;
|
||||
|
||||
/** NetworkTables Entry Information */
|
||||
struct EntryInfo {
|
||||
@@ -166,7 +168,7 @@ class EntryNotification {
|
||||
public:
|
||||
EntryNotification() : listener(0), entry(0) {}
|
||||
EntryNotification(NT_EntryListener listener_, NT_Entry entry_,
|
||||
llvm::StringRef name_, std::shared_ptr<Value> value_,
|
||||
StringRef name_, std::shared_ptr<Value> value_,
|
||||
unsigned int flags_)
|
||||
: listener(listener_),
|
||||
entry(entry_),
|
||||
@@ -233,7 +235,7 @@ class LogMessage {
|
||||
public:
|
||||
LogMessage() : logger(0), level(0), filename(""), line(0) {}
|
||||
LogMessage(NT_Logger logger_, unsigned int level_, const char* filename_,
|
||||
unsigned int line_, llvm::StringRef message_)
|
||||
unsigned int line_, StringRef message_)
|
||||
: logger(logger_),
|
||||
level(level_),
|
||||
filename(filename_),
|
||||
@@ -310,7 +312,7 @@ NT_Inst GetInstanceFromHandle(NT_Handle handle);
|
||||
* @param name entry name (UTF-8 string)
|
||||
* @return entry handle
|
||||
*/
|
||||
NT_Entry GetEntry(NT_Inst inst, StringRef name);
|
||||
NT_Entry GetEntry(NT_Inst inst, const Twine& name);
|
||||
|
||||
/**
|
||||
* Get Entry Handles.
|
||||
@@ -325,7 +327,7 @@ NT_Entry GetEntry(NT_Inst inst, StringRef name);
|
||||
* as a "don't care"
|
||||
* @return Array of entry handles.
|
||||
*/
|
||||
std::vector<NT_Entry> GetEntries(NT_Inst inst, StringRef prefix,
|
||||
std::vector<NT_Entry> GetEntries(NT_Inst inst, const Twine& prefix,
|
||||
unsigned int types);
|
||||
|
||||
/**
|
||||
@@ -549,7 +551,7 @@ std::vector<EntryInfo> GetEntryInfo(StringRef prefix, unsigned int types);
|
||||
*
|
||||
* @param inst instance handle
|
||||
*/
|
||||
std::vector<EntryInfo> GetEntryInfo(NT_Inst inst, StringRef prefix,
|
||||
std::vector<EntryInfo> GetEntryInfo(NT_Inst inst, const Twine& prefix,
|
||||
unsigned int types);
|
||||
|
||||
/**
|
||||
@@ -602,7 +604,7 @@ NT_EntryListener AddEntryListener(StringRef prefix,
|
||||
* @param inst instance handle
|
||||
*/
|
||||
NT_EntryListener AddEntryListener(
|
||||
NT_Inst inst, StringRef prefix,
|
||||
NT_Inst inst, const Twine& prefix,
|
||||
std::function<void(const EntryNotification& event)> callback,
|
||||
unsigned int flags);
|
||||
|
||||
@@ -646,7 +648,8 @@ void DestroyEntryListenerPoller(NT_EntryListenerPoller poller);
|
||||
* @return Listener handle
|
||||
*/
|
||||
NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller,
|
||||
StringRef prefix, unsigned int flags);
|
||||
const Twine& prefix,
|
||||
unsigned int flags);
|
||||
|
||||
/**
|
||||
* Create a polled entry listener.
|
||||
@@ -1028,7 +1031,7 @@ void SetNetworkIdentity(StringRef name);
|
||||
* @copydoc SetNetworkIdentity(StringRef)
|
||||
* @param inst instance handle
|
||||
*/
|
||||
void SetNetworkIdentity(NT_Inst inst, StringRef name);
|
||||
void SetNetworkIdentity(NT_Inst inst, const Twine& name);
|
||||
|
||||
/**
|
||||
* Get the current network mode.
|
||||
@@ -1061,7 +1064,7 @@ void StartServer(StringRef persist_filename, const char* listen_address,
|
||||
* @copydoc StartServer(StringRef, const char*, unsigned int)
|
||||
* @param inst instance handle
|
||||
*/
|
||||
void StartServer(NT_Inst inst, StringRef persist_filename,
|
||||
void StartServer(NT_Inst inst, const Twine& persist_filename,
|
||||
const char* listen_address, unsigned int port);
|
||||
|
||||
/**
|
||||
@@ -1290,7 +1293,7 @@ const char* SavePersistent(StringRef filename);
|
||||
* @copydoc SavePersistent(StringRef)
|
||||
* @param inst instance handle
|
||||
*/
|
||||
const char* SavePersistent(NT_Inst inst, StringRef filename);
|
||||
const char* SavePersistent(NT_Inst inst, const Twine& filename);
|
||||
|
||||
/**
|
||||
* Load persistent values from a file. The server automatically does this
|
||||
@@ -1310,7 +1313,7 @@ const char* LoadPersistent(
|
||||
* @param inst instance handle
|
||||
*/
|
||||
const char* LoadPersistent(
|
||||
NT_Inst inst, StringRef filename,
|
||||
NT_Inst inst, const Twine& filename,
|
||||
std::function<void(size_t line, const char* msg)> warn);
|
||||
|
||||
/**
|
||||
@@ -1321,7 +1324,8 @@ const char* LoadPersistent(
|
||||
* @param prefix save only keys starting with this prefix
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* SaveEntries(NT_Inst inst, StringRef filename, StringRef prefix);
|
||||
const char* SaveEntries(NT_Inst inst, const Twine& filename,
|
||||
const Twine& prefix);
|
||||
|
||||
/**
|
||||
* Load table values from a file. The file format used is identical to
|
||||
@@ -1332,7 +1336,8 @@ const char* SaveEntries(NT_Inst inst, StringRef filename, StringRef prefix);
|
||||
* @param warn callback function for warnings
|
||||
* @return error string, or nullptr if successful
|
||||
*/
|
||||
const char* LoadEntries(NT_Inst inst, StringRef filename, StringRef prefix,
|
||||
const char* LoadEntries(NT_Inst inst, const Twine& filename,
|
||||
const Twine& prefix,
|
||||
std::function<void(size_t line, const char* msg)> warn);
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "llvm/StringRef.h"
|
||||
#include "llvm/Twine.h"
|
||||
#include "networktables/NetworkTableValue.h"
|
||||
#include "support/deprecated.h"
|
||||
|
||||
@@ -31,7 +32,7 @@ class WPI_DEPRECATED("Use NetworkTable directly") 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) const = 0;
|
||||
virtual bool ContainsKey(const llvm::Twine& key) const = 0;
|
||||
|
||||
/**
|
||||
* Determines whether there exists a non-empty subtable for this key
|
||||
@@ -41,7 +42,7 @@ class WPI_DEPRECATED("Use NetworkTable directly") 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) const = 0;
|
||||
virtual bool ContainsSubTable(const llvm::Twine& key) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the subtable in this table for the given name.
|
||||
@@ -49,7 +50,8 @@ class WPI_DEPRECATED("Use NetworkTable directly") ITable {
|
||||
* @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(llvm::StringRef key) const = 0;
|
||||
virtual std::shared_ptr<nt::NetworkTable> GetSubTable(
|
||||
const llvm::Twine& key) const = 0;
|
||||
|
||||
/**
|
||||
* @param types bitmask of types; 0 is treated as a "don't care".
|
||||
@@ -116,7 +118,7 @@ class WPI_DEPRECATED("Use NetworkTable directly") ITable {
|
||||
*
|
||||
* @param key the key name
|
||||
*/
|
||||
virtual void Delete(llvm::StringRef key) = 0;
|
||||
virtual void Delete(const llvm::Twine& key) = 0;
|
||||
|
||||
/**
|
||||
* Gets the value associated with a key as an object
|
||||
@@ -125,7 +127,7 @@ class WPI_DEPRECATED("Use NetworkTable directly") ITable {
|
||||
* @return the value associated with the given key, or nullptr if the key
|
||||
* does not exist
|
||||
*/
|
||||
virtual std::shared_ptr<nt::Value> GetValue(llvm::StringRef key) const = 0;
|
||||
virtual std::shared_ptr<nt::Value> GetValue(const llvm::Twine& key) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the current value in the table, setting it if it does not exist.
|
||||
@@ -133,7 +135,7 @@ class WPI_DEPRECATED("Use NetworkTable directly") ITable {
|
||||
* @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(llvm::StringRef key,
|
||||
virtual bool SetDefaultValue(const llvm::Twine& key,
|
||||
std::shared_ptr<nt::Value> defaultValue) = 0;
|
||||
|
||||
/**
|
||||
@@ -143,7 +145,7 @@ class WPI_DEPRECATED("Use NetworkTable directly") ITable {
|
||||
* @param value the value that will be assigned
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
virtual bool PutValue(llvm::StringRef key,
|
||||
virtual bool PutValue(const llvm::Twine& key,
|
||||
std::shared_ptr<nt::Value> value) = 0;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user