IQueuedoutNode.h
Go to the documentation of this file.
1 #ifndef WIRECELL_IQUEUEDOUTNODE
2 #define WIRECELL_IQUEUEDOUTNODE
3 
4 #include "WireCellIface/INode.h"
5 
6 #include <boost/any.hpp>
7 #include <deque>
8 #include <vector>
9 
10 namespace WireCell {
11 
12  /** A node which is a function producing a zero or more output
13  */
14  class IQueuedoutNodeBase : public INode
15  {
16  public:
17  typedef std::shared_ptr<IQueuedoutNodeBase> pointer;
18 
19  virtual ~IQueuedoutNodeBase() ;
20 
21  typedef std::deque<boost::any> queuedany;
22 
23  /// The calling signature:
24  virtual bool operator()(const boost::any& anyin, queuedany& out) = 0;
25 
26  virtual NodeCategory category() {
27  return queuedoutNode;
28  }
29 
30  /// By default assume all subclasses maintain state.
31  virtual int concurrency() { return 1; }
32 
33 
34  };
35 
36  template <typename InputType, typename OutputType>
38  {
39  public:
40  typedef std::shared_ptr<IQueuedoutNodeBase> pointer;
41 
42  typedef InputType input_type;
43  typedef OutputType output_type;
44  typedef std::shared_ptr<const InputType> input_pointer;
45  typedef std::shared_ptr<const OutputType> output_pointer;
46  typedef std::deque<output_pointer> output_queue;
47 
48  virtual ~IQueuedoutNode(){}
49 
50 
51  virtual bool operator()(const boost::any& anyin, queuedany& outanyq) {
52  const input_pointer& in = boost::any_cast<const input_pointer&>(anyin);
53  output_queue outq;
54  bool ok = (*this)(in, outq);
55  if (!ok) return false;
56  for (auto o : outq) { // transfer typed to any
57  outanyq.push_back(o);
58  }
59  return true;
60  }
61 
62  /// The calling signature:
63  virtual bool operator()(const input_pointer& in, output_queue& outq) = 0;
64 
65  // Return the names of the types this node takes as input.
66  virtual std::vector<std::string> input_types() {
67  return std::vector<std::string>{typeid(input_type).name()};
68  }
69  // Return the names of the types this node produces as output.
70  virtual std::vector<std::string> output_types() {
71  return std::vector<std::string>{typeid(output_type).name()};
72  }
73 
74  };
75 
76 }
77 
78 #endif
static QCString name
Definition: declinfo.cpp:673
virtual std::vector< std::string > input_types()
virtual bool operator()(const boost::any &anyin, queuedany &out)=0
The calling signature:
std::deque< output_pointer > output_queue
std::deque< boost::any > queuedany
std::shared_ptr< IQueuedoutNodeBase > pointer
std::shared_ptr< IQueuedoutNodeBase > pointer
virtual NodeCategory category()
Return the behavior category type.
virtual std::vector< std::string > output_types()
Definition: Main.h:22
std::shared_ptr< const OutputType > output_pointer
virtual bool operator()(const boost::any &anyin, queuedany &outanyq)
The calling signature:
std::shared_ptr< const InputType > input_pointer
virtual int concurrency()
By default assume all subclasses maintain state.