Commit cb115aec authored by Jens Kroeger's avatar Jens Kroeger
Browse files

Merge branch 'clipboard_remove' into 'master'

Clipboard: add methods to remove data from the clipboard again

See merge request !409
parents c3c2f87a 279919a4
Pipeline #2562778 passed with stages
in 22 minutes and 25 seconds
......@@ -84,6 +84,20 @@ namespace corryvreckan {
*/
template <typename T> std::vector<std::shared_ptr<T>>& getData(const std::string& key = "") const;
/**
* @brief Method to remove an existing object from the clipboard
* @param object Shared pointer of the object to be removed
* @param key Identifying key for the set this object belongs to. Defaults to empty key
*/
template <typename T> void removeData(std::shared_ptr<T> object, const std::string& key = "");
/**
* @brief Method to remove existing objects from the clipboard
* @param object List of objects to be removed
* @param key Identifying key for the set these objects belongs to. Defaults to empty key
*/
template <typename T> void removeData(std::vector<std::shared_ptr<T>>& objects, const std::string& key = "");
/**
* @brief Method to count the number of objects of a given type on the clipboard
* @param key Identifying key of objects to be counted. An empty key will count all objects available.
......@@ -150,12 +164,29 @@ namespace corryvreckan {
*/
void clear();
/**
* Helper to put new data onto clipboard
* @param storage_element The storage element of the clipboard to store data in
* @param objects Data to be stored
* @param key Key under which data will be stored
* @param append Flag whether data should be appended to existing key or not
*/
template <typename T>
void put_data(ClipboardData& storage_element,
std::vector<std::shared_ptr<T>> objects,
const std::string& key,
bool append = false);
/**
* Helper to remove a set of objects from the clipboard
* @param storage_element Storage element concerned
* @param objects Objects to be removed
* @param key Key under which objects should be searched
*/
template <typename T>
void
remove_data(ClipboardData& storage_element, const std::vector<std::shared_ptr<T>>& objects, const std::string& key);
// Container for data, list of all data held
ClipboardData data_;
......
......@@ -16,6 +16,14 @@ namespace corryvreckan {
put_data(data_, std::move(objects), key);
}
template <typename T> void Clipboard::removeData(std::shared_ptr<T> object, const std::string& key) {
remove_data(data_, std::vector<std::shared_ptr<T>>{std::move(object)}, key);
}
template <typename T> void Clipboard::removeData(std::vector<std::shared_ptr<T>>& objects, const std::string& key) {
remove_data(data_, std::move(objects), key);
}
template <typename T> std::vector<std::shared_ptr<T>>& Clipboard::getData(const std::string& key) const {
return get_data<T>(data_, key);
}
......@@ -99,6 +107,24 @@ namespace corryvreckan {
}
}
template <typename T>
void Clipboard::remove_data(ClipboardData& storage_element,
const std::vector<std::shared_ptr<T>>& objects,
const std::string& key) {
// Try to get existing objects:
if(storage_element.count(typeid(T)) == 0 || storage_element.at(typeid(T)).count(key) == 0) {
return;
}
auto data = std::static_pointer_cast<std::vector<std::shared_ptr<T>>>(storage_element.at(typeid(T)).at(key));
for(const auto& object : objects) {
auto object_iterator = std::find(data->begin(), data->end(), object);
if(object_iterator != data->end()) {
data->erase(object_iterator);
}
}
}
template <typename T>
std::vector<std::shared_ptr<T>>& ReadonlyClipboard::get_data(const ClipboardData& storage_element,
const std::string& key) const {
......
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