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

@@ -267,6 +267,14 @@ class NetworkTable : public ITable {
* @return False if the table key already exists with a different type
*/
bool PutNumber(llvm::StringRef key, double value) override;
/**
* 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) override;
/**
* Gets the number associated with the given name.
@@ -301,6 +309,15 @@ class NetworkTable : public ITable {
* @return False if the table key already exists with a different type
*/
virtual bool PutString(llvm::StringRef key, llvm::StringRef value) override;
/**
* 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) override;
/**
* Gets the string associated with the given name.
@@ -336,6 +353,14 @@ class NetworkTable : public ITable {
* @return False if the table key already exists with a different type
*/
virtual bool PutBoolean(llvm::StringRef key, bool value) override;
/**
* 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) override;
/**
* Gets the boolean associated with the given name.
@@ -376,6 +401,15 @@ class NetworkTable : public ITable {
virtual bool PutBooleanArray(llvm::StringRef key,
llvm::ArrayRef<int> value) override;
/**
* 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) override;
/**
* Returns the boolean array the key maps to. If the key does not exist or is
* of different type, it will return the default value.
@@ -403,6 +437,15 @@ class NetworkTable : public ITable {
virtual bool PutNumberArray(llvm::StringRef key,
llvm::ArrayRef<double> value) override;
/**
* 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) override;
/**
* Returns the number array the key maps to. If the key does not exist or is
* of different type, it will return the default value.
@@ -426,6 +469,15 @@ class NetworkTable : public ITable {
virtual bool PutStringArray(llvm::StringRef key,
llvm::ArrayRef<std::string> value) override;
/**
* 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) override;
/**
* Returns the string array the key maps to. If the key does not exist or is
* of different type, it will return the default value.
@@ -448,6 +500,15 @@ class NetworkTable : public ITable {
* @return False if the table key already exists with a different type
*/
virtual bool PutRaw(llvm::StringRef key, llvm::StringRef value) override;
/**
* 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) override;
/**
* Returns the raw value (byte array) the key maps to. If the key does not
@@ -471,6 +532,15 @@ class NetworkTable : public ITable {
* @return False if the table key already exists with a different type
*/
bool PutValue(llvm::StringRef key, std::shared_ptr<nt::Value> value) override;
/**
* 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) override;
/**
* Gets the value associated with a key as an object