Midge  v3.9.2
Data Processing Framework
node.cc
Go to the documentation of this file.
1 #include "node.hh"
2 
3 #include "coremsg.hh"
4 #include "midge_error.hh"
5 
6 using std::string;
7 
8 namespace midge
9 {
10 
12  scarab::cancelable(),
13  f_name( "(unnamed node)" ),
14  f_node_map(),
15  f_input_map(),
16  f_output_map()
17  {
18  }
20  {
21  for( input_it t_input_it = f_input_map.begin(); t_input_it != f_input_map.end(); t_input_it++ )
22  {
23  delete (t_input_it->second);
24  }
25 
26  for( output_it t_output_it = f_output_map.begin(); t_output_it != f_output_map.end(); t_output_it++ )
27  {
28  delete (t_output_it->second);
29  }
30  }
31 
32  node* node::node_ptr( const string& p_label )
33  {
34  node_it t_it = f_node_map.find( p_label );
35  if( t_it == f_node_map.end() )
36  {
37  throw error() << "node named <" << get_name() << "> has no pointer to node named <" << p_label << ">";
38  return NULL;
39  }
40  return t_it->second;
41  }
42  input* node::in( const string& p_label )
43  {
44  input_it t_it = f_input_map.find( p_label );
45  if( t_it == f_input_map.end() )
46  {
47  throw error() << "node named <" << get_name() << "> has no input named <" << p_label << ">";
48  return NULL;
49  }
50  return t_it->second;
51  }
52  output* node::out( const string& p_label )
53  {
54  output_it t_it = f_output_map.find( p_label );
55  if( t_it == f_output_map.end() )
56  {
57  throw error() << "node named <" << get_name() << "> has no out named <" << p_label << ">";
58  return NULL;
59  }
60  return t_it->second;
61  }
62  signal* node::signal_ptr( const string& p_label )
63  {
64  signal_it t_it = f_signal_map.find( p_label );
65  if( t_it == f_signal_map.end() )
66  {
67  throw error() << "node named <" << get_name() << "> has no signal named <" << p_label << ">";
68  return NULL;
69  }
70  return t_it->second;
71  }
72  slot* node::slot_ptr( const string& p_label )
73  {
74  slot_it t_it = f_slot_map.find( p_label );
75  if( t_it == f_slot_map.end() )
76  {
77  throw error() << "node named <" << get_name() << "> has no slot named <" << p_label << ">";
78  return NULL;
79  }
80  return t_it->second;
81  }
82 
83  void node::node_ptr( node* p_node, const string& p_label )
84  {
85  node_it t_it = f_node_map.find( p_label );
86  if( t_it == f_node_map.end() )
87  {
88  f_node_map.insert( node_entry( p_label, p_node ) );
89  }
90  else
91  {
92  throw error() << "node already has a node pointer named <" << p_label << ">";
93  }
94  return;
95  }
96  void node::in( input* p_input, const string& p_label )
97  {
98  input_it t_it = f_input_map.find( p_label );
99  if( t_it == f_input_map.end() )
100  {
101  p_input->set_name( p_label );
102  f_input_map.insert( input_entry( p_label, p_input ) );
103  }
104  else
105  {
106  throw error() << "node already has in named <" << p_label << ">";
107  }
108  return;
109  }
110  void node::out( output* p_output, const string& p_label )
111  {
112  output_it t_it = f_output_map.find( p_label );
113  if( t_it == f_output_map.end() )
114  {
115  p_output->set_name( p_label );
116  f_output_map.insert( output_entry( p_label, p_output ) );
117  }
118  else
119  {
120  throw error() << "node already has out named <" << p_label << ">";
121  }
122  return;
123  }
124  void node::signal_ptr( signal* p_signal, const string& p_label )
125  {
126  signal_it t_it = f_signal_map.find( p_label );
127  if( t_it == f_signal_map.end() )
128  {
129  f_signal_map.insert( signal_entry( p_label, p_signal ) );
130  }
131  else
132  {
133  throw error() << "node already has a signal named <" << p_label << ">";
134  }
135  return;
136  }
137  void node::slot_ptr( slot* p_slot, const string& p_label )
138  {
139  slot_it t_it = f_slot_map.find( p_label );
140  if( t_it == f_slot_map.end() )
141  {
142  f_slot_map.insert( slot_entry( p_label, p_slot ) );
143  }
144  else
145  {
146  throw error() << "node already has a slot named <" << p_label << ">";
147  }
148  return;
149  }
150 
151  void node::do_cancellation( int a_code )
152  {
153  msg_debug( coremsg, "node::do_cancellation for <" << f_name << ">" << eom );
154  for( output_it t_it = f_output_map.begin(); t_it != f_output_map.end(); ++t_it )
155  {
156  msg_debug( coremsg, "Canceling stream <" << t_it->first << ">" << eom );
157  t_it->second->get()->cancel( a_code );
158  }
159  return;
160  }
161 
162 
163 }
static const message_end eom
Definition: _buffer.hh:11
signal_map::iterator signal_it
Definition: node.hh:75
slot_map::iterator slot_it
Definition: node.hh:82
node()
Definition: node.cc:11
output_map f_output_map
Definition: node.hh:72
virtual ~node()
Definition: node.cc:19
void do_cancellation(int a_node) override
Definition: node.cc:151
output_map::iterator output_it
Definition: node.hh:68
signal * signal_ptr(const std::string &p_label)
Definition: node.cc:62
input * in(const std::string &p_label)
Definition: node.cc:42
node * node_ptr(const std::string &p_label)
Definition: node.cc:32
slot_map f_slot_map
Definition: node.hh:86
slot_map::value_type slot_entry
Definition: node.hh:84
node_map f_node_map
Definition: node.hh:58
output_map::value_type output_entry
Definition: node.hh:70
node_map::iterator node_it
Definition: node.hh:54
input_map f_input_map
Definition: node.hh:65
#define msg_debug(x_name, x_content)
input_map::value_type input_entry
Definition: node.hh:63
output * out(const std::string &p_label)
Definition: node.cc:52
signal_map f_signal_map
Definition: node.hh:79
node_map::value_type node_entry
Definition: node.hh:56
signal_map::value_type signal_entry
Definition: node.hh:77
slot * slot_ptr(const std::string &p_label)
Definition: node.cc:72
input_map::iterator input_it
Definition: node.hh:61