mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
Make NetworkTable constructor private/package-private. (#253)
Users should be using either NetworkTableInstance.getTable() or NetworkTable.getSubTable().
This commit is contained in:
@@ -28,7 +28,10 @@ public final class NetworkTable {
|
||||
private final String pathWithSep;
|
||||
private final NetworkTableInstance inst;
|
||||
|
||||
public NetworkTable(NetworkTableInstance inst, String path) {
|
||||
/**
|
||||
* Constructor. Use NetworkTableInstance.getTable() or getSubTable() instead.
|
||||
*/
|
||||
NetworkTable(NetworkTableInstance inst, String path) {
|
||||
this.path = path;
|
||||
this.pathWithSep = path + PATH_SEPARATOR;
|
||||
this.inst = inst;
|
||||
|
||||
@@ -124,7 +124,7 @@ std::shared_ptr<NetworkTable> NetworkTable::GetTable(StringRef key) {
|
||||
return NetworkTableInstance::GetDefault().GetTable(key);
|
||||
}
|
||||
|
||||
NetworkTable::NetworkTable(NT_Inst inst, StringRef path)
|
||||
NetworkTable::NetworkTable(NT_Inst inst, StringRef path, const private_init&)
|
||||
: m_inst(inst), m_path(path) {}
|
||||
|
||||
NetworkTable::~NetworkTable() {
|
||||
@@ -282,7 +282,7 @@ 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);
|
||||
return std::make_shared<NetworkTable>(m_inst, path, private_init{});
|
||||
}
|
||||
|
||||
bool NetworkTable::ContainsKey(StringRef key) const {
|
||||
|
||||
@@ -13,14 +13,17 @@ using namespace nt;
|
||||
std::shared_ptr<NetworkTable> NetworkTableInstance::GetTable(
|
||||
StringRef key) const {
|
||||
if (key.empty() || key == "/") {
|
||||
return std::make_shared<NetworkTable>(m_handle, "");
|
||||
return std::make_shared<NetworkTable>(m_handle, "",
|
||||
NetworkTable::private_init{});
|
||||
} else if (key[0] == NetworkTable::PATH_SEPARATOR_CHAR) {
|
||||
return std::make_shared<NetworkTable>(m_handle, key);
|
||||
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);
|
||||
return std::make_shared<NetworkTable>(m_handle, path,
|
||||
NetworkTable::private_init{});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +50,15 @@ class NetworkTable final : public ITable {
|
||||
static bool s_running;
|
||||
static unsigned int s_port;
|
||||
|
||||
struct private_init {};
|
||||
friend class NetworkTableInstance;
|
||||
|
||||
public:
|
||||
NetworkTable(NT_Inst inst, StringRef path);
|
||||
/**
|
||||
* Constructor. Use NetworkTableInstance::GetTable() or GetSubTable()
|
||||
* instead.
|
||||
*/
|
||||
NetworkTable(NT_Inst inst, StringRef path, const private_init&);
|
||||
virtual ~NetworkTable();
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user