Clipboard.cpp 1.42 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
9
10
11
    m_dataID.push_back(name);
    m_data[name] = objects;
}

12
void Clipboard::put(std::string name, std::string type, Objects* objects) {
13
14
15
16
17
18
19
20
    m_dataID.push_back(name + type);
    m_data[name + type] = objects;
}

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

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

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

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

void Clipboard::clear() {
    for(auto& id : m_dataID) {
42
        Objects* collection = m_data[id];
Simon Spannagel's avatar
Simon Spannagel committed
43
        for(Objects::iterator it = collection->begin(); it != collection->end(); ++it)
44
45
46
47
48
49
50
            delete(*it);
        delete m_data[id];
        m_data.erase(id);
    }
    m_dataID.clear();
}

51
52
53
54
55
56
std::vector<std::string> Clipboard::listCollections() {
    std::vector<std::string> collections;
    for(auto& name : m_dataID) {
        collections.push_back(name);
    }
    return collections;
57
}