IFanoutNode.h
Go to the documentation of this file.
1 #ifndef WIRECELL_IFANOUTNODE
2 #define WIRECELL_IFANOUTNODE
3 
4 #include "WireCellIface/INode.h"
5 
6 #include <boost/any.hpp>
7 #include <vector>
8 
9 namespace WireCell {
10 
11  /** A node which accepts one object of the given InputType and
12  * produces N of the given OutputType.
13  */
14  class IFanoutNodeBase : public INode
15  {
16  public:
17  typedef std::shared_ptr<IFanoutNodeBase> pointer;
18 
19  virtual ~IFanoutNodeBase() ;
20 
21  typedef std::vector<boost::any> any_vector;
22 
23  /// The calling signature:
24  virtual bool operator()(const boost::any& anyin, any_vector& anyout) = 0;
25 
26  virtual NodeCategory category() {
27  return fanoutNode;
28  }
29 
30  /// Fanout nodes can usually do their thing stateless.
31  virtual int concurrency() { return 0; }
32 
33 
34  };
35 
36  // This converts between any and typed.
37  template <typename InputType, typename OutputType, int FanoutMultiplicity=3>
38  class IFanoutNode : public IFanoutNodeBase {
39  public:
40 
41  typedef InputType input_type;
42  typedef OutputType output_type;
43  typedef std::shared_ptr<const InputType> input_pointer;
44  typedef std::shared_ptr<const OutputType> output_pointer;
45  typedef std::vector<output_pointer> output_vector;
46 
47  virtual ~IFanoutNode() {}
48 
49  virtual bool operator()(const boost::any& anyin, any_vector& anyv) {
50  const input_pointer& in = boost::any_cast<const input_pointer&>(anyin);
51  output_vector outv;
52  bool ok = (*this)(in, outv);
53  if (!ok) return false;
54  const size_t mult = output_types().size(); // don't use FanoutMultiplicity
55  anyv.resize(mult);
56  for (size_t ind=0; ind<mult; ++ind) {
57  anyv[ind] = outv[ind];
58  }
59  return true;
60  }
61 
62  // The typed interface
63  virtual bool operator()(const input_pointer& in, output_vector& outv) = 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  // Note: if subclass wants to supply FaninMultiplicity at
71  // construction time, this needs to be overridden.
72  virtual std::vector<std::string> output_types() {
73  std::vector<std::string> ret(FanoutMultiplicity, std::string(typeid(output_type).name()));
74  return ret;
75  }
76  };
77 
78 }
79 
80 #endif
static QCString name
Definition: declinfo.cpp:673
virtual bool operator()(const boost::any &anyin, any_vector &anyout)=0
The calling signature:
virtual std::vector< std::string > output_types()
Definition: INode.h:58
virtual std::vector< std::string > output_types()
Definition: IFanoutNode.h:72
std::shared_ptr< IFanoutNodeBase > pointer
Definition: IFanoutNode.h:17
virtual std::vector< std::string > input_types()
Definition: IFanoutNode.h:66
std::string string
Definition: nybbler.cc:12
OutputType output_type
Definition: IFanoutNode.h:42
virtual NodeCategory category()
Return the behavior category type.
Definition: IFanoutNode.h:26
std::vector< output_pointer > output_vector
Definition: IFanoutNode.h:45
Definition: Main.h:22
std::shared_ptr< const InputType > input_pointer
Definition: IFanoutNode.h:43
std::vector< boost::any > any_vector
Definition: IFanoutNode.h:21
virtual ~IFanoutNode()
Definition: IFanoutNode.h:47
virtual bool operator()(const boost::any &anyin, any_vector &anyv)
The calling signature:
Definition: IFanoutNode.h:49
std::shared_ptr< const OutputType > output_pointer
Definition: IFanoutNode.h:44
virtual int concurrency()
Fanout nodes can usually do their thing stateless.
Definition: IFanoutNode.h:31