Clipboard.tpp 1.21 KB
Newer Older
1
2
3

namespace corryvreckan {

4
    template <typename T> void Clipboard::put(std::shared_ptr<T> objects, const std::string& key) {
5
6
7
8
9
10
11
12
13
14
15
        // Do not insert empty sets:
        if(objects->empty()) {
            return;
        }

        // Iterator for data type:
        ClipboardData::iterator type = m_data.begin();

        /* If data type exists, returns iterator to offending key, if data type does not exist yet, creates new entry and
         * returns iterator to the newly created element
         */
16
        type = m_data.insert(type, ClipboardData::value_type(typeid(T), std::map<std::string, std::shared_ptr<void>>()));
17
18

        // Insert data into data type element, silently fail if it exists already
19
        auto test = type->second.insert(std::make_pair(key, std::static_pointer_cast<void>(objects)));
20
21
22
23
24
        if(!test.second) {
            LOG(WARNING) << "Not inserted for " << key;
        }
    }

25
    template <typename T> std::shared_ptr<T> Clipboard::get(const std::string& key) const {
26
27
28
        if(m_data.count(typeid(T)) == 0 || m_data.at(typeid(T)).count(key) == 0) {
            return nullptr;
        }
29
        return std::static_pointer_cast<T>(m_data.at(typeid(T)).at(key));
30
31
32
    }

} // namespace corryvreckan