Skip to content

Commit

Permalink
[feat] add Syntactic sugar for element realation set
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Nov 12, 2023
1 parent e29d31b commit a1443b1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ message("* * * * * * * * * * * * * * * * * * * * * * * * * * * * *")

cmake_minimum_required(VERSION 3.2.5)

project(CGraph VERSION 2.5.2)
project(CGraph VERSION 2.5.3)

# CGraph默认使用C++11版本,推荐使用C++17版本。暂不支持C++11以下版本
set(CMAKE_CXX_STANDARD 11)
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ int main() {
* 优化`CStatus`功能,添加了异常定位信息
[2023.09.05 - v2.5.0 - Chunel]
* 提供了perf功能,用于做`pipeline`的性能分析
* 提供了`element`的超时机制
* 提供了`some`(部分)功能,优化`pipeline`的异步执行方式
* 提供perf功能,用于做`pipeline`的性能分析
* 提供`element`的超时机制
* 提供`some`(部分)功能,优化`pipeline`的异步执行方式
[2023.09.15 - v2.5.1 - Chunel]
* 提供`fence`(栅栏)功能
Expand All @@ -332,6 +332,10 @@ int main() {
* 添加`example`相关内容,针对不同行业,提供一些简单实现
* 优化调度性能
[2023.11.12 - v2.5.3 - Chunel]
* 提供`proto`定义文件
* 提供依赖关系注册语法糖
</details>
------------
Expand Down
3 changes: 1 addition & 2 deletions src/CBasic/CFuncType.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ enum class CFunctionType {
/** 在异常状态的情况下,抛出异常 */
#define CGRAPH_THROW_EXCEPTION_BY_STATUS(status) \
if (unlikely((status).isErr())) { \
CGRAPH_THROW_EXCEPTION((status).getInfo()); \
} \
CGRAPH_THROW_EXCEPTION((status).getInfo()); } \

/** 根据条件判断是否抛出异常 */
#define CGRAPH_THROW_EXCEPTION_BY_CONDITION(cond, info) \
Expand Down
21 changes: 21 additions & 0 deletions src/GraphCtrl/GraphElement/GElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,27 @@ GElementPtr GElement::setTimeout(CMSec timeout, GElementTimeoutStrategy strategy
}


GElementRef GElement::operator--(int) {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_INIT_THROW_ERROR(false)
return (*this);
}


GElementRef GElement::operator>(GElementPtr element) {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_INIT_THROW_ERROR(false)
CGRAPH_ASSERT_NOT_NULL_THROW_ERROR(element)
CGRAPH_THROW_EXCEPTION_BY_STATUS(element->addDependGElements({this}))
return (*this);
}


GElementRef GElement::operator&(GElementPtr element) {
return operator>(element);
}


CBool GElement::isRunnable() const {
return 0 >= this->left_depend_ && !this->done_;
}
Expand Down
14 changes: 13 additions & 1 deletion src/GraphCtrl/GraphElement/GElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class GElement : public GElementObject,
* 设定绑定的线程id
* @param index,需要绑定的 thread id 信息
* @return
* @notice 若不了解调度机制,不建议使用本接口,否则可能导致运行时阻塞
* @notice 本接口仅保证绑定线程优先调度,但不保证最终一定在绑定线程上执行。若不了解调度机制,不建议使用本接口,否则可能导致运行时阻塞
*/
GElement* setBindingIndex(CIndex index);

Expand All @@ -119,6 +119,17 @@ class GElement : public GElementObject,
*/
CBool isGroup() const;

/**
* 实现连续注册的语法糖,形如:
* (*a)-->b&c;
* (*b)-->d;
* (*c)-->d;
* @return
*/
GElement& operator--(int);
GElement& operator>(GElement* element);
GElement& operator&(GElement* element);

protected:
/**
* 构造函数
Expand Down Expand Up @@ -404,6 +415,7 @@ class GElement : public GElementObject,
CGRAPH_DECLARE_GEVENT_MANAGER_WRAPPER_WITH_MEMBER
};

using GElementRef = GElement &;
using GElementPtr = GElement *;
using GElementPPtr = GElementPtr *;
using GElementPtrArr = std::vector<GElementPtr>;
Expand Down
2 changes: 1 addition & 1 deletion xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set_project("CGraph")

-- set project version
set_version("2.5.0")
set_version("2.5.3")

-- set language: c++11
set_languages("c++11")
Expand Down

0 comments on commit a1443b1

Please sign in to comment.