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