Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/GraphCtrl/GraphPipeline/GPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,13 @@ CBool GPipeline::checkSeparate(GElementPtr fst, GElementPtr snd) const {

CStatus GPipeline::save(const std::string& path) {
CGRAPH_FUNCTION_BEGIN
std::set<std::string> names;
CGRAPH_ASSERT_INIT(false)

// 不允许有同名的 element 被存储
for (const auto* element : repository_.elements_) {
CGRAPH_ASSERT_NOT_NULL(element)
CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION(element->isGAdaptor(),
element->name_ + " is GAdaptor, cannot be saved.")
CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION(names.find(element->name_) != names.end(),
element->name_ + " name is duplicated, cannot be saved.")
names.insert(element->name_);
}

#if __cplusplus >= 201703L
Expand All @@ -347,6 +344,8 @@ CStatus GPipeline::save(const std::string& path) {

CStatus GPipeline::load(const std::string& path) {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_INIT(false)

#if __cplusplus >= 201703L
status = GStorage::load(this, path);
#else
Expand Down
27 changes: 14 additions & 13 deletions src/GraphCtrl/GraphPipeline/_GStroage/GStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ CGRAPH_INTERNAL_NAMESPACE_BEGIN
UREFL_CREATE_STRUCT_TRAIT_INFO(_GElementStorage,
UREFL_DECLARE_FIELD(_GElementStorage, name_, 1),
UREFL_DECLARE_FIELD(_GElementStorage, loop_, 2),
UREFL_DECLARE_FIELD(_GElementStorage, dependence_, 3),
UREFL_DECLARE_FIELD(_GElementStorage, visible_, 4),
UREFL_DECLARE_FIELD(_GElementStorage, binding_index_, 5),
UREFL_DECLARE_FIELD(_GElementStorage, session_, 3),
UREFL_DECLARE_FIELD(_GElementStorage, dependence_sessions_, 4),
UREFL_DECLARE_FIELD(_GElementStorage, visible_, 5),
UREFL_DECLARE_FIELD(_GElementStorage, binding_index_, 6),
UREFL_DECLARE_FIELD(_GElementStorage, level_, 7),
UREFL_DECLARE_FIELD(_GElementStorage, timeout_, 8),
UREFL_DECLARE_FIELD(_GElementStorage, timeout_strategy_, 9),
UREFL_DECLARE_FIELD(_GElementStorage, is_marco_, 10),
UREFL_DECLARE_FIELD(_GElementStorage, clz_name_, 11),
UREFL_DECLARE_FIELD(_GElementStorage, belong_name_, 12),
UREFL_DECLARE_FIELD(_GElementStorage, belong_session_, 12),
UREFL_DECLARE_FIELD(_GElementStorage, element_type_, 13),
UREFL_DECLARE_FIELD(_GElementStorage, children_, 14)
)
Expand Down Expand Up @@ -157,36 +158,36 @@ CStatus GStorage::loadBuffer(GPipelinePtr pipeline, char* buffer, CSize size) {
status = cur.recover(element);
CGRAPH_FUNCTION_CHECK_STATUS

eleCache[cur.name_] = element;
eleCache[cur.session_] = element;
}

// 设定从属关系
for (const auto& cur : storage.element_storages_) {
auto element = eleCache[cur.name_];
if (cur.belong_name_.empty()) {
auto element = eleCache[cur.session_];
if (cur.belong_session_.empty()) {
pipeline->innerRegister(element, {}, cur.name_, cur.loop_);
} else {
element->belong_ = eleCache[cur.belong_name_];
element->belong_ = eleCache[cur.belong_session_];
}
}

// 设定依赖关系
for (const auto& cur : storage.element_storages_) {
if (!cur.dependence_.empty()) {
auto element = eleCache[cur.name_];
if (!cur.dependence_sessions_.empty()) {
auto element = eleCache[cur.session_];
GElementPtrSet depSet{};
for (const std::string& dep : cur.dependence_) {
for (const std::string& dep : cur.dependence_sessions_) {
depSet.insert(eleCache[dep]);
}
status += element->addDependGElements(depSet);
CGRAPH_FUNCTION_CHECK_STATUS
}

if (!cur.children_.empty()) {
GGroupPtr group = dynamic_cast<GGroupPtr>(eleCache[cur.name_]);
GGroupPtr group = dynamic_cast<GGroupPtr>(eleCache[cur.session_]);
CGRAPH_ASSERT_NOT_NULL(group)
for (const auto& child : cur.children_) {
group->addElement(eleCache[child.name_]);
group->addElement(eleCache[child.session_]);
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/GraphCtrl/GraphPipeline/_GStroage/GStorageDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,36 @@ CGRAPH_NAMESPACE_BEGIN
struct _GElementStorage : public CStruct {
std::string name_ {};
CSize loop_ { CGRAPH_DEFAULT_LOOP_TIMES };
std::string session_ {};
CBool visible_ { true };
CIndex binding_index_ { CGRAPH_DEFAULT_BINDING_INDEX };
CLevel level_ { CGRAPH_DEFAULT_ELEMENT_LEVEL };
CMSec timeout_ { CGRAPH_DEFAULT_ELEMENT_TIMEOUT };
GElementTimeoutStrategy timeout_strategy_ { GElementTimeoutStrategy::AS_ERROR };
CBool is_marco_ { false };
std::string belong_name_ {};
std::string belong_session_ {};
GElementType element_type_ {};
std::string clz_name_ {}; // 记录element 的真实类型信息
std::vector<std::string> dependence_ {};
std::vector<std::string> dependence_sessions_ {};
std::vector<_GElementStorage> children_ {};

explicit _GElementStorage() = default;

explicit _GElementStorage(GElementCPtr element) {
name_ = element->getName();
loop_ = element->getLoop();
session_ = element->getSession();
visible_ = element->visible_;
binding_index_ = element->binding_index_;
binding_index_ = element->getBindingIndex();
level_ = element->level_;
timeout_ = element->timeout_;
timeout_strategy_ = element->timeout_strategy_;
is_marco_ = element->is_marco_;
belong_name_ = element->belong_ ? element->belong_->getName() : CGRAPH_EMPTY;
belong_session_ = element->belong_ ? element->belong_->getSession() : CGRAPH_EMPTY;
element_type_ = element->element_type_;
clz_name_ = typeid(*element).name();
for (const auto* dep : element->dependence_) {
dependence_.emplace_back(dep->getName());
dependence_sessions_.emplace_back(dep->getSession());
}
for (const auto* child : element->getChildren()) {
children_.emplace_back(child);
Expand All @@ -69,8 +71,6 @@ struct _GElementStorage : public CStruct {
element->setVisible(visible_);
element->setLevel(level_);
element->setTimeout(timeout_, timeout_strategy_);
element->setMacro(is_marco_);

if (element->isGNode()) {
element->setMacro(is_marco_);
}
Expand Down
2 changes: 1 addition & 1 deletion tutorial/T29-Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@Contact: chunel@foxmail.com
@File: Storage.cpp
@Time: 2025/10/4 13:43
@Desc: 本例子主要展示保存
@Desc: 本例子主要展示保存pipeline 到本地,并且重新加载的功能
***************************/

#include <iostream>
Expand Down
Loading