[DEV] add parenting between bufferManager and Buffer

This commit is contained in:
Edouard DUPIN 2014-09-12 22:10:32 +02:00
parent 996fd58370
commit 0a054c209f
2 changed files with 19 additions and 0 deletions

View File

@ -71,6 +71,7 @@ std::shared_ptr<appl::Buffer> appl::BufferManager::get(const std::string& _fileN
APPL_ERROR("Can not allocate the Buffer class : " << _fileName);
return nullptr;
}
tmp->setParent(shared_from_this());
tmp->loadFile(_fileName);
m_list.push_back(tmp);
APPL_INFO("Creata a open Buffer");
@ -128,3 +129,19 @@ void appl::BufferManager::open(const std::string& _fileName) {
signalSelectFile.emit(_fileName);
}
void appl::BufferManager::requestDestroyFromChild(const std::shared_ptr<Object>& _child) {
APPL_WARNING("Buffer request a close...");
auto it = m_list.begin();
while(it != m_list.end()) {
if (*it == nullptr) {
it = m_list.erase(it);
continue;
}
if (*it == _child) {
it = m_list.erase(it);
return;
}
++it;
}
}

View File

@ -81,6 +81,8 @@ namespace appl {
std::shared_ptr<appl::Buffer> getBufferSelected() {
return m_bufferSelected;
};
private:
void requestDestroyFromChild(const std::shared_ptr<Object>& _child);
};
};