#include "dataprototype.h" RuntimeItem::RuntimeItem(AssembleType t) : type_store(t) {} RuntimeItem::RuntimeItem(const RuntimeItem &other) : RuntimeItem(other.baseType()) { this->listener_collection.append(other.listener_collection); } std::shared_ptr RuntimeItem::add(std::shared_ptr inst) const { if(this->listener_collection.contains(inst)) return this->shared_from_this(); auto ninst = std::const_pointer_cast(this->clone()); ninst->listener_collection.append(inst); itemNotify([ninst, this](std::shared_ptr p) { p->itemHasbeenUpdated(ninst, this->shared_from_this()); }); return ninst; } std::shared_ptr RuntimeItem::del(std::shared_ptr inst) const { if(!this->listener_collection.contains(inst)) return this->shared_from_this(); auto ninst = std::const_pointer_cast(this->clone()); ninst->listener_collection.removeAll(inst); itemNotify([ninst, this](std::shared_ptr p) { p->itemHasbeenUpdated(ninst, this->shared_from_this()); }); return ninst; } void RuntimeItem::itemNotify(std::function)> proc) const { for(auto < : listener_collection) proc(lt); } AssembleType RuntimeItem::baseType() const { return type_store; } qulonglong RuntimeItem::hashCode() const { return (qulonglong)this; } std::shared_ptr RuntimeItem::clone() const{ return std::make_shared(*this); } TypeTemplate::TypeTemplate() : RuntimeItem(AssembleType::DATAS_ASSEMBLE) {} TypeTemplate::TypeTemplate(const TypeTemplate &other) : RuntimeItem(other) { this->name_store = other.name_store; this->type_store = other.type_store; this->io_type = other.io_type; this->comps_store = other.comps_store; } QString TypeTemplate::name() const { return this->name_store; } std::shared_ptr TypeTemplate::setName(const QString &val) const{ auto ninst = std::static_pointer_cast(std::const_pointer_cast(this->clone())); ninst->name_store = val; ninst->itemNotify([ninst, this](std::shared_ptr p) { p->itemHasbeenUpdated(ninst, this->shared_from_this()); }); return ninst; } QString TypeTemplate::type() const { return this->type_store; } std::shared_ptr TypeTemplate::setType(const QString &val) const { auto ninst = std::static_pointer_cast(std::const_pointer_cast(this->clone())); ninst->name_store = val; ninst->itemNotify([ninst, this](std::shared_ptr p) { p->itemHasbeenUpdated(ninst, this->shared_from_this()); }); return ninst; } DataOritation TypeTemplate::oritation() const { return io_type; } std::shared_ptr TypeTemplate::setOritation(DataOritation t) const { auto ninst = std::static_pointer_cast(std::const_pointer_cast(this->clone())); ninst->io_type = t; ninst->itemNotify([ninst, this](std::shared_ptr p) { p->itemHasbeenUpdated(ninst, this->shared_from_this()); }); return ninst; } std::shared_ptr TypeTemplate::clone() const { return std::make_shared(*this); } DownAccess::DownAccess(std::shared_ptr peer) : runtime_item(peer) {} DownAccess::DownAccess(const DownAccess &other) { this->runtime_item = other.runtime_item; this->children_store = other.children_store; } std::shared_ptr DownAccess::itemPeer() const { return this->runtime_item; } QList > DownAccess::members() const { return this->children_store; } std::shared_ptr DownAccess::append(std::shared_ptr child_inst) const{ if(this->children_store.contains(child_inst)) return this->shared_from_this(); auto ninst = std::const_pointer_cast(this->clone()); ninst->children_store.append(child_inst); itemPeer()->itemNotify( [this, child_inst](std::shared_ptr inst) { inst->memberHasbeenAppended(*this->itemPeer(), child_inst->itemPeer()); }); return ninst; } std::shared_ptr DownAccess::remove(std::shared_ptr child_inst) const { if(!this->children_store.contains(child_inst)) return this->shared_from_this(); auto ninst = std::const_pointer_cast(this->clone()); itemPeer()->itemNotify( [this, child_inst](std::shared_ptr inst) { inst->memberAboutToBeRemove(*this->itemPeer(), child_inst->itemPeer()); }); ninst->children_store.removeAll(child_inst); return ninst; } std::shared_ptr DownAccess::replace(std::shared_ptr current, std::shared_ptr previous) const { return this->remove(previous)->append(current); } std::shared_ptr DownAccess::clone() const { return std::make_shared(*this); } UpAccess::UpAccess(std::shared_ptr parent, std::shared_ptr down):runtime_downward(down), parent_ptr(parent){} UpAccess::UpAccess(const UpAccess &other) { runtime_downward = other.runtime_downward; } std::shared_ptr UpAccess::downwardPeers() const { return this->runtime_downward; } std::shared_ptr UpAccess::parent() const { return parent_ptr; } std::shared_ptr UpAccess::clone() const { return std::make_shared(*this); }