SyDEVS  v0.6.7
Multiscale Simulation and Systems Modeling Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
node_structure.h
Go to the documentation of this file.
1 #pragma once
2 #ifndef SYDEVS_SYSTEMS_NODE_STRUCTURE_H_
3 #define SYDEVS_SYSTEMS_NODE_STRUCTURE_H_
4 
6 #include <vector>
7 #include <map>
8 
9 namespace sydevs {
10 namespace systems {
11 
12 class system_node;
13 
14 
16 {
17 public:
19 
20  node_structure(const node_structure&) = delete;
21  node_structure& operator=(const node_structure&) = delete;
22  node_structure(node_structure&&) = delete;
24  virtual ~node_structure() = default;
25 
26  int64 node_count() const;
27  system_node& node(int64 node_index) const;
28 
29  int64 add_node(system_node* node_ptr);
30  void erase_node(int64 node_index);
31 
32  void add_flow_inward_link(int64 src_port_index,
33  int64 dst_node_index, int64 dst_port_index);
34  const std::vector<std::pair<int64, int64>>& flow_inward_links(int64 src_port_index) const;
35 
36  void add_message_inward_link(int64 src_port_index,
37  int64 dst_node_index, int64 dst_port_index);
38  const std::vector<std::pair<int64, int64>>& message_inward_links(int64 src_port_index) const;
39 
40  void add_flow_inner_link(int64 src_node_index, int64 src_port_index,
41  int64 dst_node_index, int64 dst_port_index);
42  const std::vector<std::pair<int64, int64>>& flow_inner_links(int64 src_node_index, int64 src_port_index) const;
43 
44  void add_message_inner_link(int64 src_node_index, int64 src_port_index,
45  int64 dst_node_index, int64 dst_port_index);
46  const std::vector<std::pair<int64, int64>>& message_inner_links(int64 src_node_index, int64 src_port_index) const;
47 
48  void add_flow_outward_link(int64 src_node_index, int64 src_port_index,
49  int64 dst_port_index);
50  const std::vector<int64>& flow_outward_links(int64 src_node_index, int64 src_port_index) const;
51 
52  void add_message_outward_link(int64 src_node_index, int64 src_port_index,
53  int64 dst_port_index);
54  const std::vector<int64>& message_outward_links(int64 src_node_index, int64 src_port_index) const;
55 
56 private:
57  int64 next_node_index_;
58  std::map<int64, system_node*> node_ptrs_;
59  std::map<int64, std::vector<std::pair<int64, int64>>> flow_inward_links_;
60  std::map<int64, std::vector<std::pair<int64, int64>>> message_inward_links_;
61  std::map<std::pair<int64, int64>, std::vector<std::pair<int64, int64>>> flow_inner_links_;
62  std::map<std::pair<int64, int64>, std::vector<std::pair<int64, int64>>> message_inner_links_;
63  std::map<std::pair<int64, int64>, std::vector<int64>> flow_outward_links_;
64  std::map<std::pair<int64, int64>, std::vector<int64>> message_outward_links_;
65 };
66 
67 
69  : next_node_index_(0)
70  , node_ptrs_()
71  , flow_inward_links_()
72  , message_inward_links_()
73  , flow_inner_links_()
74  , message_inner_links_()
75  , flow_outward_links_()
76  , message_outward_links_()
77 {
78 }
79 
80 
82 {
83  return node_ptrs_.size();
84 }
85 
86 
87 inline system_node& node_structure::node(int64 node_index) const
88 {
89  return *node_ptrs_.at(node_index);
90 }
91 
92 
94 {
95  node_ptrs_[next_node_index_] = node_ptr;
96  ++next_node_index_;
97  return next_node_index_ - 1;
98 }
99 
100 
101 inline void node_structure::erase_node(int64 node_index)
102 {
103  node_ptrs_.erase(node_index);
104 }
105 
106 
107 inline void node_structure::add_flow_inward_link(int64 src_port_index,
108  int64 dst_node_index, int64 dst_port_index)
109 {
110  flow_inward_links_[src_port_index].emplace_back(dst_node_index, dst_port_index);
111 }
112 
113 
114 inline const std::vector<std::pair<int64, int64>>& node_structure::flow_inward_links(int64 src_port_index) const
115 {
116  static const auto no_links = std::vector<std::pair<int64, int64>>();
117  auto* links_ptr = &no_links;
118  auto links_iter = flow_inward_links_.find(src_port_index);
119  if (links_iter != std::end(flow_inward_links_)) {
120  links_ptr = &(links_iter->second);
121  }
122  return *links_ptr;
123 }
124 
125 
126 inline void node_structure::add_message_inward_link(int64 src_port_index,
127  int64 dst_node_index, int64 dst_port_index)
128 {
129  message_inward_links_[src_port_index].emplace_back(dst_node_index, dst_port_index);
130 }
131 
132 
133 inline const std::vector<std::pair<int64, int64>>& node_structure::message_inward_links(int64 src_port_index) const
134 {
135  static const auto no_links = std::vector<std::pair<int64, int64>>();
136  auto* links_ptr = &no_links;
137  auto links_iter = message_inward_links_.find(src_port_index);
138  if (links_iter != std::end(message_inward_links_)) {
139  links_ptr = &(links_iter->second);
140  }
141  return *links_ptr;
142 
143 }
144 
145 
146 inline void node_structure::add_flow_inner_link(int64 src_node_index, int64 src_port_index,
147  int64 dst_node_index, int64 dst_port_index)
148 {
149  flow_inner_links_[std::make_pair(src_node_index, src_port_index)].emplace_back(dst_node_index, dst_port_index);
150 }
151 
152 
153 inline const std::vector<std::pair<int64, int64>>& node_structure::flow_inner_links(int64 src_node_index, int64 src_port_index) const
154 {
155  static const auto no_links = std::vector<std::pair<int64, int64>>();
156  auto* links_ptr = &no_links;
157  auto links_iter = flow_inner_links_.find(std::make_pair(src_node_index, src_port_index));
158  if (links_iter != std::end(flow_inner_links_)) {
159  links_ptr = &(links_iter->second);
160  }
161  return *links_ptr;
162 }
163 
164 
165 inline void node_structure::add_message_inner_link(int64 src_node_index, int64 src_port_index,
166  int64 dst_node_index, int64 dst_port_index)
167 {
168  message_inner_links_[std::make_pair(src_node_index, src_port_index)].emplace_back(dst_node_index, dst_port_index);
169 }
170 
171 
172 inline const std::vector<std::pair<int64, int64>>& node_structure::message_inner_links(int64 src_node_index, int64 src_port_index) const
173 {
174  static const auto no_links = std::vector<std::pair<int64, int64>>();
175  auto* links_ptr = &no_links;
176  auto links_iter = message_inner_links_.find(std::make_pair(src_node_index, src_port_index));
177  if (links_iter != std::end(message_inner_links_)) {
178  links_ptr = &(links_iter->second);
179  }
180  return *links_ptr;
181 }
182 
183 
184 inline void node_structure::add_flow_outward_link(int64 src_node_index, int64 src_port_index,
185  int64 dst_port_index)
186 {
187  flow_outward_links_[std::make_pair(src_node_index, src_port_index)].emplace_back(dst_port_index);
188 }
189 
190 
191 inline const std::vector<int64>& node_structure::flow_outward_links(int64 src_node_index, int64 src_port_index) const
192 {
193  static const auto no_links = std::vector<int64>();
194  auto* links_ptr = &no_links;
195  auto links_iter = flow_outward_links_.find(std::make_pair(src_node_index, src_port_index));
196  if (links_iter != std::end(flow_outward_links_)) {
197  links_ptr = &(links_iter->second);
198  }
199  return *links_ptr;
200 }
201 
202 
203 inline void node_structure::add_message_outward_link(int64 src_node_index, int64 src_port_index,
204  int64 dst_port_index)
205 {
206  message_outward_links_[std::make_pair(src_node_index, src_port_index)].emplace_back(dst_port_index);
207 }
208 
209 
210 inline const std::vector<int64>& node_structure::message_outward_links(int64 src_node_index, int64 src_port_index) const
211 {
212  static const auto no_links = std::vector<int64>();
213  auto* links_ptr = &no_links;
214  auto links_iter = message_outward_links_.find(std::make_pair(src_node_index, src_port_index));
215  if (links_iter != std::end(message_outward_links_)) {
216  links_ptr = &(links_iter->second);
217  }
218  return *links_ptr;
219 }
220 
221 
222 } // namespace
223 } // namespace
224 
225 #endif
void add_message_outward_link(int64 src_node_index, int64 src_port_index, int64 dst_port_index)
Definition: node_structure.h:203
const std::vector< std::pair< int64, int64 > > & flow_inward_links(int64 src_port_index) const
Definition: node_structure.h:114
A base class for all nodes from which systems models are constructed.
Definition: system_node.h:41
int64 add_node(system_node *node_ptr)
Definition: node_structure.h:93
system_node & node(int64 node_index) const
Definition: node_structure.h:87
const std::vector< int64 > & flow_outward_links(int64 src_node_index, int64 src_port_index) const
Definition: node_structure.h:191
void add_flow_inner_link(int64 src_node_index, int64 src_port_index, int64 dst_node_index, int64 dst_port_index)
Definition: node_structure.h:146
virtual ~node_structure()=default
Destructor.
node_structure()
Definition: node_structure.h:68
const std::vector< std::pair< int64, int64 > > & message_inward_links(int64 src_port_index) const
Definition: node_structure.h:133
void add_message_inner_link(int64 src_node_index, int64 src_port_index, int64 dst_node_index, int64 dst_port_index)
Definition: node_structure.h:165
int64 node_count() const
Definition: node_structure.h:81
void add_flow_outward_link(int64 src_node_index, int64 src_port_index, int64 dst_port_index)
Definition: node_structure.h:184
node_structure & operator=(const node_structure &)=delete
No copy assignment.
const std::vector< int64 > & message_outward_links(int64 src_node_index, int64 src_port_index) const
Definition: node_structure.h:210
void erase_node(int64 node_index)
Definition: node_structure.h:101
const std::vector< std::pair< int64, int64 > > & message_inner_links(int64 src_node_index, int64 src_port_index) const
Definition: node_structure.h:172
void add_flow_inward_link(int64 src_port_index, int64 dst_node_index, int64 dst_port_index)
Definition: node_structure.h:107
void add_message_inward_link(int64 src_port_index, int64 dst_node_index, int64 dst_port_index)
Definition: node_structure.h:126
Definition: node_structure.h:15
const std::vector< std::pair< int64, int64 > > & flow_inner_links(int64 src_node_index, int64 src_port_index) const
Definition: node_structure.h:153