datacontainer.cpp 1.53 KB
Newer Older
schultezub's avatar
schultezub committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "datacontainer.h"

namespace TUMVis {
    const std::string DataContainer::loggerCat_ = "TUMVis.core.datastructures.DataContainer";

    DataContainer::DataContainer() {

    }

    DataContainer::~DataContainer() {
        // remove ownership op all owned DataHandles
        for (std::map<std::string, const DataHandle*>::iterator it = _handles.begin(); it != _handles.end(); ++it) {
            DataHandle::removeOwner(it->second, this);
        }
        _handles.clear();
    }

    const DataHandle* DataContainer::addData(const std::string& name, AbstractData* data) {
        DataHandle* dh = new DataHandle(this, data);
20
        tbb::spin_mutex::scoped_lock lock(_localMutex);
schultezub's avatar
schultezub committed
21
22
23
24
25
        _handles.insert(std::make_pair(name, dh));
        return dh;
    }

    void DataContainer::addDataHandle(const std::string& name, const DataHandle* dh) {
26
        tbb::spin_mutex::scoped_lock lock(_localMutex);
schultezub's avatar
schultezub committed
27
28
29
30
31
        _handles.insert(std::make_pair(name, dh));
        DataHandle::addOwner(dh, this);
    }

    bool DataContainer::hasData(const std::string& name) const {
32
        tbb::spin_mutex::scoped_lock lock(_localMutex);
schultezub's avatar
schultezub committed
33
34
35
36
        return (_handles.find(name) != _handles.end());
    }

    const DataHandle* DataContainer::getData(const std::string& name) const {
37
        tbb::spin_mutex::scoped_lock lock(_localMutex);
schultezub's avatar
schultezub committed
38
39
40
41
42
43
44
        std::map<std::string, const DataHandle*>::const_iterator it = _handles.find(name);
        if (it == _handles.end())
            return 0;
        else
            return it->second;
    }
}