Skip to content

Commit 67cb5b8

Browse files
committed
[feat] export addGElements function for PyCGraph
1 parent 3383860 commit 67cb5b8

8 files changed

Lines changed: 41 additions & 22 deletions

File tree

python/PyCGraph.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,27 @@ PYBIND11_MODULE(PyCGraph, m) {
4747

4848
py::class_<PyGCluster, GElement, std::unique_ptr<PyGCluster, py::nodelete> >(m, "GCluster")
4949
.def(py::init<>())
50-
.def("addGElement", &PyGCluster::addGElement,
51-
py::arg("element"));
50+
.def("addGElements", &PyGCluster::addGElements,
51+
py::arg("elements"));
5252

5353
py::class_<PyGRegion, GElement, std::unique_ptr<PyGRegion, py::nodelete> >(m, "GRegion")
5454
.def(py::init<>())
55-
.def("addGElement", &PyGRegion::addGElement,
56-
py::arg("element"));
55+
.def("addGElements", &PyGRegion::addGElements,
56+
py::arg("elements"))
57+
;
5758

5859
py::class_<PywGCondition, GElement, std::unique_ptr<PywGCondition, py::nodelete> >(m, "GCondition")
5960
.def(py::init<>())
60-
.def("addGElement", &PywGCondition::addGElement,
61-
py::arg("element"));
61+
.def("addGElements", &PywGCondition::addGElements,
62+
py::arg("elements"));
6263

6364
py::class_<PyGMultiCondition<CGraph::GMultiConditionType::SERIAL>, GElement>(m, "GSerialMultiCondition")
6465
.def(py::init<>())
65-
.def("addGElement", &PyGMultiCondition<CGraph::GMultiConditionType::SERIAL>::addGElement,
66-
py::arg("element"));
66+
.def("addGElements", &PyGMultiCondition<CGraph::GMultiConditionType::SERIAL>::addGElements,
67+
py::arg("elements"));
6768

6869
py::class_<PyGMultiCondition<CGraph::GMultiConditionType::PARALLEL>, GElement>(m, "GParallelMultiCondition")
6970
.def(py::init<>())
70-
.def("addGElement", &PyGMultiCondition<CGraph::GMultiConditionType::PARALLEL>::addGElement,
71-
py::arg("element"));
71+
.def("addGElements", &PyGMultiCondition<CGraph::GMultiConditionType::PARALLEL>::addGElements,
72+
py::arg("elements"));
7273
}

python/wrapper/PyGCluster.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class PyGCluster : public CGraph::GCluster {
1616
explicit PyGCluster() : CGraph::GCluster() {};
1717
~PyGCluster() override {};
1818

19-
CStatus addGElement(CGraph::GElementPtr element) {
20-
return addElement(element);
19+
CStatus addGElements(const CGraph::GElementPtrArr& elements) {
20+
return addElements(elements);
2121
}
2222
};
2323

python/wrapper/PyGMultiCondition.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class PyGMultiCondition : public CGraph::GMultiCondition<type> {
1717
explicit PyGMultiCondition() : CGraph::GMultiCondition<type>() {};
1818
~PyGMultiCondition() override {};
1919

20-
CStatus addGElement(CGraph::GElementPtr element) {
21-
return CGraph::GMultiCondition<type>::addElement(element);
20+
CStatus addGElements(const CGraph::GElementPtrArr& elements) {
21+
return CGraph::GMultiCondition<type>::addElements(elements);
2222
}
2323
};
2424

python/wrapper/PyGRegion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class PyGRegion : public CGraph::GRegion {
1616
explicit PyGRegion() : CGraph::GRegion() {};
1717
~PyGRegion() override {};
1818

19-
CStatus addGElement(CGraph::GElementPtr element) {
20-
return addElement(element);
19+
CStatus addGElements(const CGraph::GElementPtrArr& elements) {
20+
return addElements(elements);
2121
}
2222
};
2323

python/wrapper/PywGCondition.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class PywGCondition : public CGraph::GCondition {
2424
PYBIND11_OVERLOAD_PURE(CIndex, PywGCondition, choose);
2525
}
2626

27-
CStatus addGElement(CGraph::GElementPtr element) {
28-
return addElement(element);
27+
CStatus addGElements(const CGraph::GElementPtrArr& elements) {
28+
return addElements(elements);
2929
}
3030
};
3131

src/GraphCtrl/GraphElement/GGroup/GGroup.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ CStatus GGroup::addElement(GElementPtr element) {
5353
}
5454

5555

56+
CStatus GGroup::addElements(const GElementPtrArr& elements) {
57+
CGRAPH_FUNCTION_BEGIN
58+
CGRAPH_ASSERT_INIT(false)
59+
for (GElementPtr element : elements) {
60+
status += addElement(element);
61+
}
62+
CGRAPH_FUNCTION_END
63+
}
64+
65+
5666
CVoid GGroup::dumpGroupLabelBegin(std::ostream& oss) {
5767
oss << "subgraph ";
5868
oss << "cluster_p" << this; // cluster_ 是 graphviz的关键字,和CGraph中GCluster逻辑无关

src/GraphCtrl/GraphElement/GGroup/GGroup.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@ CGRAPH_NAMESPACE_BEGIN
2020
class GGroup : public GElement {
2121
protected:
2222
/**
23-
* 向group中,添加element信息
24-
* @param element
23+
* 插入多个 elements 信息
24+
* @param elements
2525
* @return
26+
* @notice 主要为了适配python接口,不建议cpp用户直接使用
2627
*/
27-
virtual CStatus addElement(GElementPtr element);
28+
CStatus addElements(const GElementPtrArr& elements);
2829

2930
CBool isSerializable() const override;
3031

3132
explicit GGroup();
3233

3334
private:
35+
/**
36+
* 向group中,添加element信息
37+
* @param element
38+
* @return
39+
*/
40+
virtual CStatus addElement(GElementPtr element);
41+
3442
CStatus addManagers(GParamManagerPtr paramManager,
3543
GEventManagerPtr eventManager,
3644
GStageManagerPtr stageManager) override;

tutorial/T22-Timeout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void tutorial_timeout() {
2222

2323
status = pipeline->process(); // 正常运行
2424
if (status.isOK()) {
25-
std::cout << "pipeline run finish" << std::endl;
25+
std::cout << "---- pipeline run finish" << std::endl;
2626
}
2727
std::cout << "===================" << std::endl;
2828

0 commit comments

Comments
 (0)