<add>工作流框架搭建
This commit is contained in:
		
						commit
						a569ee6972
					
				| 
						 | 
					@ -0,0 +1,4 @@
 | 
				
			||||||
 | 
					/bin
 | 
				
			||||||
 | 
					/build
 | 
				
			||||||
 | 
					/.vscode
 | 
				
			||||||
 | 
					/.cache
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,13 @@
 | 
				
			||||||
 | 
					cmake_minimum_required(VERSION 3.10)
 | 
				
			||||||
 | 
					project(workflow VERSION 0.1.0 LANGUAGES CXX)
 | 
				
			||||||
 | 
					set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
 | 
				
			||||||
 | 
					set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
 | 
				
			||||||
 | 
					set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
 | 
				
			||||||
 | 
					set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib)
 | 
				
			||||||
 | 
					set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib)
 | 
				
			||||||
 | 
					add_compile_definitions(-DSWF_EXPORT_DLL)
 | 
				
			||||||
 | 
					set(CMAKE_CXX_STANDARD 17)
 | 
				
			||||||
 | 
					aux_source_directory(src SRC_LIST)
 | 
				
			||||||
 | 
					add_executable(${PROJECT_NAME} ${SRC_LIST})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					target_include_directories(${PROJECT_NAME} PRIVATE include head)
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,16 @@
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "INode.h"
 | 
				
			||||||
 | 
					#include "node_view.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class SWF_API SWFNode : public WF::INode
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    std::vector<node_view> m_next;
 | 
				
			||||||
 | 
					    std::vector<node_view> m_prev;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
					    SWFNode();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 获取节点类型
 | 
				
			||||||
 | 
					    NodeType GetNodeType() const noexcept;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,30 @@
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "SWFDefine.h"
 | 
				
			||||||
 | 
					#include "IFlow.h"
 | 
				
			||||||
 | 
					#include "node_view.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace WF { class INode; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class SWF_API SWFlow : public WF::IFlow
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // 工作流状态
 | 
				
			||||||
 | 
					    FlowStatus m_nStatus;
 | 
				
			||||||
 | 
					    // 工作流节点列表
 | 
				
			||||||
 | 
					    std::vector<std::shared_ptr<WF::INode>> m_vecNodes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    node_view m_curNode; // 当前节点视图
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
					    SWFlow();
 | 
				
			||||||
 | 
					    ~SWFlow() override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 运行工作流
 | 
				
			||||||
 | 
					    void Run() override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 停止工作流
 | 
				
			||||||
 | 
					    void Stop() override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 获取工作流状态
 | 
				
			||||||
 | 
					    int GetStatus() const noexcept override;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,18 @@
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "INode.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class SWF_API node_view
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /*
 | 
				
			||||||
 | 
					     * @brief 节点视图类
 | 
				
			||||||
 | 
					     * @note  不管理节点对象的生命周期
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    WF::INode* m_node;
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
					    node_view(WF::INode* node) : m_node(node) {}
 | 
				
			||||||
 | 
					    ~node_view() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 获取节点类型
 | 
				
			||||||
 | 
					    NodeType GetNodeType() const noexcept;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,28 @@
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					// @file:  IError.h
 | 
				
			||||||
 | 
					// @brief: Error handling interface
 | 
				
			||||||
 | 
					// @author: dyz
 | 
				
			||||||
 | 
					// @date: 2025-04-19
 | 
				
			||||||
 | 
					// @version: 1.0
 | 
				
			||||||
 | 
					/////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					#include "SWFInc.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace WF {
 | 
				
			||||||
 | 
					    class SWF_API IError
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					        virtual ~IError() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Get the error code
 | 
				
			||||||
 | 
					        virtual int GetErrorCode() const = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Get the error message
 | 
				
			||||||
 | 
					        virtual const char* GetErrorMessage() const = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Set the error code and message
 | 
				
			||||||
 | 
					        virtual void SetError(int code, const char* message) = 0;
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace WF
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,30 @@
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					// @file: IFlow.h
 | 
				
			||||||
 | 
					// @brief:  Interface for the Flow class
 | 
				
			||||||
 | 
					// @author: dyz
 | 
				
			||||||
 | 
					// @date: 2025-04-19
 | 
				
			||||||
 | 
					// @version: 1.0
 | 
				
			||||||
 | 
					/////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "SWFInc.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace WF {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class SWF_API IFlow
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					        virtual ~IFlow() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 运行工作流
 | 
				
			||||||
 | 
					        virtual void Run() = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 停止工作流
 | 
				
			||||||
 | 
					        virtual void Stop() = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 获取工作流状态
 | 
				
			||||||
 | 
					        virtual int GetStatus() const = 0;
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace WF
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,26 @@
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					// @file: INode.h
 | 
				
			||||||
 | 
					// @brief: Interface for the Node class
 | 
				
			||||||
 | 
					// @author: dyz
 | 
				
			||||||
 | 
					// @date: 2025-04-19
 | 
				
			||||||
 | 
					// @version: 1.0
 | 
				
			||||||
 | 
					/////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "SWFInc.h"
 | 
				
			||||||
 | 
					#include "SWFDefine.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace WF
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    class SWF_API INode
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					        // 执行节点的操作
 | 
				
			||||||
 | 
					        virtual void exec() = 0;
 | 
				
			||||||
 | 
					        virtual INode* clone() const = 0;
 | 
				
			||||||
 | 
					        virtual NodeType GetNodeType() const = 0;
 | 
				
			||||||
 | 
					        virtual ~INode() = default;
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace WF
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,46 @@
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					// @file: SWFDefine.h
 | 
				
			||||||
 | 
					// @brief: 工作流类型定义
 | 
				
			||||||
 | 
					// @author: dyz
 | 
				
			||||||
 | 
					// @date: 2025-04-19
 | 
				
			||||||
 | 
					// @version: 1.0
 | 
				
			||||||
 | 
					//////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**********************************************************
 | 
				
			||||||
 | 
					 * @brief 工作流节点类型定义
 | 
				
			||||||
 | 
					 * @note 该定义用于工作流节点的类型标识
 | 
				
			||||||
 | 
					**********************************************************/
 | 
				
			||||||
 | 
					#define FOR_MEMORY_NODETYPE(_f) \
 | 
				
			||||||
 | 
					    _f(START)  \
 | 
				
			||||||
 | 
					    _f(END)    \
 | 
				
			||||||
 | 
					    _f(IF)     \
 | 
				
			||||||
 | 
					    _f(ACTIVTIY) \
 | 
				
			||||||
 | 
					    _f(SEND)   \
 | 
				
			||||||
 | 
					    _f(RECEIVE) \
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define FOR_MEMORY_FLOWSTATUS(_f) \
 | 
				
			||||||
 | 
					    _f(INIT)  \
 | 
				
			||||||
 | 
					    _f(RUNNING)    \
 | 
				
			||||||
 | 
					    _f(END)     \
 | 
				
			||||||
 | 
					    _f(ERROR) \
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum class NodeType
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					#define _f(_name) _name,
 | 
				
			||||||
 | 
					    FOR_MEMORY_NODETYPE(_f)
 | 
				
			||||||
 | 
					#undef _f
 | 
				
			||||||
 | 
					    MAX_NODETYPE
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum class FlowStatus
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					#define _f(_name) _name,
 | 
				
			||||||
 | 
					    FOR_MEMORY_FLOWSTATUS(_f)
 | 
				
			||||||
 | 
					#undef _f
 | 
				
			||||||
 | 
					    MAX_FLOWSTATUS
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,23 @@
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef _WIN32
 | 
				
			||||||
 | 
					#   ifdef SWF_EXPORT_DLL
 | 
				
			||||||
 | 
					#       define SWF_API __declspec(dllexport)
 | 
				
			||||||
 | 
					#   else
 | 
				
			||||||
 | 
					#       define SWF_API __declspec(dllimport)
 | 
				
			||||||
 | 
					#   endif
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#   ifdef SWF_EXPORT_DLL
 | 
				
			||||||
 | 
					#       define SWF_API __attribute__((visibility("default")))
 | 
				
			||||||
 | 
					#   else
 | 
				
			||||||
 | 
					#       define SWF_API
 | 
				
			||||||
 | 
					#   endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 公共头文件
 | 
				
			||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <string>
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					#include <map>
 | 
				
			||||||
 | 
					#include <memory>
 | 
				
			||||||
 | 
					#include <algorithm>
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					#include "INode.h"
 | 
				
			||||||
 | 
					#include "SWFlow.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void SWFlow::Run() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 按照序列执行节点
 | 
				
			||||||
 | 
					    for (auto& node : m_vecNodes) {
 | 
				
			||||||
 | 
					        node->exec();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					#include "IFlow.h"
 | 
				
			||||||
 | 
					#include "SWFlow.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(){
 | 
				
			||||||
 | 
					    WF::IFlow* flow = new SWFlow();
 | 
				
			||||||
 | 
					    flow->Run();
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue