Factory.h
Go to the documentation of this file.
1 #ifndef WIRECELL_PGRAPH_FACTORY
2 #define WIRECELL_PGRAPH_FACTORY
3 
4 
5 #include "WireCellPgraph/Node.h"
6 #include "WireCellUtil/Logging.h"
7 #include "WireCellIface/INode.h"
8 
9 namespace WireCell {
10  namespace Pgraph {
11 
12  // Makers make an appropriate Pgraph::Node from an INode
13  struct Maker {
14  virtual ~Maker() {}
15  virtual Node* operator()(INode::pointer wcnode) = 0;
16  };
17  template<class Wrapper>
18  struct MakerT : public Maker {
19  virtual ~MakerT() {}
20  virtual Node* operator()(INode::pointer wcnode) {
21  return new Wrapper(wcnode);
22  }
23  };
24 
25  // This factory creates Pgraph::Nodes*'s from INode::pointers.
26  // It only knows about the categories that have been hard
27  // coded in the Factory constructor.
28  class Factory {
29  public:
30 
31  Factory();
32 
33  typedef std::map<INode::pointer, Node*> WCNodeWrapperMap;
34 
35  template<class Wrapper>
37  m_factory[cat] = new MakerT<Wrapper>;
38  }
39 
41 
42 
43  private:
44  typedef std::map<INode::NodeCategory, Maker*> NodeMakers;
45  NodeMakers m_factory;
46  WCNodeWrapperMap m_nodes;
48  };
49 
50  }
51 }
52 #endif
std::map< INode::NodeCategory, Maker * > NodeMakers
Definition: Factory.h:44
virtual Node * operator()(INode::pointer wcnode)
Definition: Factory.h:20
std::map< INode::pointer, Node * > WCNodeWrapperMap
Definition: Factory.h:33
virtual Node * operator()(INode::pointer wcnode)=0
void bind_maker(INode::NodeCategory cat)
Definition: Factory.h:36
std::shared_ptr< Interface > pointer
Definition: Interface.h:16
std::shared_ptr< spdlog::logger > logptr_t
Definition: Logging.h:24
Definition: Main.h:22
WCNodeWrapperMap m_nodes
Definition: Factory.h:46
NodeMakers m_factory
Definition: Factory.h:45
Log::logptr_t l
Definition: Factory.h:47