SpiecsEngine
 
Loading...
Searching...
No Matches
DirectedAcyclicGraph.h
Go to the documentation of this file.
1/**
2* @file DirectedAcyclicGraph.h.
3* @brief The DirectedAcyclicGraph Class Definitions.
4* @author Spices.
5*/
6
7#pragma once
8#include "Core/Core.h"
9
10namespace scl {
11
12 /**
13 * @brief DAG Node Class.
14 */
16 {
17 public:
18
19 /**
20 * @brief Constructor Function.
21 */
23
24 /**
25 * @brief Constructor Function.
26 * @param[in] name Node name.
27 * @param[in] dependencies Node dependencies name.
28 * @param[in] func Node function.
29 */
30 directed_acyclic_node(const std::string& name, const std::vector<std::string>& dependencies, const std::function<void()>& func)
31 : m_Name(std::move(name))
33 , m_Func(std::move(func))
34 {}
35
36 /**
37 * @brief Destructor Function.
38 */
39 virtual ~directed_acyclic_node() = default;
40
41 private:
42
43 /**
44 * @brief Node name.
45 */
46 std::string m_Name;
47
48 /**
49 * @brief Node dependencies name.
50 */
52
53 /**
54 * @brief Node function.
55 */
57
58 /**
59 * @brief Allow directed_acyclic_graph access all data.
60 */
62 };
63
64 /**
65 * @brief DAG Class.
66 */
68 {
69 public:
70
71 /**
72 * @brief Constructor Function.
73 */
75
76 /**
77 * @brief Destructor Function.
78 */
79 virtual ~directed_acyclic_graph() = default;
80
81 /**
82 * @brief Add a node to this graph.
83 * @param[in] node directed_acyclic_node.
84 */
86
87 /**
88 * @brief Execute all node function by order.
89 */
90 void execute();
91
92 /**
93 * @brief Get Node size.
94 * @return Returns Node size.
95 */
96 size_t size() const { return m_Nodes.size(); }
97
98 private:
99
100 /**
101 * @brief Execute a node's function.
102 * @param[in] node directed_acyclic_node.
103 * @param[in] visited graph execute states.
104 */
105 void execute_internal(directed_acyclic_node* node, std::unordered_map<std::string, bool>& visited);
106
107 private:
108
109 /**
110 * @brief Graph Nodes.
111 */
113 };
114}
directed_acyclic_graph()=default
Constructor Function.
void add_node(directed_acyclic_node *node)
Add a node to this graph.
void execute_internal(directed_acyclic_node *node, std::unordered_map< std::string, bool > &visited)
Execute a node's function.
std::unordered_map< std::string, directed_acyclic_node * > m_Nodes
Graph Nodes.
void execute()
Execute all node function by order.
virtual ~directed_acyclic_graph()=default
Destructor Function.
size_t size() const
Get Node size.
std::vector< std::string > m_Dependencies
Node dependencies name.
directed_acyclic_node()=delete
Constructor Function.
std::function< void()> m_Func
Node function.
directed_acyclic_node(const std::string &name, const std::vector< std::string > &dependencies, const std::function< void()> &func)
Constructor Function.
virtual ~directed_acyclic_node()=default
Destructor Function.