Make NetworkTable constructor private/package-private. (#253)

Users should be using either NetworkTableInstance.getTable() or
NetworkTable.getSubTable().
This commit is contained in:
Peter Johnson
2017-11-12 21:57:28 -08:00
committed by GitHub
parent 51165ba0aa
commit 86d4899a54
4 changed files with 20 additions and 7 deletions

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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{});
}
}

View File

@@ -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();
/**