Commit f46d7956 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Clipboard: simplify, remove redundant information, make safer

parent f337ce26
Pipeline #573856 passed with stages
in 15 minutes and 46 seconds
......@@ -5,13 +5,11 @@
using namespace corryvreckan;
void Clipboard::put(std::string name, Objects* objects) {
m_dataID.push_back(name);
m_data[name] = objects;
m_data.insert(ClipboardData::value_type(name, objects));
}
void Clipboard::put(std::string name, std::string type, Objects* objects) {
m_dataID.push_back(name + type);
m_data[name + type] = objects;
m_data.insert(ClipboardData::value_type(name + type, objects));
}
void Clipboard::put_persistent(std::string name, double value) {
......@@ -38,20 +36,20 @@ bool Clipboard::has_persistent(std::string name) {
}
void Clipboard::clear() {
for(auto& id : m_dataID) {
Objects* collection = m_data[id];
for(Objects::iterator it = collection->begin(); it != collection->end(); ++it)
for(auto set = m_data.cbegin(); set != m_data.cend();) {
Objects* collection = set->second;
for(Objects::iterator it = collection->begin(); it != collection->end(); ++it) {
delete(*it);
delete m_data[id];
m_data.erase(id);
}
delete collection;
set = m_data.erase(set);
}
m_dataID.clear();
}
std::vector<std::string> Clipboard::listCollections() {
std::vector<std::string> collections;
for(auto& name : m_dataID) {
collections.push_back(name);
for(auto& dataset : m_data) {
collections.push_back(dataset.first);
}
return collections;
}
......@@ -98,11 +98,10 @@ namespace corryvreckan {
std::vector<std::string> listCollections();
private:
// Container for data, list of all data held
std::map<std::string, Objects*> m_data;
typedef std::map<std::string, Objects*> ClipboardData;
// List of available data collections
std::vector<std::string> m_dataID;
// Container for data, list of all data held
ClipboardData m_data;
// Persistent clipboard storage
std::unordered_map<std::string, double> m_persistent_data;
......
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