Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / runtime / onert / core / src / dumper / dot / Node.h
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file Node.h
19  * @brief    This file contains Node class
20  * @ingroup  COM_AI_RUNTIME
21  *
22  */
23
24 #ifndef __ONERT_DUMPER_DOT_NODE_H__
25 #define __ONERT_DUMPER_DOT_NODE_H__
26
27 #include <string>
28 #include <memory>
29 #include <vector>
30 #include <unordered_map>
31
32 namespace onert
33 {
34 namespace dumper
35 {
36 namespace dot
37 {
38
39 enum BGCOLORS : int
40 {
41   RED,
42   BLUE,
43   GREEN,
44   PUPLE,
45   ORANGE,
46   YELLOW,
47   BROWN,
48   PINK
49 };
50
51 /**
52  * @brief Class that represents a Node in "dot" format
53  *
54  */
55 class Node
56 {
57 public:
58   const static std::string DEFAULT_FILLCOLOR;
59   const static std::string DEFAULT_COLORSCHEME;
60   const static std::string BG_COLORS[8];
61
62 public:
63   /**
64    * @brief Destroy the Node object
65    *
66    */
67   virtual ~Node() = default;
68
69   /**
70    * @brief Construct a new Node object
71    *
72    * @param id
73    */
74   Node(const std::string &id);
75
76   /**
77    * @brief return id
78    *
79    * @return id
80    */
81   std::string id() const { return _id; }
82
83   /**
84    * @brief return attributes
85    *
86    * @return const reference of attributes object
87    */
88   const std::unordered_map<std::string, std::string> &attributes() const { return _attributes; }
89   /**
90    * @brief Store an attribute with key-value pair
91    *
92    * @param[in] key attribute's key
93    * @param[in] val attribute's value that is associated with the key
94    */
95   void setAttribute(const std::string &key, const std::string &val);
96   /**
97    * @brief Get the attributte value that is associated with key
98    *
99    * @param[in] key key of the attribute
100    * @return value that is associated with the key
101    */
102   std::string getAttribute(const std::string &key);
103
104   /**
105    * @brief Add an edge in the graph, which is an outgoing edge
106    *
107    * @param[in] dotinfo A node that the new edge will be connected to
108    */
109   void addOutEdge(Node *dotinfo) { _out_edges.emplace_back(dotinfo); }
110   /**
111    * @brief Return list of out edges
112    *
113    * @return Edges
114    */
115   const std::vector<Node *> &out_edges() const { return _out_edges; }
116
117 private:
118   std::string _id;
119   std::unordered_map<std::string, std::string> _attributes;
120   std::vector<Node *> _out_edges;
121 };
122
123 } // namespace dot
124 } // namespace dumper
125 } // namespace onert
126
127 #endif // __ONERT_DUMPER_DOT_NODE_H__