ComSDK
 Указатель Классы Пространства имен Функции Переменные Определения типов Перечисления Элементы перечислений Друзья Группы Страницы
graph.h
1 #ifndef __GRAPH_H__
2 #define __GRAPH_H__
3 
4 #include "anymap.h"
5 #include "predicate.h"
6 #include "edge.h"
7 
8 #include <vector>
9 #include <set>
10 #include <map>
11 #include <memory>
12 #include <functional>
13 
14 #include "libtools.h"
15 
16 namespace com {
26  namespace graph {
27  namespace detail {
28  struct EdgeHelper {
29  std::string name;
30  std::map< std::string, std::string > props;
31  };
32 
33  struct NodeHelper {
34  NodeHelper(const std::string& name, int id) : name(name), id(id) {}//, owner(nullptr) {}
35  std::string name;
36  int id;
37  //NodeHelper* owner;
38  std::vector<NodeHelper*> children;
39  std::vector<EdgeHelper> edges;
40  std::map< std::string, std::string > props;
41  };
42 
43  void parseDotLine(const std::string& line, std::map<std::string, detail::NodeHelper*>& nodesLookup,
44  std::map<std::string, std::map<std::string, std::string> >& funcLookup, detail::NodeHelper*& entryNode);
45 
46  std::shared_ptr< Node > buildNodeFromNodeHelper(NodeHelper* nodeHelper,
47  std::map<std::string, std::shared_ptr<Node> >& nodes,
48  std::map<std::string, std::shared_ptr<sys::ActionItemExecutor> >& edgeExecs,
49  std::map<std::string, std::shared_ptr<sys::ActionItemExecutor> >& predExecs,
50  const std::map<std::string, NodeHelper*>& nodesLookup,
51  const std::map<std::string, std::map<std::string, std::string> >& funcLookup);
52 
53  std::shared_ptr<Edge> buildEdgeWithSubsequentNodes(EdgeHelper& edgeHelper,
54  NodeHelper* endNodeHelper,
55  std::map<std::string, std::shared_ptr<Node> >& nodes,
56  std::map<std::string, std::shared_ptr<sys::ActionItemExecutor> >& edgeExecs,
57  std::map<std::string, std::shared_ptr<sys::ActionItemExecutor> >& predExecs,
58  const std::map<std::string, NodeHelper*>& nodesLookup,
59  const std::map<std::string, std::map<std::string, std::string> >& funcLookup);
60 
61  std::shared_ptr<sys::ActionItemExecutor> buildActionItemExecutorFromHelperProps(const std::map<std::string, std::string>& props);
62  }
63 
70  class MAC_DLLEXPORT Node : public std::enable_shared_from_this< Node > {
71  public:
73  Node(int id, std::shared_ptr< Predicate > pred = nullptr);
74  Node(const Node&) = delete;
75  ~Node(){}
76 
78  int getId() const;
79 
81  std::shared_ptr< Predicate > getPredicate();
82 
84  void setPredicate(std::shared_ptr< Predicate > pred);
85 
87  Anymap& run(Anymap& input);
88 
90  bool verify();
91 
92  private:
93  // возвращает <isInfiniteLoopInside, doesItCreateLoop>
94  std::pair< bool, bool > tryToFindInfiniteLoop(std::shared_ptr< Node > node, std::set< std::shared_ptr<Node> > nodesPath,
95  std::set< std::shared_ptr<Node> > nodesDirectPath);
96 
97  bool hasTerminateNode(std::shared_ptr< Node > node,
98  std::map< std::shared_ptr<Node>, std::set< std::shared_ptr<Node> > > nodesBranches,
99  std::set< std::shared_ptr<Node> > directNodesPath);
100 
101  private:
102  int m_id;
103  std::shared_ptr< Predicate > m_predicate;
104  };
105 
106  MAC_DLLEXPORT std::shared_ptr< Node > loadFromADot(const std::string& adotFile);
107  }
108 }
109 
110 #endif
Узел графа
Definition: graph.h:70
Мультитиповой словарь
Definition: anymap.h:79
Definition: graph.h:28
Definition: graph.h:33