十行代码跑起来
#include <task_graph/task_graph.hpp>
using namespace task_graph;
int main() {
DAG dag;
auto fetch = std::make_shared<Task>("fetch", [](TaskContext& ctx) {
return TaskResult{.status = TaskStatus::COMPLETED, .value = std::string("user_123")};
});
auto process = std::make_shared<Task>("process", [](TaskContext& ctx) {
auto data = ctx.input<std::string>("in");
return TaskResult{.status = TaskStatus::COMPLETED,
.value = std::string(*data + "_processed")};
});
dag.add_task(fetch);
dag.add_task(process);
dag.connect("fetch", "process"); // out -> in
DAGExecutor executor;
executor.execute(dag).wait();
}
图即数据
同一张图也可以用 JSON 描述,交给 DAGSerializer::from_string 加载、DAGExecutor 执行 —— GraphStudio 保存和加载的就是这种格式:
{
"version": "2.0",
"tasks": [
{ "id": "src", "type": "opencv_image_read", "params": { "file_path": "test.png" } },
{ "id": "gaussian", "type": "opencv_gaussian_blur_filter" },
{ "id": "sobel", "type": "opencv_sobel_filter" }
],
"edges": [
{ "from": "src", "from_port": "out", "to": "gaussian", "to_port": "in" },
{ "from": "gaussian", "from_port": "out", "to": "sobel", "to_port": "in" }
]
}
深入了解
- 📖 完整文档见 GitHub 仓库 README(含构建选项、插件开发、GPU 后端说明)
- 🚀 从零开始搭建第一张图,见博客《快速上手 GraphStudio》
- 📦 想自己出安装包,见《从源码构建三端安装包》
