Clipboard.cpp 1.45 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
25
26
27
    if(m_data.count(name + type) == 0)
        return NULL;
    return m_data[name + type];
}

double Clipboard::get_persistent(std::string name) {
28
29
30
31
32
33
34
35
36
    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();
37
38
39
40
}

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

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