Adds SetDefault methods to NetworkTables (#54)

There was no way to atomically check for a key in the table,
and then setting if it if non existant. Back before persistent
this was not a problem, however now it is, as its possible for
values to be added before team's robot programs start. This makes
the old method of calling Put*** methods in RobotInit invalid.
This adds SetDefault methods, which do this atomically.
This commit is contained in:
Thad House
2016-07-13 00:31:03 -07:00
committed by Peter Johnson
parent 6615a34e99
commit 58092c5190
15 changed files with 785 additions and 1 deletions

View File

@@ -143,6 +143,15 @@ class ITable {
* does not exist
*/
virtual std::shared_ptr<nt::Value> GetValue(llvm::StringRef key) const = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultValue(llvm::StringRef key,
std::shared_ptr<nt::Value> defaultValue) = 0;
/**
* Put a value in the table
@@ -162,6 +171,14 @@ class ITable {
* @return False if the table key already exists with a different type
*/
virtual bool PutNumber(llvm::StringRef key, double value) = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultNumber(llvm::StringRef key, double defaultValue) = 0;
/**
* Gets the number associated with the given name.
@@ -195,6 +212,15 @@ class ITable {
* @return False if the table key already exists with a different type
*/
virtual bool PutString(llvm::StringRef key, llvm::StringRef value) = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultString(llvm::StringRef key,
llvm::StringRef defaultValue) = 0;
/**
* Gets the string associated with the given name.
@@ -233,6 +259,14 @@ class ITable {
* @return False if the table key already exists with a different type
*/
virtual bool PutBoolean(llvm::StringRef key, bool value) = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultBoolean(llvm::StringRef key, bool defaultValue) = 0;
/**
* Gets the boolean associated with the given name.
@@ -271,6 +305,15 @@ class ITable {
*/
virtual bool PutBooleanArray(llvm::StringRef key,
llvm::ArrayRef<int> value) = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultBooleanArray(llvm::StringRef key,
llvm::ArrayRef<int> defaultValue) = 0;
/**
* Returns the boolean array the key maps to. If the key does not exist or is
@@ -298,6 +341,15 @@ class ITable {
*/
virtual bool PutNumberArray(llvm::StringRef key,
llvm::ArrayRef<double> value) = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultNumberArray(llvm::StringRef key,
llvm::ArrayRef<double> defaultValue) = 0;
/**
* Returns the number array the key maps to. If the key does not exist or is
@@ -321,6 +373,15 @@ class ITable {
*/
virtual bool PutStringArray(llvm::StringRef key,
llvm::ArrayRef<std::string> value) = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultStringArray(llvm::StringRef key,
llvm::ArrayRef<std::string> defaultValue) = 0;
/**
* Returns the string array the key maps to. If the key does not exist or is
@@ -343,6 +404,15 @@ class ITable {
* @return False if the table key already exists with a different type
*/
virtual bool PutRaw(llvm::StringRef key, llvm::StringRef value) = 0;
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
*/
virtual bool SetDefaultRaw(llvm::StringRef key,
llvm::StringRef defaultValue) = 0;
/**
* Returns the raw value (byte array) the key maps to. If the key does not