Node.h
Go to the documentation of this file.
1 #ifndef WIRECELL_PGRAPH_NODE
2 #define WIRECELL_PGRAPH_NODE
3 
4 #include "WireCellPgraph/Port.h"
5 
6 namespace WireCell {
7  namespace Pgraph {
8 
9  // A node in the DFP graph must inherit from Node.
10  class Node {
11  public:
12  Node() {} // constructures may wish to resize/populate m_ports.
13  virtual ~Node() { }
14 
15  // Concrete Node must implement this to consume inputs
16  // and/or produce outputs.
17  virtual bool operator()() = 0;
18 
19  // Concrete node must return some instance identifier.
20  virtual std::string ident() = 0;
21 
22  Port& iport(size_t ind=0) {
23  return port(Port::input, ind);
24  }
25  Port& oport(size_t ind=0) {
26  return port(Port::output, ind);
27  }
28 
30  return m_ports[Port::input];
31  }
33  return m_ports[Port::output];
34  }
35 
36  Port& port(Port::Type type, size_t ind=0) {
37  if (ind >= m_ports[type].size()) {
38  THROW(ValueError() << errmsg{"unknown port"});
39  }
40  return m_ports[type][ind];
41  }
43  for (size_t ind=0; ind<m_ports[type].size(); ++ind) {
44  if (m_ports[type][ind].name() != name) {
45  continue;
46  }
47  return port(type, ind);
48  }
49  THROW(ValueError() << errmsg{"unknown port"});
50  }
51 
52  bool connected() {
53  for (auto& p : input_ports()) {
54  if (!p.edge()) {
55  return false;
56  }
57  }
58  for (auto& p : output_ports()) {
59  if (!p.edge()) {
60  return false;
61  }
62  }
63  return true;
64  }
65 
66  protected:
67  // Concrete class should fill during construction
69  };
70  }
71 }
72 
73 #endif
static QCString name
Definition: declinfo.cpp:673
bool connected()
Definition: Node.h:52
PortList & input_ports()
Definition: Node.h:29
Port & port(Port::Type type, const std::string &name)
Definition: Node.h:42
std::string string
Definition: nybbler.cc:12
boost::error_info< struct tag_errmsg, std::string > errmsg
Definition: Exceptions.h:54
virtual std::string ident()=0
virtual ~Node()
Definition: Node.h:13
std::vector< Port > PortList
Definition: Port.h:70
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:87
Port & port(Port::Type type, size_t ind=0)
Definition: Node.h:36
virtual bool operator()()=0
Port & iport(size_t ind=0)
Definition: Node.h:22
#define THROW(e)
Definition: Exceptions.h:25
Thrown when a wrong value has been encountered.
Definition: Exceptions.h:37
Definition: Main.h:22
p
Definition: test.py:223
PortList m_ports[Port::ntypes]
Definition: Node.h:68
std::string type(const T &t)
Definition: Type.h:20
Port & oport(size_t ind=0)
Definition: Node.h:25
PortList & output_ports()
Definition: Node.h:32