Clipboard.cpp 1.46 KB
Newer Older
1
#include "Clipboard.hpp"
2
#include "exceptions.h"
3
#include "objects/Object.hpp"
4
5
6

using namespace corryvreckan;

7
void Clipboard::put(std::string name, Objects* objects) {
8
    m_data.insert(ClipboardData::value_type(name, objects));
9
10
}

11
void Clipboard::put(std::string name, std::string type, Objects* objects) {
12
    m_data.insert(ClipboardData::value_type(name + type, objects));
13
14
15
16
17
18
}

void Clipboard::put_persistent(std::string name, double value) {
    m_persistent_data[name] = value;
}

19
Objects* Clipboard::get(std::string name, std::string type) {
20
21
22
    if(m_data.count(name + type) == 0) {
        return nullptr;
    }
23
24
25
26
    return m_data[name + type];
}

double Clipboard::get_persistent(std::string name) {
27
28
29
    try {
        return m_persistent_data.at(name);
    } catch(std::out_of_range&) {
Simon Spannagel's avatar
Simon Spannagel committed
30
        throw MissingDataError(name);
31
32
33
34
35
    }
}

bool Clipboard::has_persistent(std::string name) {
    return m_persistent_data.find(name) != m_persistent_data.end();
36
37
38
}

void Clipboard::clear() {
39
40
41
    for(auto set = m_data.cbegin(); set != m_data.cend();) {
        Objects* collection = set->second;
        for(Objects::iterator it = collection->begin(); it != collection->end(); ++it) {
42
            delete(*it);
43
44
45
        }
        delete collection;
        set = m_data.erase(set);
46
47
48
    }
}

49
50
std::vector<std::string> Clipboard::listCollections() {
    std::vector<std::string> collections;
51
52
    for(auto& dataset : m_data) {
        collections.push_back(dataset.first);
53
54
    }
    return collections;
55
}