diff --git a/include/networktables/NetworkTable.h b/include/networktables/NetworkTable.h index d2c7f8eda3..c66e10d11c 100644 --- a/include/networktables/NetworkTable.h +++ b/include/networktables/NetworkTable.h @@ -95,6 +95,13 @@ class NetworkTable : public ITable { bool ContainsSubTable(llvm::StringRef key) const; + /** + * Makes a key's value persistent through program restarts. + * + * @param key the key to make persistent + */ + void Persist(llvm::StringRef key); + /** * Maps the specified key to the specified value in this table. The key can * not be null. The value can be retrieved by calling the get method with a diff --git a/include/tables/ITable.h b/include/tables/ITable.h index d458d45ac4..adb2c12b91 100644 --- a/include/tables/ITable.h +++ b/include/tables/ITable.h @@ -43,6 +43,13 @@ class ITable { */ virtual std::shared_ptr GetSubTable(llvm::StringRef key) const = 0; + /** + * Makes a key's value persistent through program restarts. + * + * @param key the key to make persistent + */ + virtual void Persist(llvm::StringRef key) = 0; + /** * Gets the value associated with a key as an object * diff --git a/src/networktables/NetworkTable.cpp b/src/networktables/NetworkTable.cpp index e91e922070..689c7f7a64 100644 --- a/src/networktables/NetworkTable.cpp +++ b/src/networktables/NetworkTable.cpp @@ -121,6 +121,13 @@ bool NetworkTable::ContainsSubTable(StringRef key) const { return !nt::GetEntryInfo(path, 0).empty(); } +void NetworkTable::Persist(StringRef key) { + llvm::SmallString<128> path(m_path); + path += PATH_SEPARATOR_CHAR; + path += key; + nt::SetEntryFlags(path, NT_PERSISTENT); +} + void NetworkTable::PutNumber(StringRef key, double value) { llvm::SmallString<128> path(m_path); path += PATH_SEPARATOR_CHAR;