[wpilib] Add init methods to Preferences (#2443)

This commit is contained in:
Prateek Machiraju
2020-04-01 23:26:49 -04:00
committed by GitHub
parent b9ee3ae030
commit 8f33d21bc2
3 changed files with 136 additions and 3 deletions

View File

@@ -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);
}

View File

@@ -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.
*