Clipboard.cpp 1.18 KB
Newer Older
1
#include "Clipboard.hpp"
2
#include "objects/Object.hpp"
3
4
5

using namespace corryvreckan;

6
void Clipboard::put(std::string name, Objects* objects) {
7
8
9
10
    m_dataID.push_back(name);
    m_data[name] = objects;
}

11
void Clipboard::put(std::string name, std::string type, Objects* objects) {
12
13
14
15
16
17
18
19
    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;
}

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

double Clipboard::get_persistent(std::string name) {
    return m_persistent_data[name];
}

void Clipboard::clear() {
    for(auto& id : m_dataID) {
32
33
        Objects* collection = m_data[id];
        for(Objects::iterator it = collection->begin(); it != collection->end(); it++)
34
35
36
37
38
39
40
            delete(*it);
        delete m_data[id];
        m_data.erase(id);
    }
    m_dataID.clear();
}

41
42
43
44
45
46
std::vector<std::string> Clipboard::listCollections() {
    std::vector<std::string> collections;
    for(auto& name : m_dataID) {
        collections.push_back(name);
    }
    return collections;
47
}