mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
[wpilib] Add init methods to Preferences (#2443)
This commit is contained in:
committed by
GitHub
parent
b9ee3ae030
commit
8f33d21bc2
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2011-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2011-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -58,36 +58,66 @@ void Preferences::PutString(wpi::StringRef key, wpi::StringRef value) {
|
||||
entry.SetPersistent();
|
||||
}
|
||||
|
||||
void Preferences::InitString(wpi::StringRef key, wpi::StringRef value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDefaultString(value);
|
||||
}
|
||||
|
||||
void Preferences::PutInt(wpi::StringRef key, int value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDouble(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
|
||||
void Preferences::InitInt(wpi::StringRef key, int value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDefaultDouble(value);
|
||||
}
|
||||
|
||||
void Preferences::PutDouble(wpi::StringRef key, double value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDouble(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
|
||||
void Preferences::InitDouble(wpi::StringRef key, double value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDefaultDouble(value);
|
||||
}
|
||||
|
||||
void Preferences::PutFloat(wpi::StringRef key, float value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDouble(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
|
||||
void Preferences::InitFloat(wpi::StringRef key, float value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDefaultDouble(value);
|
||||
}
|
||||
|
||||
void Preferences::PutBoolean(wpi::StringRef key, bool value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetBoolean(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
|
||||
void Preferences::InitBoolean(wpi::StringRef key, bool value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDefaultBoolean(value);
|
||||
}
|
||||
|
||||
void Preferences::PutLong(wpi::StringRef key, int64_t value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDouble(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
|
||||
void Preferences::InitLong(wpi::StringRef key, int64_t value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
entry.SetDefaultDouble(value);
|
||||
}
|
||||
|
||||
bool Preferences::ContainsKey(wpi::StringRef key) {
|
||||
return m_table->ContainsKey(key);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2011-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -121,6 +121,12 @@ class Preferences : public ErrorBase {
|
||||
*/
|
||||
void PutString(wpi::StringRef key, wpi::StringRef value);
|
||||
|
||||
/**
|
||||
* Puts the given string into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitString(wpi::StringRef key, wpi::StringRef value);
|
||||
|
||||
/**
|
||||
* Puts the given int into the preferences table.
|
||||
*
|
||||
@@ -131,6 +137,12 @@ class Preferences : public ErrorBase {
|
||||
*/
|
||||
void PutInt(wpi::StringRef key, int value);
|
||||
|
||||
/**
|
||||
* Puts the given int into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitInt(wpi::StringRef key, int value);
|
||||
|
||||
/**
|
||||
* Puts the given double into the preferences table.
|
||||
*
|
||||
@@ -141,6 +153,12 @@ class Preferences : public ErrorBase {
|
||||
*/
|
||||
void PutDouble(wpi::StringRef key, double value);
|
||||
|
||||
/**
|
||||
* Puts the given double into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitDouble(wpi::StringRef key, double value);
|
||||
|
||||
/**
|
||||
* Puts the given float into the preferences table.
|
||||
*
|
||||
@@ -151,6 +169,12 @@ class Preferences : public ErrorBase {
|
||||
*/
|
||||
void PutFloat(wpi::StringRef key, float value);
|
||||
|
||||
/**
|
||||
* Puts the given float into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitFloat(wpi::StringRef key, float value);
|
||||
|
||||
/**
|
||||
* Puts the given boolean into the preferences table.
|
||||
*
|
||||
@@ -161,6 +185,12 @@ class Preferences : public ErrorBase {
|
||||
*/
|
||||
void PutBoolean(wpi::StringRef key, bool value);
|
||||
|
||||
/**
|
||||
* Puts the given boolean into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitBoolean(wpi::StringRef key, bool value);
|
||||
|
||||
/**
|
||||
* Puts the given long (int64_t) into the preferences table.
|
||||
*
|
||||
@@ -171,6 +201,12 @@ class Preferences : public ErrorBase {
|
||||
*/
|
||||
void PutLong(wpi::StringRef key, int64_t value);
|
||||
|
||||
/**
|
||||
* Puts the given long into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitLong(wpi::StringRef key, int64_t value);
|
||||
|
||||
/**
|
||||
* Returns whether or not there is a key with the given name.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -31,6 +31,7 @@ import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
|
||||
* <p> This will also interact with {@link NetworkTable} by creating a table called "Preferences"
|
||||
* with all the key-value pairs. </p>
|
||||
*/
|
||||
@SuppressWarnings("PMD.TooManyMethods")
|
||||
public final class Preferences {
|
||||
/**
|
||||
* The Preferences table name.
|
||||
@@ -94,6 +95,17 @@ public final class Preferences {
|
||||
entry.setPersistent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the given string into the preferences table if it doesn't already exist.
|
||||
*
|
||||
* @param key The key
|
||||
* @param value The value
|
||||
*/
|
||||
public void initString(String key, String value) {
|
||||
NetworkTableEntry entry = m_table.getEntry(key);
|
||||
entry.setDefaultString(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the given int into the preferences table.
|
||||
*
|
||||
@@ -106,6 +118,17 @@ public final class Preferences {
|
||||
entry.setPersistent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the given int into the preferences table if it doesn't already exist.
|
||||
*
|
||||
* @param key The key
|
||||
* @param value The value
|
||||
*/
|
||||
public void initInt(String key, int value) {
|
||||
NetworkTableEntry entry = m_table.getEntry(key);
|
||||
entry.setDefaultDouble(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the given double into the preferences table.
|
||||
*
|
||||
@@ -118,6 +141,17 @@ public final class Preferences {
|
||||
entry.setPersistent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the given double into the preferences table if it doesn't already exist.
|
||||
*
|
||||
* @param key The key
|
||||
* @param value The value
|
||||
*/
|
||||
public void initDouble(String key, double value) {
|
||||
NetworkTableEntry entry = m_table.getEntry(key);
|
||||
entry.setDefaultDouble(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the given float into the preferences table.
|
||||
*
|
||||
@@ -130,6 +164,17 @@ public final class Preferences {
|
||||
entry.setPersistent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the given float into the preferences table if it doesn't already exist.
|
||||
*
|
||||
* @param key The key
|
||||
* @param value The value
|
||||
*/
|
||||
public void initFloat(String key, float value) {
|
||||
NetworkTableEntry entry = m_table.getEntry(key);
|
||||
entry.setDefaultDouble(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the given boolean into the preferences table.
|
||||
*
|
||||
@@ -142,6 +187,17 @@ public final class Preferences {
|
||||
entry.setPersistent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the given boolean into the preferences table if it doesn't already exist.
|
||||
*
|
||||
* @param key The key
|
||||
* @param value The value
|
||||
*/
|
||||
public void initBoolean(String key, boolean value) {
|
||||
NetworkTableEntry entry = m_table.getEntry(key);
|
||||
entry.setDefaultBoolean(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the given long into the preferences table.
|
||||
*
|
||||
@@ -154,6 +210,17 @@ public final class Preferences {
|
||||
entry.setPersistent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the given long into the preferences table if it doesn't already exist.
|
||||
*
|
||||
* @param key The key
|
||||
* @param value The value
|
||||
*/
|
||||
public void initLong(String key, long value) {
|
||||
NetworkTableEntry entry = m_table.getEntry(key);
|
||||
entry.setDefaultDouble(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not there is a key with the given name.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user