85 lines
2.9 KiB
C++
85 lines
2.9 KiB
C++
#include "mapcore.h"
|
|
|
|
MapCore::MapCore()
|
|
{
|
|
|
|
}
|
|
|
|
std::shared_ptr<const DownAccess> MapCore::root() const{ return root_bind; }
|
|
|
|
void MapCore::setRoot(std::shared_ptr<const DownAccess> root) { this->root_bind = root; }
|
|
|
|
std::shared_ptr<const DownAccess> MapCore::refreshRoot(std::shared_ptr<const DownAccess> old, std::shared_ptr<const DownAccess> _new){
|
|
MapVisitor visitor(*this);
|
|
|
|
auto links = visitor.findLink(old->itemPeer());
|
|
std::function<std::shared_ptr<const DownAccess>(std::shared_ptr<const UpAccess>, std::shared_ptr<const DownAccess>)> replace_cascade =
|
|
[&replace_cascade, this](std::shared_ptr<const UpAccess> current_up, std::shared_ptr<const DownAccess> current_new) -> std::shared_ptr<const DownAccess> {
|
|
auto pinst_up = current_up->parent();
|
|
if(!pinst_up)
|
|
return current_new;
|
|
|
|
auto pinst = pinst_up->downwardPeers();
|
|
auto new_pinst = pinst->replace(current_up->downwardPeers(), current_new);
|
|
return replace_cascade(pinst_up, new_pinst);
|
|
};
|
|
|
|
this->root_bind = replace_cascade(links, _new);
|
|
return this->root_bind;
|
|
}
|
|
|
|
MapVisitor::MapVisitor(MapCore &base) : core_bind(base) {}
|
|
|
|
std::shared_ptr<const DownAccess> MapVisitor::findTarget(std::shared_ptr<const RuntimeItem> node) const{
|
|
return find_target(core_bind.root(), node);
|
|
}
|
|
|
|
std::shared_ptr<const UpAccess> MapVisitor::findLink(std::shared_ptr<const RuntimeItem> node) const
|
|
{
|
|
return this->find_link(nullptr, core_bind.root(), node);
|
|
}
|
|
|
|
QList<std::shared_ptr<const DownAccess> > MapVisitor::collect(std::function<bool (std::shared_ptr<const DownAccess>)> proc) const{
|
|
return collect(core_bind.root(), proc);
|
|
}
|
|
|
|
std::shared_ptr<const UpAccess> MapVisitor::find_link(std::shared_ptr<const UpAccess> pinst, std::shared_ptr<const DownAccess> handle, std::shared_ptr<const RuntimeItem> node) const
|
|
{
|
|
if(handle->itemPeer() == node)
|
|
return std::make_shared<UpAccess>(pinst, handle);
|
|
|
|
auto target_ptr = std::make_shared<UpAccess>(pinst, handle);
|
|
for(auto &hc : handle->members()){
|
|
auto result = find_link(target_ptr, hc, node);
|
|
if(result)
|
|
return result;
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
std::shared_ptr<const DownAccess> MapVisitor::find_target(std::shared_ptr<const DownAccess> handle, std::shared_ptr<const RuntimeItem> node) const {
|
|
if (handle->itemPeer() == node) {
|
|
return handle;
|
|
}
|
|
|
|
for (auto &it : handle->members()) {
|
|
auto result = find_target(it, node);
|
|
if (result)
|
|
return result;
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
QList<std::shared_ptr<const DownAccess> > MapVisitor::collect(std::shared_ptr<const DownAccess> handle, std::function<bool (std::shared_ptr<const DownAccess>)> proc) const {
|
|
QList<std::shared_ptr<const DownAccess>> retlist;
|
|
if(proc(handle))
|
|
retlist.append(handle);
|
|
|
|
for(auto &c : handle->members())
|
|
retlist.append(collect(c, proc));
|
|
|
|
return retlist;
|
|
}
|