Ophidian
All Classes Namespaces Functions
graph.h
1 /*
2  * Copyright 2016 Ophidian
3 Licensed to the Apache Software Foundation (ASF) under one
4 or more contributor license agreements. See the NOTICE file
5 distributed with this work for additional information
6 regarding copyright ownership. The ASF licenses this file
7 to you under the Apache License, Version 2.0 (the
8 "License"); you may not use this file except in compliance
9 with the License. You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0
12 
13 Unless required by applicable law or agreed to in writing,
14 software distributed under the License is distributed on an
15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 KIND, either express or implied. See the License for the
17 specific language governing permissions and limitations
18 under the License.
19  */
20 
21 #ifndef SRC_TIMING_GRAPH_H_
22 #define SRC_TIMING_GRAPH_H_
23 
24 #include <lemon/list_graph.h>
25 #include "../entity_system/entity_system.h"
26 #include "transition.h"
27 #include <unordered_map>
28 
29 namespace ophidian {
30 namespace timing {
31 
32 enum class edge_types {
33  TIMING_ARC, NET
34 };
35 
36 
37 struct test {
38 
39  lemon::ListDigraph::Node ck;
40  lemon::ListDigraph::Node d;
41  entity_system::entity tarc;
42 };
43 
44 class graph {
45 public:
46  using graph_t = lemon::ListDigraph;
47  using node = graph_t::Node;
48  using edge = graph_t::Arc;
49 private:
50  graph_t m_graph;
51 
52  lemon::ListDigraph::NodeMap< entity_system::entity > m_pins;
53  lemon::ListDigraph::NodeMap< edges > m_node_edges;
54  lemon::ListDigraph::ArcMap< edge_types > m_arc_types;
55  lemon::ListDigraph::ArcMap< entity_system::entity > m_arcs;
56 
57 
58  std::unordered_map< entity_system::entity, node > m_rise_nodes;
59  std::unordered_map< entity_system::entity, node > m_fall_nodes;
60 
61  std::vector< test > m_tests;
62 
63  node node_create(entity_system::entity pin, edges node_edge, std::unordered_map<entity_system::entity, node> &map);
64 
65 
66 
67 public:
68  graph();
69  virtual ~graph();
70 
71  void test_insert(node ck,
72  node d,
73  entity_system::entity tarc);
74 
75  const std::vector< test > & tests() const {
76  return m_tests;
77  }
78 
79  const graph_t & G() const {
80  return m_graph;
81  }
82 
83 
84  std::size_t nodes_count() const {
85  return lemon::countNodes(m_graph);
86  }
87 
88  std::size_t edges_count() const {
89  return lemon::countArcs(m_graph);
90  }
91 
92  node rise_node_create(entity_system::entity pin);
93  node rise_node(entity_system::entity pin) const {
94  return m_rise_nodes.at(pin);
95  }
96 
97  node fall_node_create(entity_system::entity pin);
98  node fall_node(entity_system::entity pin) const {
99  return m_fall_nodes.at(pin);
100  }
101 
102  void node_edge(node u, edges e);
103  edges node_edge(node u) const {
104  return m_node_edges[u];
105  }
106 
107 
108  edge edge_create(node u, node v, edge_types type, entity_system::entity entity);
109  entity_system::entity edge_entity(edge e) const{
110  return m_arcs[e];
111  }
112 
113  entity_system::entity pin(node u) const {
114  return m_pins[u];
115  }
116 
117  graph_t::OutArcIt out_edges_it(node u) const {
118  return graph_t::OutArcIt(m_graph, u);
119  }
120 
121  node edge_source(edge e) const {
122  return m_graph.source(e);
123  }
124  node edge_target(edge e) const {
125  return m_graph.target(e);
126  }
127  edge_types edge_type(edge e) const {
128  return m_arc_types[e];
129  }
130 
131  void edge_source(edge e, node u);
132 
133 
134  template <class Iterator>
135  void edge_destroy(const Iterator begin, const Iterator end) {
136  for(Iterator it{begin}; it != end; ++it)
137  m_graph.erase(*it);
138  }
139 
140 
141 };
142 
143 }
144 /* namespace timing */
145 } /* namespace ophidian */
146 
147 #endif /* SRC_TIMING_GRAPH_H_ */
Definition: graph.h:37
Definition: graph.h:44