From 5f3ec2237738b82d3c28b7a7dd023de633dc7352 Mon Sep 17 00:00:00 2001 From: Chunel Date: Sat, 7 Mar 2026 15:17:46 +0800 Subject: [PATCH] [delete] delete getChildren api --- src/GraphCtrl/GraphElement/GElement.cpp | 8 +------- src/GraphCtrl/GraphElement/GElement.h | 7 +------ src/GraphCtrl/GraphElement/GElement.inl | 2 +- .../GraphElement/GElementRepository.cpp | 2 +- .../GraphElement/GGroup/GCluster/GCluster.cpp | 6 +++--- .../GGroup/GCondition/GCondition.cpp | 12 ++++++------ .../GGroup/GCondition/GMultiCondition.inl | 6 +++--- src/GraphCtrl/GraphElement/GGroup/GGroup.cpp | 17 ++++++----------- src/GraphCtrl/GraphElement/GGroup/GGroup.h | 5 ----- .../GraphElement/GGroup/GMutable/GMutable.cpp | 8 ++++---- .../GraphElement/GGroup/GSome/GSome.inl | 10 +++++----- .../GraphPipeline/_GStroage/GStorageDefine.h | 2 +- 12 files changed, 32 insertions(+), 53 deletions(-) diff --git a/src/GraphCtrl/GraphElement/GElement.cpp b/src/GraphCtrl/GraphElement/GElement.cpp index ba4e8a11..b4a8061b 100644 --- a/src/GraphCtrl/GraphElement/GElement.cpp +++ b/src/GraphCtrl/GraphElement/GElement.cpp @@ -504,7 +504,7 @@ GElementRelation GElement::getRelation() const { GElementRelation relation; relation.predecessors_ = this->dependence_.asVector(); // 前驱 relation.successors_ = this->run_before_.asVector(); // 后继 - relation.children_ = this->getChildren(); + relation.children_ = this->children_; relation.belong_ = this->belong_; // 从属信息 return relation; @@ -595,12 +595,6 @@ GElementPtrArr GElement::getDeepPath(CBool reverse) const { } -GElementPtrArr GElement::getChildren() const { - (void)(this); - return GElementPtrArr{}; -} - - CBool GElement::isDefaultBinding() const { return CGRAPH_DEFAULT_BINDING_INDEX == binding_index_; } diff --git a/src/GraphCtrl/GraphElement/GElement.h b/src/GraphCtrl/GraphElement/GElement.h index 7d4247b2..38c8bfaa 100644 --- a/src/GraphCtrl/GraphElement/GElement.h +++ b/src/GraphCtrl/GraphElement/GElement.h @@ -436,12 +436,6 @@ class GElement : public GElementObject, */ GElement* updateAspectInfo(); - /** - * 获取其中包含的内容 - * @return - * @notice 仅在为 group 的情况下有意义 - */ - virtual std::vector getChildren() const; private: /** 状态相关信息 */ @@ -472,6 +466,7 @@ class GElement : public GElementObject, USmallVector run_before_ {}; // 被依赖的节点(后继) USmallVector dependence_ {}; // 依赖的节点信息(前驱) GElement* belong_ { nullptr }; // 从属的element 信息,如为nullptr,则表示从属于 pipeline + std::vector children_ {}; // 子节点,适用于group类型 /** 异步执行相关信息 */ std::future async_result_; // 用于记录当前节点的异步执行情况 diff --git a/src/GraphCtrl/GraphElement/GElement.inl b/src/GraphCtrl/GraphElement/GElement.inl index 61907470..0347a92e 100644 --- a/src/GraphCtrl/GraphElement/GElement.inl +++ b/src/GraphCtrl/GraphElement/GElement.inl @@ -65,7 +65,7 @@ GElementPtr GElement::addEParam(const std::string& key, T* param) { template::value, int>> T* GElement::getEParam(const std::string& key) { - auto iter = local_params_.find(key); + const auto iter = local_params_.find(key); if (iter == local_params_.end()) { return nullptr; } diff --git a/src/GraphCtrl/GraphElement/GElementRepository.cpp b/src/GraphCtrl/GraphElement/GElementRepository.cpp index 94adc2f7..40fc7496 100644 --- a/src/GraphCtrl/GraphElement/GElementRepository.cpp +++ b/src/GraphCtrl/GraphElement/GElementRepository.cpp @@ -95,7 +95,7 @@ CVoid GElementRepository::fetch(GElementPtr element) { if (element->isGGroup()) { auto group = dynamic_cast(element); CGRAPH_ASSERT_NOT_NULL_THROW_ERROR(group) - for (auto* cur : group->group_elements_arr_) { + for (auto* cur : group->children_) { fetch(cur); } } diff --git a/src/GraphCtrl/GraphElement/GGroup/GCluster/GCluster.cpp b/src/GraphCtrl/GraphElement/GGroup/GCluster/GCluster.cpp index 8431a1cd..caf10988 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GCluster/GCluster.cpp +++ b/src/GraphCtrl/GraphElement/GGroup/GCluster/GCluster.cpp @@ -18,7 +18,7 @@ GCluster::GCluster() { CStatus GCluster::run() { CGRAPH_FUNCTION_BEGIN - for (GElementPtr element : this->group_elements_arr_) { + for (GElementPtr element : this->children_) { status = element->fatProcessor(CFunctionType::RUN); CGRAPH_FUNCTION_CHECK_STATUS } @@ -34,8 +34,8 @@ CVoid GCluster::dump(std::ostream& oss) { oss << "color=blue;\n"; GElementPtr pre = nullptr; - for (CSize i = 0; i < group_elements_arr_.size(); i++) { - const auto& element = group_elements_arr_[i]; + for (CSize i = 0; i < children_.size(); i++) { + const auto& element = children_[i]; element->dump(oss); if (0 != i) { diff --git a/src/GraphCtrl/GraphElement/GGroup/GCondition/GCondition.cpp b/src/GraphCtrl/GraphElement/GGroup/GCondition/GCondition.cpp index 18bf14af..3615429e 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GCondition/GCondition.cpp +++ b/src/GraphCtrl/GraphElement/GGroup/GCondition/GCondition.cpp @@ -21,13 +21,13 @@ CStatus GCondition::run() { CIndex index = this->choose(); if (internal::CGRAPH_CONDITION_LAST_INDEX == index - && !this->group_elements_arr_.empty()) { + && !this->children_.empty()) { // 如果返回-1,则直接执行最后一个条件(模仿default功能) - auto element = group_elements_arr_.back(); + auto element = children_.back(); status = element->fatProcessor(CFunctionType::RUN); - } else if (0 <= index && index < (CIndex)group_elements_arr_.size()) { + } else if (0 <= index && index < (CIndex)children_.size()) { // 如果返回的内容,在元素范围之内,则直接执行元素的内容。不在的话,则不执行任何操作,直接返回正确状态 - auto element = group_elements_arr_[index]; + auto element = children_[index]; status = element->fatProcessor(CFunctionType::RUN); } @@ -41,8 +41,8 @@ CVoid GCondition::dump(std::ostream& oss) { oss << 'p' << this << "[shape=diamond];\n"; oss << "color=blue;\n"; - for (CSize i = 0; i < group_elements_arr_.size(); ++i) { - const auto& cur = group_elements_arr_[i]; + for (CSize i = 0; i < children_.size(); ++i) { + const auto& cur = children_[i]; cur->dump(oss); const std::string& label = "[label=\"" + std::to_string(i) + "\"]"; diff --git a/src/GraphCtrl/GraphElement/GGroup/GCondition/GMultiCondition.inl b/src/GraphCtrl/GraphElement/GGroup/GCondition/GMultiCondition.inl index 366a8eed..80e4d776 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GCondition/GMultiCondition.inl +++ b/src/GraphCtrl/GraphElement/GGroup/GCondition/GMultiCondition.inl @@ -43,7 +43,7 @@ template CStatus GMultiCondition::serialRun() { CGRAPH_FUNCTION_BEGIN - for (auto cur: this->group_elements_arr_) { + for (auto* cur: this->children_) { if (cur->isMatch()) { // 仅依次执行 match 的逻辑 status = cur->fatProcessor(CFunctionType::RUN); @@ -59,7 +59,7 @@ template CStatus GMultiCondition::parallelRun() { CGRAPH_FUNCTION_BEGIN std::vector > futures; - for (GElementPtr cur : this->group_elements_arr_) { + for (auto* cur : this->children_) { if (!cur->isMatch()) { continue; // 不满足条件,则不执行 } @@ -91,7 +91,7 @@ CIndex GMultiCondition::choose() { template CBool GMultiCondition::isSerializable() const { - if (GMultiConditionType::PARALLEL == type && group_elements_arr_.size() > 1) { + if (GMultiConditionType::PARALLEL == type && children_.size() > 1) { /** * 如果是PARALLEL模式的话,并且其中的元素个数大于1,则一定不可以串行执行 * PARALLEL模式中,仅有一个元素的情况,和 SERIAL模式的判断方式一样, diff --git a/src/GraphCtrl/GraphElement/GGroup/GGroup.cpp b/src/GraphCtrl/GraphElement/GGroup/GGroup.cpp index 1e07df32..a4deac31 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GGroup.cpp +++ b/src/GraphCtrl/GraphElement/GGroup/GGroup.cpp @@ -17,7 +17,7 @@ GGroup::GGroup() { CStatus GGroup::init() { CGRAPH_FUNCTION_BEGIN - for (GElementPtr element : group_elements_arr_) { + for (GElementPtr element : children_) { CGRAPH_ASSERT_NOT_NULL(element) status += element->fatProcessor(CFunctionType::INIT); } @@ -31,7 +31,7 @@ CStatus GGroup::init() { CStatus GGroup::destroy() { CGRAPH_FUNCTION_BEGIN - for (GElementPtr element : group_elements_arr_) { + for (GElementPtr element : children_) { CGRAPH_ASSERT_NOT_NULL(element) status += element->fatProcessor(CFunctionType::DESTROY); } @@ -46,7 +46,7 @@ CStatus GGroup::addElement(GElementPtr element) { CGRAPH_FUNCTION_BEGIN CGRAPH_ASSERT_NOT_NULL(element) - this->group_elements_arr_.emplace_back(element); + this->children_.emplace_back(element); element->belong_ = this; // 在这里不要进行判断返回值,因为可能是region刚刚创建的时候,还没被写入 pipeline中 element->addManagers(param_manager_, event_manager_, stage_manager_); @@ -61,11 +61,6 @@ CStatus GGroup::addElementEx(GElementPtr element) { } -GElementPtrArr GGroup::getChildren() const { - return group_elements_arr_; -} - - CVoid GGroup::dumpGroupLabelBegin(std::ostream& oss) { oss << "subgraph "; oss << "cluster_p" << this; // cluster_ 是 graphviz的关键字,和CGraph中GCluster逻辑无关 @@ -97,7 +92,7 @@ CBool GGroup::isSerializable() const { * 针对group的情况,应该是所有在其中的element 都是可以串行的,才认定为可串行 * 但是在 region和 multiCondition中,有针对性的判断 */ - return std::all_of(group_elements_arr_.begin(), group_elements_arr_.end(), + return std::all_of(children_.begin(), children_.end(), [](GElementPtr element) { return element->isSerializable(); }); @@ -114,7 +109,7 @@ CStatus GGroup::addManagers(GParamManagerPtr paramManager, status = GElement::addManagers(paramManager, eventManager, stageManager); CGRAPH_FUNCTION_CHECK_STATUS - for (GElementPtr element : group_elements_arr_) { + for (auto* element : children_) { CGRAPH_ASSERT_NOT_NULL(element) status += element->addManagers(paramManager, eventManager, stageManager); } @@ -131,7 +126,7 @@ CBool GGroup::isSeparate(GElementCPtr a, GElementCPtr b) const { CStatus GGroup::__addGElements_4py(const GElementPtrArr& elements) { CGRAPH_FUNCTION_BEGIN CGRAPH_ASSERT_INIT(false) - for (GElementPtr element : elements) { + for (auto* element : elements) { status += addElement(element); } CGRAPH_FUNCTION_END diff --git a/src/GraphCtrl/GraphElement/GGroup/GGroup.h b/src/GraphCtrl/GraphElement/GGroup/GGroup.h index 1572f002..1d81413e 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GGroup.h +++ b/src/GraphCtrl/GraphElement/GGroup/GGroup.h @@ -46,8 +46,6 @@ class GGroup : public GElement { CStatus destroy() override; - GElementPtrArr getChildren() const override; - /** * 生成graphviz中 group对应的label 的开头信息 * @param oss @@ -71,9 +69,6 @@ class GGroup : public GElement { */ virtual CBool isSeparate(GElementCPtr a, GElementCPtr b) const; -private: - GElementPtrArr group_elements_arr_; // 存放 element的数组 - friend class GPipeline; friend class GCluster; friend class GRegion; diff --git a/src/GraphCtrl/GraphElement/GGroup/GMutable/GMutable.cpp b/src/GraphCtrl/GraphElement/GGroup/GMutable/GMutable.cpp index 19afb327..35bd173d 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GMutable/GMutable.cpp +++ b/src/GraphCtrl/GraphElement/GGroup/GMutable/GMutable.cpp @@ -42,17 +42,17 @@ CStatus GMutable::run() { * 3. 通过 manager 执行 */ setup(); - status = reshape(group_elements_arr_); + status = reshape(children_); CGRAPH_FUNCTION_CHECK_STATUS - status = manager_->process({group_elements_arr_.begin(), group_elements_arr_.end()}); + status = manager_->process({children_.begin(), children_.end()}); CGRAPH_FUNCTION_END } CStatus GMutable::destroy() { CGRAPH_FUNCTION_BEGIN - for (auto* element : group_elements_arr_) { + for (auto* element : children_) { // 链路中,可能会将部分内容设置为 visible 的信息。这里统一恢复一下 element->setVisible(true); } @@ -76,7 +76,7 @@ GElementPtr GMutable::setThreadPoolEx(UThreadPoolPtr ptr) { CVoid GMutable::setup() { - for (auto* element : group_elements_arr_) { + for (auto* element : children_) { element->run_before_.clear(); element->dependence_.clear(); element->setLoop(1); diff --git a/src/GraphCtrl/GraphElement/GGroup/GSome/GSome.inl b/src/GraphCtrl/GraphElement/GGroup/GSome/GSome.inl index 94847139..fbcd5fd4 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GSome/GSome.inl +++ b/src/GraphCtrl/GraphElement/GGroup/GSome/GSome.inl @@ -51,7 +51,7 @@ CStatus GSome::run() { * 3. 将所有未执行完的element 设置为timeout * 4. 赋返回值 */ - for (auto* element : group_elements_arr_) { + for (auto* element : children_) { thread_pool_->commit([this, element] { { const auto& curStatus = element->fatProcessor(CFunctionType::RUN); @@ -68,7 +68,7 @@ CStatus GSome::run() { return left_num_ <= 0 || cur_status_.isErr(); }); - for (auto* element : group_elements_arr_) { + for (auto* element : children_) { if (!element->done_) { element->cur_state_.store(GElementState::TIMEOUT, std::memory_order_release); } @@ -91,7 +91,7 @@ CVoid GSome::dump(std::ostream& oss) { oss << 'p' << this << "[shape=point height=0];\n"; oss << "color=blue;style=dashed;\n"; // 蓝色虚线 - for (const auto& element : group_elements_arr_) { + for (const auto& element : children_) { element->dump(oss); } @@ -118,9 +118,9 @@ CStatus GSome::checkSuitable() { CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION((CGRAPH_DEFAULT_LOOP_TIMES != loop_), "GSome cannot set loop > 1.") CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION((0 >= TriggerNum), "trigger num must bigger than 0.") - CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION((group_elements_arr_.size() < TriggerNum), \ + CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION((children_.size() < TriggerNum), \ "this GSome need at least [" + std::to_string(TriggerNum) + "] element.") - CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION(std::any_of(group_elements_arr_.begin(), group_elements_arr_.end(), [](GElementPtr ptr) { + CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION(std::any_of(children_.begin(), children_.end(), [](GElementPtr ptr) { return !ptr->isAsync(); }), "GSome contains async node only.") diff --git a/src/GraphCtrl/GraphPipeline/_GStroage/GStorageDefine.h b/src/GraphCtrl/GraphPipeline/_GStroage/GStorageDefine.h index 8c3d7f60..75d6e02a 100644 --- a/src/GraphCtrl/GraphPipeline/_GStroage/GStorageDefine.h +++ b/src/GraphCtrl/GraphPipeline/_GStroage/GStorageDefine.h @@ -119,7 +119,7 @@ struct _GElementStorage : public _GStorageBasic { for (const auto* dep : element->dependence_) { dependence_sessions_.emplace_back(dep->getSession()); } - for (const auto* child : element->getChildren()) { + for (const auto* child : element->children_) { children_.emplace_back(child); } if (element->aspect_manager_) {