Port.h
Go to the documentation of this file.
1 #ifndef WIRECELL_PGRAPH_PORT
2 #define WIRECELL_PGRAPH_PORT
3 
5 
6 #include <boost/any.hpp>
7 
8 #include <string>
9 #include <vector>
10 #include <deque>
11 #include <memory>
12 
13 
14 
15 namespace WireCell {
16  namespace Pgraph {
17 
18  // The type of data passed in the graph.
19  typedef boost::any Data;
20  // A buffer of data. It is a std::deque instead of a
21  // std::queue so that it may be iterated as well as pushed
22  // back into. Like a British queue, one enters it from the
23  // back and exits it from the front.
24  typedef std::deque<Data> Queue;
25 
26  // Edges are just queues that can be shared.
27  typedef std::shared_ptr<Queue> Edge;
28 
29  class Node;
30 
31  class Port {
32  public:
33  enum Type { tail=0, output=0, head=1, input=1, ntypes=2 };
34 
36 
37  bool isinput();
38  bool isoutput();
39  Edge edge();
40 
41  // Connect an edge, returning any previous one.
42  Edge plug(Edge edge);
43 
44  // return edge queue size or 0 if no edge has been plugged
45  size_t size();
46 
47  // Return true if queue is empty or no edge has been plugged.
48  bool empty();
49 
50  // Get the next data. By default this pops the data off
51  // the queue. To "peek" at the data, pas false.
52  Data get(bool pop = true);
53 
54  // Put the data onto the queue.
55  void put(Data& data);
56 
57  // Get back the associated Node.
58  Node* node();
59 
60  const std::string& name();
61  const std::string& signature();
62 
63  private:
64  Node* m_node; // node to which port belongs
67  Edge m_edge;
68  };
69 
70  typedef std::vector<Port> PortList;
71  }
72 }
73 
74 #endif
Edge plug(Edge edge)
Definition: Port.cxx:23
std::string string
Definition: nybbler.cc:12
std::shared_ptr< Queue > Edge
Definition: Port.h:27
std::deque< Data > Queue
Definition: Port.h:24
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
std::vector< Port > PortList
Definition: Port.h:70
Port(Node *node, Type type, std::string signature, std::string name="")
Definition: Port.cxx:9
Definition: Main.h:22
boost::any Data
Definition: Port.h:19
std::string m_sig
Definition: Port.h:66
void put(Data &data)
Definition: Port.cxx:62