Commit 4b4be89d authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Clipboard persistent storage: throw if key doesn't exist, allow querying

parent 06f749ae
#include "Clipboard.hpp"
#include "exceptions.h"
#include "objects/Object.hpp"
using namespace corryvreckan;
......@@ -24,7 +25,15 @@ Objects* Clipboard::get(std::string name, std::string type) {
}
double Clipboard::get_persistent(std::string name) {
return m_persistent_data[name];
try {
return m_persistent_data.at(name);
} catch(std::out_of_range&) {
throw MissingDataError("Key " + name + " not available on clipboard");
}
}
bool Clipboard::has_persistent(std::string name) {
return m_persistent_data.find(name) != m_persistent_data.end();
}
void Clipboard::clear() {
......
......@@ -75,9 +75,17 @@ namespace corryvreckan {
* @brief Retrieve variable from the persistent clipboard storage
* @param name Name of the variable
* @return Stored value from the persistent clipboard storage
* @throws MissingKeyError in case the key is not found.
*/
double get_persistent(std::string name);
/**
* @brief Check if variable exists on the persistent clipboard storage
* @param name Name of the variable
* @return True if value exists, false if it does not exist.
*/
bool has_persistent(std::string name);
/**
* @brief Clear the event storage of the clipboard
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment