2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2015-06-25 15:07:55 -04:00
|
|
|
/* Copyright (c) FIRST 2011. All Rights Reserved.
|
|
|
|
|
*/
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
2014-05-02 17:54:01 -04:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
#include "ErrorBase.h"
|
|
|
|
|
#include "Task.h"
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2015-06-25 01:54:20 -07:00
|
|
|
#include "HAL/cpp/Semaphore.hpp"
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "tables/ITableListener.h"
|
|
|
|
|
#include "networktables/NetworkTable.h"
|
|
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* The preferences class provides a relatively simple way to save important
|
|
|
|
|
* values to
|
2014-08-05 11:17:38 -04:00
|
|
|
* the RoboRIO to access the next time the RoboRIO is booted.
|
2013-12-15 18:30:16 -05:00
|
|
|
*
|
|
|
|
|
* <p>This class loads and saves from a file
|
2015-06-25 15:07:55 -04:00
|
|
|
* inside the RoboRIO. The user can not access the file directly, but may
|
|
|
|
|
* modify values at specific
|
2015-08-13 23:17:19 -07:00
|
|
|
* fields which will then be automatically periodically saved to the file
|
|
|
|
|
* by the NetworkTable server.</p>
|
2013-12-15 18:30:16 -05:00
|
|
|
*
|
|
|
|
|
* <p>This class is thread safe.</p>
|
|
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* <p>This will also interact with {@link NetworkTable} by creating a table
|
2015-08-13 23:17:19 -07:00
|
|
|
* called "Preferences" with all the key-value pairs.</p>
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-08-13 23:17:19 -07:00
|
|
|
class Preferences : public ErrorBase {
|
2015-06-25 15:07:55 -04:00
|
|
|
public:
|
|
|
|
|
static Preferences *GetInstance();
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
std::vector<std::string> GetKeys();
|
2015-08-13 23:17:19 -07:00
|
|
|
std::string GetString(llvm::StringRef key, llvm::StringRef defaultValue = "");
|
|
|
|
|
int GetInt(llvm::StringRef key, int defaultValue = 0);
|
|
|
|
|
double GetDouble(llvm::StringRef key, double defaultValue = 0.0);
|
|
|
|
|
float GetFloat(llvm::StringRef key, float defaultValue = 0.0);
|
|
|
|
|
bool GetBoolean(llvm::StringRef key, bool defaultValue = false);
|
|
|
|
|
int64_t GetLong(llvm::StringRef key, int64_t defaultValue = 0);
|
|
|
|
|
void PutString(llvm::StringRef key, llvm::StringRef value);
|
|
|
|
|
void PutInt(llvm::StringRef key, int value);
|
|
|
|
|
void PutDouble(llvm::StringRef key, double value);
|
|
|
|
|
void PutFloat(llvm::StringRef key, float value);
|
|
|
|
|
void PutBoolean(llvm::StringRef key, bool value);
|
|
|
|
|
void PutLong(llvm::StringRef key, int64_t value);
|
2015-09-23 23:44:54 -07:00
|
|
|
DEPRECATED(
|
|
|
|
|
"Saving is now automatically performed by the NetworkTables server.")
|
2015-06-25 15:07:55 -04:00
|
|
|
void Save();
|
2015-08-13 23:17:19 -07:00
|
|
|
bool ContainsKey(llvm::StringRef key);
|
|
|
|
|
void Remove(llvm::StringRef key);
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
protected:
|
|
|
|
|
Preferences();
|
2015-06-25 01:54:20 -07:00
|
|
|
virtual ~Preferences() = default;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
private:
|
2015-08-13 23:17:19 -07:00
|
|
|
std::shared_ptr<ITable> m_table;
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|