test_onion.cxx
Go to the documentation of this file.
1 #include <memory>
3 
4 
5 class IFunctor : public WireCell::IComponent<IFunctor>
6 {
7 public:
8  virtual ~IFunctor() {}
9 
10  virtual std::string signature() = 0;
11 
12 };
13 
14 template <typename InputType, typename OutputType>
15 class IFunctorT : public IFunctor
16 {
17 public:
18  typedef InputType input_type;
19  typedef OutputType output_type;
21 
22  virtual ~IFunctorT() {}
23 
24  virtual std::string signature() {
25  return typeid(this_type).name();
26  }
27 
28  virtual bool operator()(const std::shared_ptr<const input_type>& in,
29  std::shared_ptr<const output_type>& out) = 0;
30 
31 };
32 
33 
34 class IMyIFConverter : public IFunctorT<int,float>
35 {
36 public:
37  virtual ~IMyIFConverter() {}
38 };
39 
40 class MyIFConverter : public IMyIFConverter {
41 public:
42  virtual ~MyIFConverter() {}
43 
44  virtual bool operator()(const std::shared_ptr<const input_type>& in,
45  std::shared_ptr<const output_type>& out) {
46  out = std::make_shared<const float>(*in);
47  return true;
48  }
49 
50 };
51 
52 class INode : public WireCell::IComponent<INode>
53 {
54 public:
55  virtual ~INode() {}
56 
57  virtual std::string functor_type_name() = 0;
58 
59 };
60 
61 
62 #include "WireCellUtil/Testing.h"
63 
64 int main()
65 {
66  // emulate NF lookup
67  std::shared_ptr<IFunctor> fun(new MyIFConverter);
68 
69 
70  // emulate node maker and wrapper
71  auto myfun = std::dynamic_pointer_cast<IMyIFConverter>(fun);
72 
73  // emulate running a node
74  auto in = std::make_shared<const int>(42);
75  auto out = std::make_shared<const float>(0);
76  bool ok = (*myfun)(in, out);
77 
78  Assert(ok);
79  Assert(42.0 == *out);
80  return 0;
81 }
static QCString name
Definition: declinfo.cpp:673
virtual std::string signature()
Definition: test_onion.cxx:24
virtual ~IFunctor()
Definition: test_onion.cxx:8
std::string string
Definition: nybbler.cc:12
virtual std::string signature()=0
virtual ~IFunctorT()
Definition: test_onion.cxx:22
virtual ~IMyIFConverter()
Definition: test_onion.cxx:37
InputType input_type
Definition: test_onion.cxx:18
virtual ~MyIFConverter()
Definition: test_onion.cxx:42
#define Assert
Definition: Testing.h:7
IFunctorT< InputType, OutputType > this_type
Definition: test_onion.cxx:20
virtual bool operator()(const std::shared_ptr< const input_type > &in, std::shared_ptr< const output_type > &out)
Definition: test_onion.cxx:44
OutputType output_type
Definition: test_onion.cxx:19
virtual ~INode()
Definition: test_onion.cxx:55
int main()
Definition: test_onion.cxx:64