ISplitNode.h
Go to the documentation of this file.
1 #ifndef WIRECELL_ISPLITNODE
2 #define WIRECELL_ISPLITNODE
3 
4 #include "WireCellIface/INode.h"
5 
7 
8 #include <boost/any.hpp>
9 #include <vector>
10 #include <memory>
11 
12 namespace WireCell {
13 
14  /** A node which splits 1 data into N objects each of a distinct
15  * type.
16  */
17 
18  class ISplitNodeBase : public INode
19  {
20  public:
21  typedef std::shared_ptr<ISplitNodeBase> pointer;
22 
23  virtual ~ISplitNodeBase() ;
24 
25  typedef std::vector<boost::any> any_vector;
26 
27  /// The calling signature:
28  virtual bool operator()(const boost::any& anyin, any_vector& anyout) = 0;
29 
30  virtual NodeCategory category() {
31  return splitNode;
32  }
33 
34  /// Split nodes can usually do their thing stateless.
35  virtual int concurrency() { return 0; }
36 
37 
38  };
39 
40  //
41  template <typename InputType, typename OutputTuple>
42  class ISplitNode : public ISplitNodeBase {
43  public:
44 
46  typedef typename port_helper_type::template WrappedConst<std::shared_ptr>::type output_tuple_type;
48 
49  typedef InputType input_type;
50 
51  typedef std::shared_ptr<const InputType> input_pointer;
52 
53  virtual ~ISplitNode() {}
54 
55  virtual bool operator()(const boost::any& anyin, any_vector& anyvout) {
56  const input_pointer& in = boost::any_cast<const input_pointer&>(anyin);
57 
58  output_tuple_type outtup;
59  output_helper_type oh;
60 
61  bool ok = (*this)(in,outtup);
62  if (ok) {
63  anyvout = oh.as_any(outtup);
64  }
65  return ok;
66  }
67 
68  virtual bool operator()(const input_pointer& in, output_tuple_type& out) = 0;
69 
70  // Return the names of the types this node takes as input.
71  virtual std::vector<std::string> input_types() {
72  return std::vector<std::string>{typeid(input_type).name()};
73  }
74  // Return the names of the types this node produces as output.
75  virtual std::vector<std::string> output_types() {
76  port_helper_type oph;
77  return oph.type_names();
78  }
79 
80  };
81 
82 }
83 
84 #endif
static QCString name
Definition: declinfo.cpp:673
tuple_helper< OutputTuple > port_helper_type
Definition: ISplitNode.h:45
port_helper_type::template WrappedConst< std::shared_ptr >::type output_tuple_type
Definition: ISplitNode.h:46
virtual std::vector< std::string > output_types()
Definition: ISplitNode.h:75
virtual ~ISplitNode()
Definition: ISplitNode.h:53
std::vector< boost::any > any_vector
Definition: ISplitNode.h:25
std::shared_ptr< const InputType > input_pointer
Definition: ISplitNode.h:51
virtual NodeCategory category()
Return the behavior category type.
Definition: ISplitNode.h:30
tuple_helper< output_tuple_type > output_helper_type
Definition: ISplitNode.h:47
virtual int concurrency()
Split nodes can usually do their thing stateless.
Definition: ISplitNode.h:35
virtual bool operator()(const boost::any &anyin, any_vector &anyvout)
The calling signature:
Definition: ISplitNode.h:55
Definition: Main.h:22
InputType input_type
Definition: ISplitNode.h:49
static QCString type
Definition: declinfo.cpp:672
virtual std::vector< std::string > input_types()
Definition: ISplitNode.h:71
std::shared_ptr< ISplitNodeBase > pointer
Definition: ISplitNode.h:21
virtual bool operator()(const boost::any &anyin, any_vector &anyout)=0
The calling signature: