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

@@ -165,6 +165,15 @@ public interface ITable {
* @return False if the table key already exists with a different type
*/
public boolean putNumber(String key, double value);
/**
* 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 doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultNumber(String key, double defaultValue);
/**
* Returns the number the key maps to.
* @param key the key to look up
@@ -193,6 +202,15 @@ public interface ITable {
* @return False if the table key already exists with a different type
*/
public boolean putString(String key, String value);
/**
* 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 doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultString(String key, String defaultValue);
/**
* Returns the string the key maps to.
* @param key the key to look up
@@ -221,6 +239,15 @@ public interface ITable {
* @return False if the table key already exists with a different type
*/
public boolean putBoolean(String key, boolean value);
/**
* 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 doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultBoolean(String key, boolean defaultValue);
/**
* Returns the boolean the key maps to.
* @param key the key to look up
@@ -249,6 +276,15 @@ public interface ITable {
* @return False if the table key already exists with a different type
*/
public boolean putBooleanArray(String key, boolean[] value);
/**
* 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 doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultBooleanArray(String key, boolean[] defaultValue);
/**
* Put a boolean array in the table
* @param key the key to be assigned to
@@ -256,6 +292,15 @@ public interface ITable {
* @return False if the table key already exists with a different type
*/
public boolean putBooleanArray(String key, Boolean[] value);
/**
* 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 doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultBooleanArray(String key, Boolean[] defaultValue);
/**
* Returns the boolean array the key maps to.
* @param key the key to look up
@@ -293,6 +338,15 @@ public interface ITable {
* @return False if the table key already exists with a different type
*/
public boolean putNumberArray(String key, double[] value);
/**
* 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 doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultNumberArray(String key, double[] defaultValue);
/**
* Put a number array in the table
* @param key the key to be assigned to
@@ -300,6 +354,15 @@ public interface ITable {
* @return False if the table key already exists with a different type
*/
public boolean putNumberArray(String key, Double[] value);
/**
* 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 doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultNumberArray(String key, Double[] defaultValue);
/**
* Returns the number array the key maps to.
* @param key the key to look up
@@ -337,6 +400,15 @@ public interface ITable {
* @return False if the table key already exists with a different type
*/
public boolean putStringArray(String key, String[] value);
/**
* 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 doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultStringArray(String key, String[] defaultValue);
/**
* Returns the string array the key maps to.
* @param key the key to look up
@@ -365,6 +437,15 @@ public interface ITable {
* @return False if the table key already exists with a different type
*/
public boolean putRaw(String key, byte[] value);
/**
* 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 doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultRaw(String key, byte[] defaultValue);
/**
* Put a raw value (bytes from a byte buffer) in the table
* @param key the key to be assigned to