mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Add exception-generating C++ functions, but mark as deprecated.
These are good to have for backwards compatibility, but discouraged for new development (default-taking functions should be used instead). The reason is that the exceptions must be explicitly handled and may initially work but then fail at an inopportune moment. Mark the similar Java functions as deprecated as well for the same reason. Update all the docs for consistency. Mark overridden functions as such in both C++ and Java. Make IsPersistent and GetFlags const in C++.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/StringMap.h"
|
||||
#include "tables/ITableListener.h"
|
||||
#include "tables/TableKeyNotDefinedException.h"
|
||||
#include "ntcore.h"
|
||||
|
||||
using llvm::StringRef;
|
||||
@@ -251,7 +252,7 @@ void NetworkTable::ClearPersistent(StringRef key) {
|
||||
ClearFlags(key, NT_PERSISTENT);
|
||||
}
|
||||
|
||||
bool NetworkTable::IsPersistent(StringRef key) {
|
||||
bool NetworkTable::IsPersistent(StringRef key) const {
|
||||
return (GetFlags(key) & NT_PERSISTENT) != 0;
|
||||
}
|
||||
|
||||
@@ -269,7 +270,7 @@ void NetworkTable::ClearFlags(StringRef key, unsigned int flags) {
|
||||
nt::SetEntryFlags(path, nt::GetEntryFlags(path) & ~flags);
|
||||
}
|
||||
|
||||
unsigned int NetworkTable::GetFlags(StringRef key) {
|
||||
unsigned int NetworkTable::GetFlags(StringRef key) const {
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
path += key;
|
||||
@@ -290,6 +291,16 @@ bool NetworkTable::PutNumber(StringRef key, double value) {
|
||||
return nt::SetEntryValue(path, nt::Value::MakeDouble(value));
|
||||
}
|
||||
|
||||
double NetworkTable::GetNumber(StringRef key) const {
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
path += key;
|
||||
auto value = nt::GetEntryValue(path);
|
||||
if (!value || value->type() != NT_DOUBLE)
|
||||
throw TableKeyNotDefinedException(path);
|
||||
return value->GetDouble();
|
||||
}
|
||||
|
||||
double NetworkTable::GetNumber(StringRef key, double defaultValue) const {
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
@@ -307,6 +318,16 @@ bool NetworkTable::PutString(StringRef key, StringRef value) {
|
||||
return nt::SetEntryValue(path, nt::Value::MakeString(value));
|
||||
}
|
||||
|
||||
std::string NetworkTable::GetString(StringRef key) const {
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
path += key;
|
||||
auto value = nt::GetEntryValue(path);
|
||||
if (!value || value->type() != NT_STRING)
|
||||
throw TableKeyNotDefinedException(path);
|
||||
return value->GetString();
|
||||
}
|
||||
|
||||
std::string NetworkTable::GetString(StringRef key,
|
||||
StringRef defaultValue) const {
|
||||
llvm::SmallString<128> path(m_path);
|
||||
@@ -325,6 +346,16 @@ bool NetworkTable::PutBoolean(StringRef key, bool value) {
|
||||
return nt::SetEntryValue(path, nt::Value::MakeBoolean(value));
|
||||
}
|
||||
|
||||
bool NetworkTable::GetBoolean(StringRef key) const {
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
path += key;
|
||||
auto value = nt::GetEntryValue(path);
|
||||
if (!value || value->type() != NT_BOOLEAN)
|
||||
throw TableKeyNotDefinedException(path);
|
||||
return value->GetBoolean();
|
||||
}
|
||||
|
||||
bool NetworkTable::GetBoolean(StringRef key, bool defaultValue) const {
|
||||
llvm::SmallString<128> path(m_path);
|
||||
path += PATH_SEPARATOR_CHAR;
|
||||
|
||||
Reference in New Issue
Block a user