Port.cxx
Go to the documentation of this file.
1 #include "WireCellPgraph/Port.h"
2 
3 
4 #include <iostream>
5 
6 using namespace std;
7 using namespace WireCell::Pgraph;
8 
9 Port::Port(Node* node, Type type, std::string signature, std::string name)
10  : m_node(node)
11  , m_type(type)
12  , m_name(name)
13  , m_sig(signature)
14  , m_edge(nullptr)
15 { }
16 
17 bool Port::isinput() { return m_type == Port::input; }
18 bool Port::isoutput() { return m_type == Port::output; }
19 
20 Edge Port::edge() { return m_edge; }
21 
22 // Connect an edge, returning any previous one.
24  Edge ret = m_edge;
25  m_edge = edge;
26  return ret;
27 }
28 
29 // return edge queue size or 0 if no edge has been plugged
30 size_t Port::size() {
31  if (!m_edge) { return 0; }
32  return m_edge->size();
33 }
34 
35 // Return true if queue is empty or no edge has been plugged.
36 bool Port::empty() {
37  if (!m_edge or m_edge->empty()) { return true; }
38  return false;
39 }
40 
41 // Get the next data. By default this pops the data off
42 // the queue. To "peek" at the data, pas false.
43 Data Port::get(bool pop) {
44  if (isoutput()) {
46  << errmsg{"can not get from output port"});
47  }
48  if (!m_edge) {
49  THROW(RuntimeError() << errmsg{"port has no edge"});
50  }
51  if (m_edge->empty()) {
52  THROW(RuntimeError() << errmsg{"edge is empty"});
53  }
54  Data ret = m_edge->front();
55  if (pop) {
56  m_edge->pop_front();
57  }
58  return ret;
59 }
60 
61 // Put the data onto the queue.
63  if (isinput()) {
64  THROW(RuntimeError() << errmsg{"can not put to input port"});
65  }
66  if (!m_edge) {
67  THROW(RuntimeError() << errmsg{"port has no edge"});
68  }
69  m_edge->push_back(data);
70 }
71 
72 const std::string& Port::name() { return m_name; }
73 const std::string& Port::signature() { return m_sig; }
static QCString name
Definition: declinfo.cpp:673
Edge plug(Edge edge)
Definition: Port.cxx:23
std::string string
Definition: nybbler.cc:12
boost::error_info< struct tag_errmsg, std::string > errmsg
Definition: Exceptions.h:54
std::shared_ptr< Queue > Edge
Definition: Port.h:27
STL namespace.
const std::string & name()
Definition: Port.cxx:72
std::string m_name
Definition: Port.h:66
const std::string & signature()
Definition: Port.cxx:73
basic_data data
Definition: format.h:764
Data get(bool pop=true)
Definition: Port.cxx:43
#define THROW(e)
Definition: Exceptions.h:25
std::string m_sig
Definition: Port.h:66
Thrown when an error occurs during the data processing.
Definition: Exceptions.h:49
void put(Data &data)
Definition: Port.cxx:62