[ntcore] Remove "using wpi" from nt namespace

This removes the nt::ArrayRef, nt::StringRef, and nt::Twine aliases.
This commit is contained in:
Peter Johnson
2021-04-04 12:40:46 -07:00
parent 79267f9e60
commit 397e569aaf
34 changed files with 460 additions and 437 deletions

View File

@@ -18,9 +18,9 @@
using namespace nt;
void Dispatcher::StartServer(const Twine& persist_filename,
void Dispatcher::StartServer(const wpi::Twine& persist_filename,
const char* listen_address, unsigned int port) {
std::string listen_address_copy(StringRef(listen_address).trim());
std::string listen_address_copy(wpi::StringRef(listen_address).trim());
DispatcherBase::StartServer(
persist_filename,
std::unique_ptr<wpi::NetworkAcceptor>(new wpi::TCPAcceptor(
@@ -28,7 +28,7 @@ void Dispatcher::StartServer(const Twine& persist_filename,
}
void Dispatcher::SetServer(const char* server_name, unsigned int port) {
std::string server_name_copy(StringRef(server_name).trim());
std::string server_name_copy(wpi::StringRef(server_name).trim());
SetConnector([=]() -> std::unique_ptr<wpi::NetworkStream> {
return wpi::TCPConnector::connect(server_name_copy.c_str(),
static_cast<int>(port), m_logger, 1);
@@ -36,7 +36,7 @@ void Dispatcher::SetServer(const char* server_name, unsigned int port) {
}
void Dispatcher::SetServer(
ArrayRef<std::pair<StringRef, unsigned int>> servers) {
wpi::ArrayRef<std::pair<wpi::StringRef, unsigned int>> servers) {
wpi::SmallVector<std::pair<std::string, int>, 16> servers_copy;
for (const auto& server : servers) {
servers_copy.emplace_back(std::string{server.first.trim()},
@@ -53,7 +53,7 @@ void Dispatcher::SetServer(
}
void Dispatcher::SetServerTeam(unsigned int team, unsigned int port) {
std::pair<StringRef, unsigned int> servers[5];
std::pair<wpi::StringRef, unsigned int> servers[5];
// 10.te.am.2
wpi::SmallString<32> fixed;
@@ -95,7 +95,7 @@ void Dispatcher::SetServerTeam(unsigned int team, unsigned int port) {
}
void Dispatcher::SetServerOverride(const char* server_name, unsigned int port) {
std::string server_name_copy(StringRef(server_name).trim());
std::string server_name_copy(wpi::StringRef(server_name).trim());
SetConnectorOverride([=]() -> std::unique_ptr<wpi::NetworkStream> {
return wpi::TCPConnector::connect(server_name_copy.c_str(),
static_cast<int>(port), m_logger, 1);
@@ -134,7 +134,7 @@ void DispatcherBase::StartLocal() {
}
void DispatcherBase::StartServer(
const Twine& persist_filename,
const wpi::Twine& persist_filename,
std::unique_ptr<wpi::NetworkAcceptor> acceptor) {
{
std::scoped_lock lock(m_user_mutex);
@@ -230,7 +230,7 @@ void DispatcherBase::SetUpdateRate(double interval) {
m_update_rate = static_cast<unsigned int>(interval * 1000);
}
void DispatcherBase::SetIdentity(const Twine& name) {
void DispatcherBase::SetIdentity(const wpi::Twine& name) {
std::scoped_lock lock(m_user_mutex);
m_identity = name.str();
}

View File

@@ -45,12 +45,12 @@ class DispatcherBase : public IDispatcher {
unsigned int GetNetworkMode() const;
void StartLocal();
void StartServer(const Twine& persist_filename,
void StartServer(const wpi::Twine& persist_filename,
std::unique_ptr<wpi::NetworkAcceptor> acceptor);
void StartClient();
void Stop();
void SetUpdateRate(double interval);
void SetIdentity(const Twine& name);
void SetIdentity(const wpi::Twine& name);
void Flush();
std::vector<ConnectionInfo> GetConnections() const;
bool IsConnected() const;
@@ -132,11 +132,12 @@ class Dispatcher : public DispatcherBase {
wpi::Logger& logger)
: DispatcherBase(storage, notifier, logger) {}
void StartServer(const Twine& persist_filename, const char* listen_address,
unsigned int port);
void StartServer(const wpi::Twine& persist_filename,
const char* listen_address, unsigned int port);
void SetServer(const char* server_name, unsigned int port);
void SetServer(ArrayRef<std::pair<StringRef, unsigned int>> servers);
void SetServer(
wpi::ArrayRef<std::pair<wpi::StringRef, unsigned int>> servers);
void SetServerTeam(unsigned int team, unsigned int port);
void SetServerOverride(const char* server_name, unsigned int port);

View File

@@ -59,7 +59,7 @@ bool impl::EntryNotifierThread::Matches(const EntryListenerData& listener,
unsigned int EntryNotifier::Add(
std::function<void(const EntryNotification& event)> callback,
StringRef prefix, unsigned int flags) {
wpi::StringRef prefix, unsigned int flags) {
if ((flags & NT_NOTIFY_LOCAL) != 0) {
m_local_notifiers = true;
}
@@ -93,7 +93,7 @@ unsigned int EntryNotifier::AddPolled(unsigned int poller_uid,
return DoAdd(poller_uid, Handle(m_inst, local_id, Handle::kEntry), flags);
}
void EntryNotifier::NotifyEntry(unsigned int local_id, StringRef name,
void EntryNotifier::NotifyEntry(unsigned int local_id, wpi::StringRef name,
std::shared_ptr<Value> value,
unsigned int flags,
unsigned int only_listener) {

View File

@@ -29,13 +29,13 @@ struct EntryListenerData
EntryListenerData() = default;
EntryListenerData(
std::function<void(const EntryNotification& event)> callback_,
StringRef prefix_, unsigned int flags_)
wpi::StringRef prefix_, unsigned int flags_)
: CallbackListenerData(callback_), prefix(prefix_), flags(flags_) {}
EntryListenerData(
std::function<void(const EntryNotification& event)> callback_,
NT_Entry entry_, unsigned int flags_)
: CallbackListenerData(callback_), entry(entry_), flags(flags_) {}
EntryListenerData(unsigned int poller_uid_, StringRef prefix_,
EntryListenerData(unsigned int poller_uid_, wpi::StringRef prefix_,
unsigned int flags_)
: CallbackListenerData(poller_uid_), prefix(prefix_), flags(flags_) {}
EntryListenerData(unsigned int poller_uid_, NT_Entry entry_,
@@ -93,7 +93,7 @@ class EntryNotifier
unsigned int AddPolled(unsigned int poller_uid, unsigned int local_id,
unsigned int flags) override;
void NotifyEntry(unsigned int local_id, StringRef name,
void NotifyEntry(unsigned int local_id, wpi::StringRef name,
std::shared_ptr<Value> value, unsigned int flags,
unsigned int only_listener = UINT_MAX) override;

View File

@@ -31,7 +31,7 @@ class IEntryNotifier {
virtual unsigned int AddPolled(unsigned int poller_uid, unsigned int local_id,
unsigned int flags) = 0;
virtual void NotifyEntry(unsigned int local_id, StringRef name,
virtual void NotifyEntry(unsigned int local_id, wpi::StringRef name,
std::shared_ptr<Value> value, unsigned int flags,
unsigned int only_listener = UINT_MAX) = 0;
};

View File

@@ -14,7 +14,7 @@ namespace nt {
class IRpcServer {
public:
typedef std::function<void(StringRef result)> SendResponseFunc;
typedef std::function<void(wpi::StringRef result)> SendResponseFunc;
IRpcServer() = default;
IRpcServer(const IRpcServer&) = delete;
@@ -24,7 +24,7 @@ class IRpcServer {
virtual void RemoveRpc(unsigned int rpc_uid) = 0;
virtual void ProcessRpc(unsigned int local_id, unsigned int call_uid,
StringRef name, StringRef params,
wpi::StringRef name, wpi::StringRef params,
const ConnectionInfo& conn,
SendResponseFunc send_response,
unsigned int rpc_uid) = 0;

View File

@@ -50,10 +50,10 @@ class IStorage {
// Filename-based save/load functions. Used both by periodic saves and
// accessible directly via the user API.
virtual const char* SavePersistent(const Twine& filename,
virtual const char* SavePersistent(const wpi::Twine& filename,
bool periodic) const = 0;
virtual const char* LoadPersistent(
const Twine& filename,
const wpi::Twine& filename,
std::function<void(size_t line, const char* msg)> warn) = 0;
};

View File

@@ -142,7 +142,7 @@ std::string NetworkConnection::remote_id() const {
return m_remote_id;
}
void NetworkConnection::set_remote_id(StringRef remote_id) {
void NetworkConnection::set_remote_id(wpi::StringRef remote_id) {
std::scoped_lock lock(m_remote_id_mutex);
m_remote_id = remote_id;
}

View File

@@ -76,7 +76,7 @@ class NetworkConnection : public INetworkConnection {
void set_state(State state) final;
std::string remote_id() const;
void set_remote_id(StringRef remote_id);
void set_remote_id(wpi::StringRef remote_id);
uint64_t last_update() const { return m_last_update; }

View File

@@ -27,7 +27,7 @@ void RpcServer::RemoveRpc(unsigned int rpc_uid) {
}
void RpcServer::ProcessRpc(unsigned int local_id, unsigned int call_uid,
StringRef name, StringRef params,
wpi::StringRef name, wpi::StringRef params,
const ConnectionInfo& conn,
SendResponseFunc send_response,
unsigned int rpc_uid) {

View File

@@ -22,8 +22,8 @@ namespace impl {
typedef std::pair<unsigned int, unsigned int> RpcIdPair;
struct RpcNotifierData : public RpcAnswer {
RpcNotifierData(NT_Entry entry_, NT_RpcCall call_, StringRef name_,
StringRef params_, const ConnectionInfo& conn_,
RpcNotifierData(NT_Entry entry_, NT_RpcCall call_, wpi::StringRef name_,
wpi::StringRef params_, const ConnectionInfo& conn_,
IRpcServer::SendResponseFunc send_response_)
: RpcAnswer{entry_, call_, name_, params_, conn_},
send_response{std::move(send_response_)} {}
@@ -93,9 +93,9 @@ class RpcServer
unsigned int AddPolled(unsigned int poller_uid);
void RemoveRpc(unsigned int rpc_uid) override;
void ProcessRpc(unsigned int local_id, unsigned int call_uid, StringRef name,
StringRef params, const ConnectionInfo& conn,
SendResponseFunc send_response,
void ProcessRpc(unsigned int local_id, unsigned int call_uid,
wpi::StringRef name, wpi::StringRef params,
const ConnectionInfo& conn, SendResponseFunc send_response,
unsigned int rpc_uid) override;
bool PostRpcResponse(unsigned int local_id, unsigned int call_uid,

View File

@@ -91,7 +91,7 @@ void Storage::ProcessIncomingEntryAssign(std::shared_ptr<Message> msg,
INetworkConnection* conn) {
std::unique_lock lock(m_mutex);
unsigned int id = msg->id();
StringRef name = msg->str();
wpi::StringRef name = msg->str();
Entry* entry;
bool may_need_update = false;
SequenceNumber seq_num(msg->seq_num_uid());
@@ -359,7 +359,7 @@ void Storage::ProcessIncomingExecuteRpc(
unsigned int call_uid = msg->seq_num_uid();
m_rpc_server.ProcessRpc(
entry->local_id, call_uid, entry->name, msg->str(), conn_info,
[=](StringRef result) {
[=](wpi::StringRef result) {
auto c = conn_weak.lock();
if (c) {
c->QueueOutgoing(Message::RpcResponse(id, call_uid, result));
@@ -442,7 +442,7 @@ void Storage::ApplyInitialAssignments(
}
SequenceNumber seq_num(msg->seq_num_uid());
StringRef name = msg->str();
wpi::StringRef name = msg->str();
Entry* entry = GetOrNew(name);
entry->seq_num = seq_num;
@@ -509,7 +509,7 @@ void Storage::ApplyInitialAssignments(
}
}
std::shared_ptr<Value> Storage::GetEntryValue(StringRef name) const {
std::shared_ptr<Value> Storage::GetEntryValue(wpi::StringRef name) const {
std::scoped_lock lock(m_mutex);
auto i = m_entries.find(name);
if (i == m_entries.end()) {
@@ -526,7 +526,7 @@ std::shared_ptr<Value> Storage::GetEntryValue(unsigned int local_id) const {
return m_localmap[local_id]->value;
}
bool Storage::SetDefaultEntryValue(StringRef name,
bool Storage::SetDefaultEntryValue(wpi::StringRef name,
std::shared_ptr<Value> value) {
if (name.empty()) {
return false;
@@ -566,7 +566,7 @@ bool Storage::SetDefaultEntryValue(unsigned int local_id,
return true;
}
bool Storage::SetEntryValue(StringRef name, std::shared_ptr<Value> value) {
bool Storage::SetEntryValue(wpi::StringRef name, std::shared_ptr<Value> value) {
if (name.empty()) {
return true;
}
@@ -664,7 +664,8 @@ void Storage::SetEntryValueImpl(Entry* entry, std::shared_ptr<Value> value,
}
}
void Storage::SetEntryTypeValue(StringRef name, std::shared_ptr<Value> value) {
void Storage::SetEntryTypeValue(wpi::StringRef name,
std::shared_ptr<Value> value) {
if (name.empty()) {
return;
}
@@ -694,7 +695,7 @@ void Storage::SetEntryTypeValue(unsigned int local_id,
SetEntryValueImpl(entry, value, lock, true);
}
void Storage::SetEntryFlags(StringRef name, unsigned int flags) {
void Storage::SetEntryFlags(wpi::StringRef name, unsigned int flags) {
if (name.empty()) {
return;
}
@@ -746,7 +747,7 @@ void Storage::SetEntryFlagsImpl(Entry* entry, unsigned int flags,
}
}
unsigned int Storage::GetEntryFlags(StringRef name) const {
unsigned int Storage::GetEntryFlags(wpi::StringRef name) const {
std::scoped_lock lock(m_mutex);
auto i = m_entries.find(name);
if (i == m_entries.end()) {
@@ -763,7 +764,7 @@ unsigned int Storage::GetEntryFlags(unsigned int local_id) const {
return m_localmap[local_id]->flags;
}
void Storage::DeleteEntry(StringRef name) {
void Storage::DeleteEntry(wpi::StringRef name) {
std::unique_lock lock(m_mutex);
auto i = m_entries.find(name);
if (i == m_entries.end()) {
@@ -872,9 +873,9 @@ void Storage::DeleteAllEntries() {
dispatcher->QueueOutgoing(Message::ClearEntries(), nullptr, nullptr);
}
Storage::Entry* Storage::GetOrNew(const Twine& name) {
Storage::Entry* Storage::GetOrNew(const wpi::Twine& name) {
wpi::SmallString<128> nameBuf;
StringRef nameStr = name.toStringRef(nameBuf);
wpi::StringRef nameStr = name.toStringRef(nameBuf);
auto& entry = m_entries[nameStr];
if (!entry) {
m_localmap.emplace_back(new Entry(nameStr));
@@ -884,7 +885,7 @@ Storage::Entry* Storage::GetOrNew(const Twine& name) {
return entry;
}
unsigned int Storage::GetEntry(const Twine& name) {
unsigned int Storage::GetEntry(const wpi::Twine& name) {
if (name.isTriviallyEmpty() ||
(name.isSingleStringRef() && name.getSingleStringRef().empty())) {
return UINT_MAX;
@@ -893,10 +894,10 @@ unsigned int Storage::GetEntry(const Twine& name) {
return GetOrNew(name)->local_id;
}
std::vector<unsigned int> Storage::GetEntries(const Twine& prefix,
std::vector<unsigned int> Storage::GetEntries(const wpi::Twine& prefix,
unsigned int types) {
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
wpi::StringRef prefixStr = prefix.toStringRef(prefixBuf);
std::scoped_lock lock(m_mutex);
std::vector<unsigned int> ids;
for (auto& i : m_entries) {
@@ -969,10 +970,10 @@ uint64_t Storage::GetEntryLastChange(unsigned int local_id) const {
return entry->value->last_change();
}
std::vector<EntryInfo> Storage::GetEntryInfo(int inst, const Twine& prefix,
std::vector<EntryInfo> Storage::GetEntryInfo(int inst, const wpi::Twine& prefix,
unsigned int types) {
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
wpi::StringRef prefixStr = prefix.toStringRef(prefixBuf);
std::scoped_lock lock(m_mutex);
std::vector<EntryInfo> infos;
for (auto& i : m_entries) {
@@ -996,11 +997,11 @@ std::vector<EntryInfo> Storage::GetEntryInfo(int inst, const Twine& prefix,
}
unsigned int Storage::AddListener(
const Twine& prefix,
const wpi::Twine& prefix,
std::function<void(const EntryNotification& event)> callback,
unsigned int flags) const {
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
wpi::StringRef prefixStr = prefix.toStringRef(prefixBuf);
std::scoped_lock lock(m_mutex);
unsigned int uid = m_notifier.Add(callback, prefixStr, flags);
// perform immediate notifications
@@ -1036,10 +1037,10 @@ unsigned int Storage::AddListener(
}
unsigned int Storage::AddPolledListener(unsigned int poller,
const Twine& prefix,
const wpi::Twine& prefix,
unsigned int flags) const {
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
wpi::StringRef prefixStr = prefix.toStringRef(prefixBuf);
std::scoped_lock lock(m_mutex);
unsigned int uid = m_notifier.AddPolled(poller, prefixStr, flags);
// perform immediate notifications
@@ -1110,11 +1111,11 @@ bool Storage::GetPersistentEntries(
}
bool Storage::GetEntries(
const Twine& prefix,
const wpi::Twine& prefix,
std::vector<std::pair<std::string, std::shared_ptr<Value>>>* entries)
const {
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
wpi::StringRef prefixStr = prefix.toStringRef(prefixBuf);
// copy values out of storage as quickly as possible so lock isn't held
{
std::scoped_lock lock(m_mutex);
@@ -1138,7 +1139,7 @@ bool Storage::GetEntries(
return true;
}
void Storage::CreateRpc(unsigned int local_id, StringRef def,
void Storage::CreateRpc(unsigned int local_id, wpi::StringRef def,
unsigned int rpc_uid) {
std::unique_lock lock(m_mutex);
if (local_id >= m_localmap.size()) {
@@ -1183,7 +1184,7 @@ void Storage::CreateRpc(unsigned int local_id, StringRef def,
}
}
unsigned int Storage::CallRpc(unsigned int local_id, StringRef params) {
unsigned int Storage::CallRpc(unsigned int local_id, wpi::StringRef params) {
std::unique_lock lock(m_mutex);
if (local_id >= m_localmap.size()) {
return 0;
@@ -1201,7 +1202,7 @@ unsigned int Storage::CallRpc(unsigned int local_id, StringRef params) {
unsigned int call_uid = entry->rpc_call_uid;
auto msg = Message::ExecuteRpc(entry->id, call_uid, params);
StringRef name{entry->name};
wpi::StringRef name{entry->name};
if (m_server) {
// RPCs are unlikely to be used locally on the server, but handle it
@@ -1217,7 +1218,7 @@ unsigned int Storage::CallRpc(unsigned int local_id, StringRef params) {
unsigned int call_uid = msg->seq_num_uid();
m_rpc_server.ProcessRpc(
local_id, call_uid, name, msg->str(), conn_info,
[=](StringRef result) {
[=](wpi::StringRef result) {
std::scoped_lock lock(m_mutex);
m_rpc_results.insert(
std::make_pair(RpcIdPair{local_id, call_uid}, result));

View File

@@ -72,35 +72,35 @@ class Storage : public IStorage {
// User functions. These are the actual implementations of the corresponding
// user API functions in ntcore_cpp.
std::shared_ptr<Value> GetEntryValue(StringRef name) const;
std::shared_ptr<Value> GetEntryValue(wpi::StringRef name) const;
std::shared_ptr<Value> GetEntryValue(unsigned int local_id) const;
bool SetDefaultEntryValue(StringRef name, std::shared_ptr<Value> value);
bool SetDefaultEntryValue(wpi::StringRef name, std::shared_ptr<Value> value);
bool SetDefaultEntryValue(unsigned int local_id,
std::shared_ptr<Value> value);
bool SetEntryValue(StringRef name, std::shared_ptr<Value> value);
bool SetEntryValue(wpi::StringRef name, std::shared_ptr<Value> value);
bool SetEntryValue(unsigned int local_id, std::shared_ptr<Value> value);
void SetEntryTypeValue(StringRef name, std::shared_ptr<Value> value);
void SetEntryTypeValue(wpi::StringRef name, std::shared_ptr<Value> value);
void SetEntryTypeValue(unsigned int local_id, std::shared_ptr<Value> value);
void SetEntryFlags(StringRef name, unsigned int flags);
void SetEntryFlags(wpi::StringRef name, unsigned int flags);
void SetEntryFlags(unsigned int local_id, unsigned int flags);
unsigned int GetEntryFlags(StringRef name) const;
unsigned int GetEntryFlags(wpi::StringRef name) const;
unsigned int GetEntryFlags(unsigned int local_id) const;
void DeleteEntry(StringRef name);
void DeleteEntry(wpi::StringRef name);
void DeleteEntry(unsigned int local_id);
void DeleteAllEntries();
std::vector<EntryInfo> GetEntryInfo(int inst, const Twine& prefix,
std::vector<EntryInfo> GetEntryInfo(int inst, const wpi::Twine& prefix,
unsigned int types);
unsigned int AddListener(
const Twine& prefix,
const wpi::Twine& prefix,
std::function<void(const EntryNotification& event)> callback,
unsigned int flags) const;
unsigned int AddListener(
@@ -108,14 +108,16 @@ class Storage : public IStorage {
std::function<void(const EntryNotification& event)> callback,
unsigned int flags) const;
unsigned int AddPolledListener(unsigned int poller_uid, const Twine& prefix,
unsigned int AddPolledListener(unsigned int poller_uid,
const wpi::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(const Twine& name);
std::vector<unsigned int> GetEntries(const Twine& prefix, unsigned int types);
unsigned int GetEntry(const wpi::Twine& name);
std::vector<unsigned int> GetEntries(const wpi::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;
@@ -123,29 +125,32 @@ class Storage : public IStorage {
// Filename-based save/load functions. Used both by periodic saves and
// accessible directly via the user API.
const char* SavePersistent(const Twine& filename,
const char* SavePersistent(const wpi::Twine& filename,
bool periodic) const override;
const char* LoadPersistent(
const Twine& filename,
const wpi::Twine& filename,
std::function<void(size_t line, const char* msg)> warn) override;
const char* SaveEntries(const Twine& filename, const Twine& prefix) const;
const char* SaveEntries(const wpi::Twine& filename,
const wpi::Twine& prefix) const;
const char* LoadEntries(
const Twine& filename, const Twine& prefix,
const wpi::Twine& filename, const wpi::Twine& prefix,
std::function<void(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(wpi::raw_ostream& os, bool periodic) const;
bool LoadEntries(wpi::raw_istream& is, const Twine& prefix, bool persistent,
bool LoadEntries(wpi::raw_istream& is, const wpi::Twine& prefix,
bool persistent,
std::function<void(size_t line, const char* msg)> warn);
void SaveEntries(wpi::raw_ostream& os, const Twine& prefix) const;
void SaveEntries(wpi::raw_ostream& os, const wpi::Twine& prefix) const;
// RPC configuration needs to come through here as RPC definitions are
// actually special Storage value types.
void CreateRpc(unsigned int local_id, StringRef def, unsigned int rpc_uid);
unsigned int CallRpc(unsigned int local_id, StringRef params);
void CreateRpc(unsigned int local_id, wpi::StringRef def,
unsigned int rpc_uid);
unsigned int CallRpc(unsigned int local_id, wpi::StringRef params);
bool GetRpcResult(unsigned int local_id, unsigned int call_uid,
std::string* result);
bool GetRpcResult(unsigned int local_id, unsigned int call_uid,
@@ -237,7 +242,7 @@ class Storage : public IStorage {
bool periodic,
std::vector<std::pair<std::string, std::shared_ptr<Value>>>* entries)
const;
bool GetEntries(const Twine& prefix,
bool GetEntries(const wpi::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 +256,7 @@ class Storage : public IStorage {
template <typename F>
void DeleteAllEntriesImpl(bool local, F should_delete);
void DeleteAllEntriesImpl(bool local);
Entry* GetOrNew(const Twine& name);
Entry* GetOrNew(const wpi::Twine& name);
};
} // namespace nt

View File

@@ -27,7 +27,7 @@ class LoadPersistentImpl {
LoadPersistentImpl(wpi::raw_istream& is, WarnFunc warn)
: m_is(is), m_warn(std::move(warn)) {}
bool Load(StringRef prefix, std::vector<Entry>* entries);
bool Load(wpi::StringRef prefix, std::vector<Entry>* entries);
private:
bool ReadLine();
@@ -138,7 +138,8 @@ static wpi::StringRef UnescapeString(wpi::StringRef source,
return wpi::StringRef{buf.data(), buf.size()};
}
bool LoadPersistentImpl::Load(StringRef prefix, std::vector<Entry>* entries) {
bool LoadPersistentImpl::Load(wpi::StringRef prefix,
std::vector<Entry>* entries) {
if (!ReadHeader()) {
return false; // header
}
@@ -373,10 +374,10 @@ std::shared_ptr<Value> LoadPersistentImpl::ReadStringArrayValue() {
}
bool Storage::LoadEntries(
wpi::raw_istream& is, const Twine& prefix, bool persistent,
wpi::raw_istream& is, const wpi::Twine& prefix, bool persistent,
std::function<void(size_t line, const char* msg)> warn) {
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
wpi::StringRef prefixStr = prefix.toStringRef(prefixBuf);
// entries to add
std::vector<LoadPersistentImpl::Entry> entries;
@@ -456,7 +457,7 @@ bool Storage::LoadEntries(
}
const char* Storage::LoadPersistent(
const Twine& filename,
const wpi::Twine& filename,
std::function<void(size_t line, const char* msg)> warn) {
std::error_code ec;
wpi::raw_fd_istream is(filename, ec);
@@ -470,7 +471,7 @@ const char* Storage::LoadPersistent(
}
const char* Storage::LoadEntries(
const Twine& filename, const Twine& prefix,
const wpi::Twine& filename, const wpi::Twine& prefix,
std::function<void(size_t line, const char* msg)> warn) {
std::error_code ec;
wpi::raw_fd_istream is(filename, ec);

View File

@@ -190,7 +190,7 @@ void Storage::SavePersistent(wpi::raw_ostream& os, bool periodic) const {
SavePersistentImpl(os).Save(entries);
}
const char* Storage::SavePersistent(const Twine& filename,
const char* Storage::SavePersistent(const wpi::Twine& filename,
bool periodic) const {
wpi::SmallString<128> fn;
filename.toVector(fn);
@@ -240,7 +240,8 @@ done:
return err;
}
void Storage::SaveEntries(wpi::raw_ostream& os, const Twine& prefix) const {
void Storage::SaveEntries(wpi::raw_ostream& os,
const wpi::Twine& prefix) const {
std::vector<SavePersistentImpl::Entry> entries;
if (!GetEntries(prefix, &entries)) {
return;
@@ -248,8 +249,8 @@ void Storage::SaveEntries(wpi::raw_ostream& os, const Twine& prefix) const {
SavePersistentImpl(os).Save(entries);
}
const char* Storage::SaveEntries(const Twine& filename,
const Twine& prefix) const {
const char* Storage::SaveEntries(const wpi::Twine& filename,
const wpi::Twine& prefix) const {
wpi::SmallString<128> fn;
filename.toVector(fn);
wpi::SmallString<128> tmp = fn;

View File

@@ -1549,7 +1549,7 @@ Java_edu_wpi_first_networktables_NetworkTablesJNI_startClient__I_3Ljava_lang_Str
}
std::vector<std::string> names;
std::vector<std::pair<nt::StringRef, unsigned int>> servers;
std::vector<std::pair<wpi::StringRef, unsigned int>> servers;
names.reserve(len);
servers.reserve(len);
for (int i = 0; i < len; ++i) {
@@ -1561,7 +1561,7 @@ Java_edu_wpi_first_networktables_NetworkTablesJNI_startClient__I_3Ljava_lang_Str
}
names.emplace_back(JStringRef{env, elem}.str());
servers.emplace_back(
std::make_pair(nt::StringRef(names.back()), portInts[i]));
std::make_pair(wpi::StringRef(names.back()), portInts[i]));
}
env->ReleaseIntArrayElements(ports, portInts, JNI_ABORT);
nt::StartClient(inst, servers);
@@ -1636,7 +1636,7 @@ Java_edu_wpi_first_networktables_NetworkTablesJNI_setServer__I_3Ljava_lang_Strin
}
std::vector<std::string> names;
std::vector<std::pair<nt::StringRef, unsigned int>> servers;
std::vector<std::pair<wpi::StringRef, unsigned int>> servers;
names.reserve(len);
servers.reserve(len);
for (int i = 0; i < len; ++i) {
@@ -1648,7 +1648,7 @@ Java_edu_wpi_first_networktables_NetworkTablesJNI_setServer__I_3Ljava_lang_Strin
}
names.emplace_back(JStringRef{env, elem}.str());
servers.emplace_back(
std::make_pair(nt::StringRef(names.back()), portInts[i]));
std::make_pair(wpi::StringRef(names.back()), portInts[i]));
}
env->ReleaseIntArrayElements(ports, portInts, JNI_ABORT);
nt::SetServer(inst, servers);

View File

@@ -15,31 +15,31 @@
using namespace nt;
StringRef NetworkTable::BasenameKey(StringRef key) {
wpi::StringRef NetworkTable::BasenameKey(wpi::StringRef key) {
size_t slash = key.rfind(PATH_SEPARATOR_CHAR);
if (slash == StringRef::npos) {
if (slash == wpi::StringRef::npos) {
return key;
}
return key.substr(slash + 1);
}
std::string NetworkTable::NormalizeKey(const Twine& key,
std::string NetworkTable::NormalizeKey(const wpi::Twine& key,
bool withLeadingSlash) {
wpi::SmallString<128> buf;
return NormalizeKey(key, buf, withLeadingSlash);
}
StringRef NetworkTable::NormalizeKey(const Twine& key,
wpi::SmallVectorImpl<char>& buf,
bool withLeadingSlash) {
wpi::StringRef NetworkTable::NormalizeKey(const wpi::Twine& key,
wpi::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
wpi::SmallString<128> keyBuf;
StringRef keyStr = key.toStringRef(keyBuf);
wpi::SmallVector<StringRef, 16> parts;
wpi::StringRef keyStr = key.toStringRef(keyBuf);
wpi::SmallVector<wpi::StringRef, 16> parts;
keyStr.split(parts, PATH_SEPARATOR_CHAR, -1, false);
for (auto i = parts.begin(); i != parts.end(); ++i) {
buf.append(i->begin(), i->end());
@@ -49,17 +49,17 @@ StringRef NetworkTable::NormalizeKey(const Twine& key,
if (!keyStr.empty() && keyStr.back() != PATH_SEPARATOR_CHAR) {
buf.pop_back();
}
return StringRef(buf.data(), buf.size());
return wpi::StringRef(buf.data(), buf.size());
}
std::vector<std::string> NetworkTable::GetHierarchy(const Twine& key) {
std::vector<std::string> NetworkTable::GetHierarchy(const wpi::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
wpi::SmallString<128> keyBuf;
StringRef keyStr = key.toStringRef(keyBuf);
wpi::StringRef keyStr = key.toStringRef(keyBuf);
wpi::SmallString<128> path;
wpi::SmallVector<StringRef, 16> parts;
wpi::SmallVector<wpi::StringRef, 16> parts;
keyStr.split(parts, PATH_SEPARATOR_CHAR, -1, false);
if (!parts.empty()) {
for (auto i = parts.begin(); i != parts.end(); ++i) {
@@ -76,7 +76,8 @@ std::vector<std::string> NetworkTable::GetHierarchy(const Twine& key) {
return hierarchy;
}
NetworkTable::NetworkTable(NT_Inst inst, const Twine& path, const private_init&)
NetworkTable::NetworkTable(NT_Inst inst, const wpi::Twine& path,
const private_init&)
: m_inst(inst), m_path(path.str()) {}
NetworkTable::~NetworkTable() {
@@ -89,13 +90,14 @@ NetworkTableInstance NetworkTable::GetInstance() const {
return NetworkTableInstance{m_inst};
}
NetworkTableEntry NetworkTable::GetEntry(const Twine& key) const {
NetworkTableEntry NetworkTable::GetEntry(const wpi::Twine& key) const {
wpi::SmallString<128> keyBuf;
StringRef keyStr = key.toStringRef(keyBuf);
wpi::StringRef keyStr = key.toStringRef(keyBuf);
std::scoped_lock lock(m_mutex);
NT_Entry& entry = m_entries[keyStr];
if (entry == 0) {
entry = nt::GetEntry(m_inst, m_path + Twine(PATH_SEPARATOR_CHAR) + keyStr);
entry =
nt::GetEntry(m_inst, m_path + wpi::Twine(PATH_SEPARATOR_CHAR) + keyStr);
}
return NetworkTableEntry{entry};
}
@@ -104,10 +106,10 @@ NT_EntryListener NetworkTable::AddEntryListener(TableEntryListener listener,
unsigned int flags) const {
size_t prefix_len = m_path.size() + 1;
return nt::AddEntryListener(
m_inst, m_path + Twine(PATH_SEPARATOR_CHAR),
m_inst, m_path + wpi::Twine(PATH_SEPARATOR_CHAR),
[=](const EntryNotification& event) {
StringRef relative_key = event.name.substr(prefix_len);
if (relative_key.find(PATH_SEPARATOR_CHAR) != StringRef::npos) {
wpi::StringRef relative_key = event.name.substr(prefix_len);
if (relative_key.find(PATH_SEPARATOR_CHAR) != wpi::StringRef::npos) {
return;
}
listener(const_cast<NetworkTable*>(this), relative_key,
@@ -116,7 +118,7 @@ NT_EntryListener NetworkTable::AddEntryListener(TableEntryListener listener,
flags);
}
NT_EntryListener NetworkTable::AddEntryListener(const Twine& key,
NT_EntryListener NetworkTable::AddEntryListener(const wpi::Twine& key,
TableEntryListener listener,
unsigned int flags) const {
size_t prefix_len = m_path.size() + 1;
@@ -147,14 +149,14 @@ NT_EntryListener NetworkTable::AddSubTableListener(TableListener listener,
flags |= NT_NOTIFY_LOCAL;
}
NT_EntryListener id = nt::AddEntryListener(
m_inst, m_path + Twine(PATH_SEPARATOR_CHAR),
m_inst, m_path + wpi::Twine(PATH_SEPARATOR_CHAR),
[=](const EntryNotification& event) {
StringRef relative_key = event.name.substr(prefix_len);
wpi::StringRef relative_key = event.name.substr(prefix_len);
auto end_sub_table = relative_key.find(PATH_SEPARATOR_CHAR);
if (end_sub_table == StringRef::npos) {
if (end_sub_table == wpi::StringRef::npos) {
return;
}
StringRef sub_table_key = relative_key.substr(0, end_sub_table);
wpi::StringRef sub_table_key = relative_key.substr(0, end_sub_table);
if (notified_tables->find(sub_table_key) == notified_tables->end()) {
return;
}
@@ -174,12 +176,12 @@ void NetworkTable::RemoveTableListener(NT_EntryListener listener) {
}
std::shared_ptr<NetworkTable> NetworkTable::GetSubTable(
const Twine& key) const {
const wpi::Twine& key) const {
return std::make_shared<NetworkTable>(
m_inst, m_path + Twine(PATH_SEPARATOR_CHAR) + key, private_init{});
m_inst, m_path + wpi::Twine(PATH_SEPARATOR_CHAR) + key, private_init{});
}
bool NetworkTable::ContainsKey(const Twine& key) const {
bool NetworkTable::ContainsKey(const wpi::Twine& key) const {
if (key.isTriviallyEmpty() ||
(key.isSingleStringRef() && key.getSingleStringRef().empty())) {
return false;
@@ -187,10 +189,10 @@ bool NetworkTable::ContainsKey(const Twine& key) const {
return GetEntry(key).Exists();
}
bool NetworkTable::ContainsSubTable(const Twine& key) const {
bool NetworkTable::ContainsSubTable(const wpi::Twine& key) const {
return !GetEntryInfo(m_inst,
m_path + Twine(PATH_SEPARATOR_CHAR) + key +
Twine(PATH_SEPARATOR_CHAR),
m_path + wpi::Twine(PATH_SEPARATOR_CHAR) + key +
wpi::Twine(PATH_SEPARATOR_CHAR),
0)
.empty();
}
@@ -198,11 +200,12 @@ bool NetworkTable::ContainsSubTable(const Twine& key) const {
std::vector<std::string> NetworkTable::GetKeys(int types) const {
std::vector<std::string> keys;
size_t prefix_len = m_path.size() + 1;
auto infos = GetEntryInfo(m_inst, m_path + Twine(PATH_SEPARATOR_CHAR), types);
auto infos =
GetEntryInfo(m_inst, m_path + wpi::Twine(PATH_SEPARATOR_CHAR), types);
std::scoped_lock lock(m_mutex);
for (auto& info : infos) {
auto relative_key = StringRef(info.name).substr(prefix_len);
if (relative_key.find(PATH_SEPARATOR_CHAR) != StringRef::npos) {
auto relative_key = wpi::StringRef(info.name).substr(prefix_len);
if (relative_key.find(PATH_SEPARATOR_CHAR) != wpi::StringRef::npos) {
continue;
}
keys.push_back(relative_key);
@@ -215,10 +218,10 @@ std::vector<std::string> NetworkTable::GetSubTables() const {
std::vector<std::string> keys;
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);
GetEntryInfo(m_inst, m_path + wpi::Twine(PATH_SEPARATOR_CHAR), 0)) {
auto relative_key = wpi::StringRef(entry.name).substr(prefix_len);
size_t end_subtable = relative_key.find(PATH_SEPARATOR_CHAR);
if (end_subtable == StringRef::npos) {
if (end_subtable == wpi::StringRef::npos) {
continue;
}
keys.push_back(relative_key.substr(0, end_subtable));
@@ -226,149 +229,157 @@ std::vector<std::string> NetworkTable::GetSubTables() const {
return keys;
}
void NetworkTable::SetPersistent(StringRef key) {
void NetworkTable::SetPersistent(wpi::StringRef key) {
GetEntry(key).SetPersistent();
}
void NetworkTable::ClearPersistent(StringRef key) {
void NetworkTable::ClearPersistent(wpi::StringRef key) {
GetEntry(key).ClearPersistent();
}
bool NetworkTable::IsPersistent(StringRef key) const {
bool NetworkTable::IsPersistent(wpi::StringRef key) const {
return GetEntry(key).IsPersistent();
}
void NetworkTable::SetFlags(StringRef key, unsigned int flags) {
void NetworkTable::SetFlags(wpi::StringRef key, unsigned int flags) {
GetEntry(key).SetFlags(flags);
}
void NetworkTable::ClearFlags(StringRef key, unsigned int flags) {
void NetworkTable::ClearFlags(wpi::StringRef key, unsigned int flags) {
GetEntry(key).ClearFlags(flags);
}
unsigned int NetworkTable::GetFlags(StringRef key) const {
unsigned int NetworkTable::GetFlags(wpi::StringRef key) const {
return GetEntry(key).GetFlags();
}
void NetworkTable::Delete(const Twine& key) {
void NetworkTable::Delete(const wpi::Twine& key) {
GetEntry(key).Delete();
}
bool NetworkTable::PutNumber(StringRef key, double value) {
bool NetworkTable::PutNumber(wpi::StringRef key, double value) {
return GetEntry(key).SetDouble(value);
}
bool NetworkTable::SetDefaultNumber(StringRef key, double defaultValue) {
bool NetworkTable::SetDefaultNumber(wpi::StringRef key, double defaultValue) {
return GetEntry(key).SetDefaultDouble(defaultValue);
}
double NetworkTable::GetNumber(StringRef key, double defaultValue) const {
double NetworkTable::GetNumber(wpi::StringRef key, double defaultValue) const {
return GetEntry(key).GetDouble(defaultValue);
}
bool NetworkTable::PutString(StringRef key, StringRef value) {
bool NetworkTable::PutString(wpi::StringRef key, wpi::StringRef value) {
return GetEntry(key).SetString(value);
}
bool NetworkTable::SetDefaultString(StringRef key, StringRef defaultValue) {
bool NetworkTable::SetDefaultString(wpi::StringRef key,
wpi::StringRef defaultValue) {
return GetEntry(key).SetDefaultString(defaultValue);
}
std::string NetworkTable::GetString(StringRef key,
StringRef defaultValue) const {
std::string NetworkTable::GetString(wpi::StringRef key,
wpi::StringRef defaultValue) const {
return GetEntry(key).GetString(defaultValue);
}
bool NetworkTable::PutBoolean(StringRef key, bool value) {
bool NetworkTable::PutBoolean(wpi::StringRef key, bool value) {
return GetEntry(key).SetBoolean(value);
}
bool NetworkTable::SetDefaultBoolean(StringRef key, bool defaultValue) {
bool NetworkTable::SetDefaultBoolean(wpi::StringRef key, bool defaultValue) {
return GetEntry(key).SetDefaultBoolean(defaultValue);
}
bool NetworkTable::GetBoolean(StringRef key, bool defaultValue) const {
bool NetworkTable::GetBoolean(wpi::StringRef key, bool defaultValue) const {
return GetEntry(key).GetBoolean(defaultValue);
}
bool NetworkTable::PutBooleanArray(StringRef key, ArrayRef<int> value) {
bool NetworkTable::PutBooleanArray(wpi::StringRef key,
wpi::ArrayRef<int> value) {
return GetEntry(key).SetBooleanArray(value);
}
bool NetworkTable::SetDefaultBooleanArray(StringRef key,
ArrayRef<int> defaultValue) {
bool NetworkTable::SetDefaultBooleanArray(wpi::StringRef key,
wpi::ArrayRef<int> defaultValue) {
return GetEntry(key).SetDefaultBooleanArray(defaultValue);
}
std::vector<int> NetworkTable::GetBooleanArray(
StringRef key, ArrayRef<int> defaultValue) const {
wpi::StringRef key, wpi::ArrayRef<int> defaultValue) const {
return GetEntry(key).GetBooleanArray(defaultValue);
}
bool NetworkTable::PutNumberArray(StringRef key, ArrayRef<double> value) {
bool NetworkTable::PutNumberArray(wpi::StringRef key,
wpi::ArrayRef<double> value) {
return GetEntry(key).SetDoubleArray(value);
}
bool NetworkTable::SetDefaultNumberArray(StringRef key,
ArrayRef<double> defaultValue) {
bool NetworkTable::SetDefaultNumberArray(wpi::StringRef key,
wpi::ArrayRef<double> defaultValue) {
return GetEntry(key).SetDefaultDoubleArray(defaultValue);
}
std::vector<double> NetworkTable::GetNumberArray(
StringRef key, ArrayRef<double> defaultValue) const {
wpi::StringRef key, wpi::ArrayRef<double> defaultValue) const {
return GetEntry(key).GetDoubleArray(defaultValue);
}
bool NetworkTable::PutStringArray(StringRef key, ArrayRef<std::string> value) {
bool NetworkTable::PutStringArray(wpi::StringRef key,
wpi::ArrayRef<std::string> value) {
return GetEntry(key).SetStringArray(value);
}
bool NetworkTable::SetDefaultStringArray(StringRef key,
ArrayRef<std::string> defaultValue) {
bool NetworkTable::SetDefaultStringArray(
wpi::StringRef key, wpi::ArrayRef<std::string> defaultValue) {
return GetEntry(key).SetDefaultStringArray(defaultValue);
}
std::vector<std::string> NetworkTable::GetStringArray(
StringRef key, ArrayRef<std::string> defaultValue) const {
wpi::StringRef key, wpi::ArrayRef<std::string> defaultValue) const {
return GetEntry(key).GetStringArray(defaultValue);
}
bool NetworkTable::PutRaw(StringRef key, StringRef value) {
bool NetworkTable::PutRaw(wpi::StringRef key, wpi::StringRef value) {
return GetEntry(key).SetRaw(value);
}
bool NetworkTable::SetDefaultRaw(StringRef key, StringRef defaultValue) {
bool NetworkTable::SetDefaultRaw(wpi::StringRef key,
wpi::StringRef defaultValue) {
return GetEntry(key).SetDefaultRaw(defaultValue);
}
std::string NetworkTable::GetRaw(StringRef key, StringRef defaultValue) const {
std::string NetworkTable::GetRaw(wpi::StringRef key,
wpi::StringRef defaultValue) const {
return GetEntry(key).GetRaw(defaultValue);
}
bool NetworkTable::PutValue(const Twine& key, std::shared_ptr<Value> value) {
bool NetworkTable::PutValue(const wpi::Twine& key,
std::shared_ptr<Value> value) {
return GetEntry(key).SetValue(value);
}
bool NetworkTable::SetDefaultValue(const Twine& key,
bool NetworkTable::SetDefaultValue(const wpi::Twine& key,
std::shared_ptr<Value> defaultValue) {
return GetEntry(key).SetDefaultValue(defaultValue);
}
std::shared_ptr<Value> NetworkTable::GetValue(const Twine& key) const {
std::shared_ptr<Value> NetworkTable::GetValue(const wpi::Twine& key) const {
return GetEntry(key).GetValue();
}
StringRef NetworkTable::GetPath() const {
wpi::StringRef NetworkTable::GetPath() const {
return m_path;
}
const char* NetworkTable::SaveEntries(const Twine& filename) const {
return nt::SaveEntries(m_inst, filename, m_path + Twine(PATH_SEPARATOR_CHAR));
const char* NetworkTable::SaveEntries(const wpi::Twine& filename) const {
return nt::SaveEntries(m_inst, filename,
m_path + wpi::Twine(PATH_SEPARATOR_CHAR));
}
const char* NetworkTable::LoadEntries(
const Twine& filename,
const wpi::Twine& filename,
std::function<void(size_t line, const char* msg)> warn) {
return nt::LoadEntries(m_inst, filename, m_path + Twine(PATH_SEPARATOR_CHAR),
warn);
return nt::LoadEntries(m_inst, filename,
m_path + wpi::Twine(PATH_SEPARATOR_CHAR), warn);
}

View File

@@ -9,8 +9,8 @@
using namespace nt;
std::shared_ptr<NetworkTable> NetworkTableInstance::GetTable(
const Twine& key) const {
StringRef simple;
const wpi::Twine& key) const {
wpi::StringRef simple;
bool isSimple = key.isSingleStringRef();
if (isSimple) {
simple = key.getSingleStringRef();
@@ -23,23 +23,23 @@ std::shared_ptr<NetworkTable> NetworkTableInstance::GetTable(
NetworkTable::private_init{});
} else {
return std::make_shared<NetworkTable>(
m_handle, Twine(NetworkTable::PATH_SEPARATOR_CHAR) + key,
m_handle, wpi::Twine(NetworkTable::PATH_SEPARATOR_CHAR) + key,
NetworkTable::private_init{});
}
}
void NetworkTableInstance::StartClient(ArrayRef<StringRef> servers,
void NetworkTableInstance::StartClient(wpi::ArrayRef<wpi::StringRef> servers,
unsigned int port) {
wpi::SmallVector<std::pair<StringRef, unsigned int>, 8> server_ports;
wpi::SmallVector<std::pair<wpi::StringRef, unsigned int>, 8> server_ports;
for (const auto& server : servers) {
server_ports.emplace_back(std::make_pair(server, port));
}
StartClient(server_ports);
}
void NetworkTableInstance::SetServer(ArrayRef<StringRef> servers,
void NetworkTableInstance::SetServer(wpi::ArrayRef<wpi::StringRef> servers,
unsigned int port) {
wpi::SmallVector<std::pair<StringRef, unsigned int>, 8> server_ports;
wpi::SmallVector<std::pair<wpi::StringRef, unsigned int>, 8> server_ports;
for (const auto& server : servers) {
server_ports.emplace_back(std::make_pair(server, port));
}
@@ -47,7 +47,7 @@ void NetworkTableInstance::SetServer(ArrayRef<StringRef> servers,
}
NT_EntryListener NetworkTableInstance::AddEntryListener(
const Twine& prefix,
const wpi::Twine& prefix,
std::function<void(const EntryNotification& event)> callback,
unsigned int flags) const {
return ::nt::AddEntryListener(m_handle, prefix, callback, flags);

View File

@@ -192,12 +192,12 @@ NT_Inst NT_GetInstanceFromHandle(NT_Handle handle) {
*/
NT_Entry NT_GetEntry(NT_Inst inst, const char* name, size_t name_len) {
return nt::GetEntry(inst, StringRef(name, name_len));
return nt::GetEntry(inst, wpi::StringRef(name, name_len));
}
NT_Entry* NT_GetEntries(NT_Inst inst, const char* prefix, size_t prefix_len,
unsigned int types, size_t* count) {
auto info_v = nt::GetEntries(inst, StringRef(prefix, prefix_len), types);
auto info_v = nt::GetEntries(inst, wpi::StringRef(prefix, prefix_len), types);
*count = info_v.size();
if (info_v.size() == 0) {
return nullptr;
@@ -266,7 +266,8 @@ void NT_DeleteAllEntries(NT_Inst inst) {
struct NT_EntryInfo* NT_GetEntryInfo(NT_Inst inst, const char* prefix,
size_t prefix_len, unsigned int types,
size_t* count) {
auto info_v = nt::GetEntryInfo(inst, StringRef(prefix, prefix_len), types);
auto info_v =
nt::GetEntryInfo(inst, wpi::StringRef(prefix, prefix_len), types);
return ConvertToC<NT_EntryInfo>(info_v, count);
}
@@ -288,7 +289,7 @@ NT_EntryListener NT_AddEntryListener(NT_Inst inst, const char* prefix,
NT_EntryListenerCallback callback,
unsigned int flags) {
return nt::AddEntryListener(
inst, StringRef(prefix, prefix_len),
inst, wpi::StringRef(prefix, prefix_len),
[=](const EntryNotification& event) {
NT_EntryNotification c_event;
ConvertToC(event, &c_event);
@@ -324,7 +325,7 @@ NT_EntryListener NT_AddPolledEntryListener(NT_EntryListenerPoller poller,
const char* prefix,
size_t prefix_len,
unsigned int flags) {
return nt::AddPolledEntryListener(poller, StringRef(prefix, prefix_len),
return nt::AddPolledEntryListener(poller, wpi::StringRef(prefix, prefix_len),
flags);
}
@@ -421,12 +422,13 @@ NT_Bool NT_WaitForConnectionListenerQueue(NT_Inst inst, double timeout) {
void NT_CreateRpc(NT_Entry entry, const char* def, size_t def_len, void* data,
NT_RpcCallback callback) {
nt::CreateRpc(entry, StringRef(def, def_len), [=](const RpcAnswer& answer) {
NT_RpcAnswer answer_c;
ConvertToC(answer, &answer_c);
callback(data, &answer_c);
NT_DisposeRpcAnswer(&answer_c);
});
nt::CreateRpc(entry, wpi::StringRef(def, def_len),
[=](const RpcAnswer& answer) {
NT_RpcAnswer answer_c;
ConvertToC(answer, &answer_c);
callback(data, &answer_c);
NT_DisposeRpcAnswer(&answer_c);
});
}
NT_RpcCallPoller NT_CreateRpcCallPoller(NT_Inst inst) {
@@ -439,7 +441,7 @@ void NT_DestroyRpcCallPoller(NT_RpcCallPoller poller) {
void NT_CreatePolledRpc(NT_Entry entry, const char* def, size_t def_len,
NT_RpcCallPoller poller) {
nt::CreatePolledRpc(entry, StringRef(def, def_len), poller);
nt::CreatePolledRpc(entry, wpi::StringRef(def, def_len), poller);
}
NT_RpcAnswer* NT_PollRpc(NT_RpcCallPoller poller, size_t* len) {
@@ -465,11 +467,11 @@ NT_Bool NT_WaitForRpcCallQueue(NT_Inst inst, double timeout) {
NT_Bool NT_PostRpcResponse(NT_Entry entry, NT_RpcCall call, const char* result,
size_t result_len) {
return nt::PostRpcResponse(entry, call, StringRef(result, result_len));
return nt::PostRpcResponse(entry, call, wpi::StringRef(result, result_len));
}
NT_RpcCall NT_CallRpc(NT_Entry entry, const char* params, size_t params_len) {
return nt::CallRpc(entry, StringRef(params, params_len));
return nt::CallRpc(entry, wpi::StringRef(params, params_len));
}
char* NT_GetRpcResult(NT_Entry entry, NT_RpcCall call, size_t* result_len) {
@@ -520,7 +522,7 @@ char* NT_PackRpcDefinition(const NT_RpcDefinition* def, size_t* packed_len) {
NT_Bool NT_UnpackRpcDefinition(const char* packed, size_t packed_len,
NT_RpcDefinition* def) {
nt::RpcDefinition def_v;
if (!nt::UnpackRpcDefinition(StringRef(packed, packed_len), &def_v)) {
if (!nt::UnpackRpcDefinition(wpi::StringRef(packed, packed_len), &def_v)) {
return 0;
}
@@ -550,8 +552,8 @@ char* NT_PackRpcValues(const NT_Value** values, size_t values_len,
NT_Value** NT_UnpackRpcValues(const char* packed, size_t packed_len,
const NT_Type* types, size_t types_len) {
auto values_v = nt::UnpackRpcValues(StringRef(packed, packed_len),
ArrayRef<NT_Type>(types, types_len));
auto values_v = nt::UnpackRpcValues(wpi::StringRef(packed, packed_len),
wpi::ArrayRef<NT_Type>(types, types_len));
if (values_v.size() == 0) {
return nullptr;
}
@@ -571,7 +573,7 @@ NT_Value** NT_UnpackRpcValues(const char* packed, size_t packed_len,
*/
void NT_SetNetworkIdentity(NT_Inst inst, const char* name, size_t name_len) {
nt::SetNetworkIdentity(inst, StringRef(name, name_len));
nt::SetNetworkIdentity(inst, wpi::StringRef(name, name_len));
}
unsigned int NT_GetNetworkMode(NT_Inst inst) {
@@ -605,7 +607,7 @@ void NT_StartClient(NT_Inst inst, const char* server_name, unsigned int port) {
void NT_StartClientMulti(NT_Inst inst, size_t count, const char** server_names,
const unsigned int* ports) {
std::vector<std::pair<StringRef, unsigned int>> servers;
std::vector<std::pair<wpi::StringRef, unsigned int>> servers;
servers.reserve(count);
for (size_t i = 0; i < count; ++i) {
servers.emplace_back(std::make_pair(server_names[i], ports[i]));
@@ -627,7 +629,7 @@ void NT_SetServer(NT_Inst inst, const char* server_name, unsigned int port) {
void NT_SetServerMulti(NT_Inst inst, size_t count, const char** server_names,
const unsigned int* ports) {
std::vector<std::pair<StringRef, unsigned int>> servers;
std::vector<std::pair<wpi::StringRef, unsigned int>> servers;
servers.reserve(count);
for (size_t i = 0; i < count; ++i) {
servers.emplace_back(std::make_pair(server_names[i], ports[i]));
@@ -679,13 +681,14 @@ const char* NT_LoadPersistent(NT_Inst inst, const char* filename,
const char* NT_SaveEntries(NT_Inst inst, const char* filename,
const char* prefix, size_t prefix_len) {
return nt::SaveEntries(inst, filename, StringRef(prefix, prefix_len));
return nt::SaveEntries(inst, filename, wpi::StringRef(prefix, prefix_len));
}
const char* NT_LoadEntries(NT_Inst inst, const char* filename,
const char* prefix, size_t prefix_len,
void (*warn)(size_t line, const char* msg)) {
return nt::LoadEntries(inst, filename, StringRef(prefix, prefix_len), warn);
return nt::LoadEntries(inst, filename, wpi::StringRef(prefix, prefix_len),
warn);
}
/*
@@ -951,23 +954,24 @@ NT_Bool NT_SetEntryBoolean(NT_Entry entry, uint64_t time, NT_Bool v_boolean,
NT_Bool NT_SetEntryString(NT_Entry entry, uint64_t time, const char* str,
size_t str_len, NT_Bool force) {
if (force != 0) {
nt::SetEntryTypeValue(entry,
Value::MakeString(StringRef(str, str_len), time));
nt::SetEntryTypeValue(
entry, Value::MakeString(wpi::StringRef(str, str_len), time));
return 1;
} else {
return nt::SetEntryValue(entry,
Value::MakeString(StringRef(str, str_len), time));
return nt::SetEntryValue(
entry, Value::MakeString(wpi::StringRef(str, str_len), time));
}
}
NT_Bool NT_SetEntryRaw(NT_Entry entry, uint64_t time, const char* raw,
size_t raw_len, NT_Bool force) {
if (force != 0) {
nt::SetEntryTypeValue(entry, Value::MakeRaw(StringRef(raw, raw_len), time));
nt::SetEntryTypeValue(entry,
Value::MakeRaw(wpi::StringRef(raw, raw_len), time));
return 1;
} else {
return nt::SetEntryValue(entry,
Value::MakeRaw(StringRef(raw, raw_len), time));
return nt::SetEntryValue(
entry, Value::MakeRaw(wpi::StringRef(raw, raw_len), time));
}
}
@@ -1128,13 +1132,14 @@ NT_Bool NT_SetDefaultEntryString(NT_Entry entry, uint64_t time,
const char* default_value,
size_t default_len) {
return nt::SetDefaultEntryValue(
entry, Value::MakeString(StringRef(default_value, default_len), time));
entry,
Value::MakeString(wpi::StringRef(default_value, default_len), time));
}
NT_Bool NT_SetDefaultEntryRaw(NT_Entry entry, uint64_t time,
const char* default_value, size_t default_len) {
return nt::SetDefaultEntryValue(
entry, Value::MakeRaw(StringRef(default_value, default_len), time));
entry, Value::MakeRaw(wpi::StringRef(default_value, default_len), time));
}
NT_Bool NT_SetDefaultEntryBooleanArray(NT_Entry entry, uint64_t time,

View File

@@ -53,7 +53,7 @@ NT_Inst GetInstanceFromHandle(NT_Handle handle) {
* Table Functions
*/
NT_Entry GetEntry(NT_Inst inst, const Twine& name) {
NT_Entry GetEntry(NT_Inst inst, const wpi::Twine& name) {
int i = Handle{inst}.GetTypedInst(Handle::kInstance);
auto ii = InstanceImpl::Get(i);
if (!ii) {
@@ -67,7 +67,7 @@ NT_Entry GetEntry(NT_Inst inst, const Twine& name) {
return Handle(i, id, Handle::kEntry);
}
std::vector<NT_Entry> GetEntries(NT_Inst inst, const Twine& prefix,
std::vector<NT_Entry> GetEntries(NT_Inst inst, const wpi::Twine& prefix,
unsigned int types) {
int i = Handle{inst}.GetTypedInst(Handle::kInstance);
auto ii = InstanceImpl::Get(i);
@@ -203,7 +203,7 @@ void DeleteAllEntries(NT_Inst inst) {
ii->storage.DeleteAllEntries();
}
std::vector<EntryInfo> GetEntryInfo(NT_Inst inst, const Twine& prefix,
std::vector<EntryInfo> GetEntryInfo(NT_Inst inst, const wpi::Twine& prefix,
unsigned int types) {
int i = Handle{inst}.GetTypedInst(Handle::kInstance);
auto ii = InstanceImpl::Get(i);
@@ -236,7 +236,7 @@ EntryInfo GetEntryInfo(NT_Entry entry) {
*/
NT_EntryListener AddEntryListener(
NT_Inst inst, const Twine& prefix,
NT_Inst inst, const wpi::Twine& prefix,
std::function<void(const EntryNotification& event)> callback,
unsigned int flags) {
int i = Handle{inst}.GetTypedInst(Handle::kInstance);
@@ -288,7 +288,7 @@ void DestroyEntryListenerPoller(NT_EntryListenerPoller poller) {
}
NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller,
const Twine& prefix,
const wpi::Twine& prefix,
unsigned int flags) {
Handle handle{poller};
int id = handle.GetTypedIndex(Handle::kEntryListenerPoller);
@@ -494,7 +494,7 @@ bool WaitForConnectionListenerQueue(NT_Inst inst, double timeout) {
* Remote Procedure Call Functions
*/
void CreateRpc(NT_Entry entry, StringRef def,
void CreateRpc(NT_Entry entry, wpi::StringRef def,
std::function<void(const RpcAnswer& answer)> callback) {
Handle handle{entry};
int id = handle.GetTypedIndex(Handle::kEntry);
@@ -535,7 +535,8 @@ void DestroyRpcCallPoller(NT_RpcCallPoller poller) {
ii->rpc_server.RemovePoller(id);
}
void CreatePolledRpc(NT_Entry entry, StringRef def, NT_RpcCallPoller poller) {
void CreatePolledRpc(NT_Entry entry, wpi::StringRef def,
NT_RpcCallPoller poller) {
Handle handle{entry};
int id = handle.GetTypedIndex(Handle::kEntry);
auto ii = InstanceImpl::Get(handle.GetInst());
@@ -607,7 +608,7 @@ bool WaitForRpcCallQueue(NT_Inst inst, double timeout) {
return ii->rpc_server.WaitForQueue(timeout);
}
bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result) {
bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, wpi::StringRef result) {
Handle handle{entry};
int id = handle.GetTypedIndex(Handle::kEntry);
auto ii = InstanceImpl::Get(handle.GetInst());
@@ -627,7 +628,7 @@ bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result) {
return ii->rpc_server.PostRpcResponse(id, call_uid, result);
}
NT_RpcCall CallRpc(NT_Entry entry, StringRef params) {
NT_RpcCall CallRpc(NT_Entry entry, wpi::StringRef params) {
Handle handle{entry};
int id = handle.GetTypedIndex(Handle::kEntry);
int i = handle.GetInst();
@@ -736,7 +737,7 @@ std::string PackRpcDefinition(const RpcDefinition& def) {
return enc.ToStringRef();
}
bool UnpackRpcDefinition(StringRef packed, RpcDefinition* def) {
bool UnpackRpcDefinition(wpi::StringRef packed, RpcDefinition* def) {
wpi::raw_mem_istream is(packed.data(), packed.size());
wpi::Logger logger;
WireDecoder dec(is, 0x0300, logger);
@@ -791,7 +792,7 @@ bool UnpackRpcDefinition(StringRef packed, RpcDefinition* def) {
return true;
}
std::string PackRpcValues(ArrayRef<std::shared_ptr<Value>> values) {
std::string PackRpcValues(wpi::ArrayRef<std::shared_ptr<Value>> values) {
WireEncoder enc(0x0300);
for (auto& value : values) {
enc.WriteValue(*value);
@@ -799,8 +800,8 @@ std::string PackRpcValues(ArrayRef<std::shared_ptr<Value>> values) {
return enc.ToStringRef();
}
std::vector<std::shared_ptr<Value>> UnpackRpcValues(StringRef packed,
ArrayRef<NT_Type> types) {
std::vector<std::shared_ptr<Value>> UnpackRpcValues(
wpi::StringRef packed, wpi::ArrayRef<NT_Type> types) {
wpi::raw_mem_istream is(packed.data(), packed.size());
wpi::Logger logger;
WireDecoder dec(is, 0x0300, logger);
@@ -823,7 +824,7 @@ uint64_t Now() {
* Client/Server Functions
*/
void SetNetworkIdentity(NT_Inst inst, const Twine& name) {
void SetNetworkIdentity(NT_Inst inst, const wpi::Twine& name) {
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
if (!ii) {
return;
@@ -859,7 +860,7 @@ void StopLocal(NT_Inst inst) {
ii->dispatcher.Stop();
}
void StartServer(NT_Inst inst, const Twine& persist_filename,
void StartServer(NT_Inst inst, const wpi::Twine& persist_filename,
const char* listen_address, unsigned int port) {
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
if (!ii) {
@@ -897,8 +898,9 @@ void StartClient(NT_Inst inst, const char* server_name, unsigned int port) {
ii->dispatcher.StartClient();
}
void StartClient(NT_Inst inst,
ArrayRef<std::pair<StringRef, unsigned int>> servers) {
void StartClient(
NT_Inst inst,
wpi::ArrayRef<std::pair<wpi::StringRef, unsigned int>> servers) {
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
if (!ii) {
return;
@@ -937,7 +939,7 @@ void SetServer(NT_Inst inst, const char* server_name, unsigned int port) {
}
void SetServer(NT_Inst inst,
ArrayRef<std::pair<StringRef, unsigned int>> servers) {
wpi::ArrayRef<std::pair<wpi::StringRef, unsigned int>> servers) {
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
if (!ii) {
return;
@@ -1013,7 +1015,7 @@ bool IsConnected(NT_Inst inst) {
* Persistent Functions
*/
const char* SavePersistent(NT_Inst inst, const Twine& filename) {
const char* SavePersistent(NT_Inst inst, const wpi::Twine& filename) {
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
if (!ii) {
return "invalid instance handle";
@@ -1023,7 +1025,7 @@ const char* SavePersistent(NT_Inst inst, const Twine& filename) {
}
const char* LoadPersistent(
NT_Inst inst, const Twine& filename,
NT_Inst inst, const wpi::Twine& filename,
std::function<void(size_t line, const char* msg)> warn) {
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
if (!ii) {
@@ -1033,8 +1035,8 @@ const char* LoadPersistent(
return ii->storage.LoadPersistent(filename, warn);
}
const char* SaveEntries(NT_Inst inst, const Twine& filename,
const Twine& prefix) {
const char* SaveEntries(NT_Inst inst, const wpi::Twine& filename,
const wpi::Twine& prefix) {
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
if (!ii) {
return "invalid instance handle";
@@ -1044,7 +1046,7 @@ const char* SaveEntries(NT_Inst inst, const Twine& filename,
}
const char* LoadEntries(
NT_Inst inst, const Twine& filename, const Twine& prefix,
NT_Inst inst, const wpi::Twine& filename, const wpi::Twine& prefix,
std::function<void(size_t line, const char* msg)> warn) {
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
if (!ii) {