All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbndcode/sbndcode/OpDetReco/OpFlash/FlashFinder/FlashAlgoFactory.h
Go to the documentation of this file.
1 /**
2  * \file FlashAlgoFactory.h
3  *
4  * \ingroup FlashFinder
5  *
6  * \brief Class def header for a class FlashAlgoFactory
7  *
8  * @author kazuhiro
9  */
10 
11 /** \addtogroup FlashAlgoFinder
12 
13  @{*/
14 #ifndef FLASHALGOFACTORY_H
15 #define FLASHALGOFACTORY_H
16 
17 #include <iostream>
18 #include <map>
19 #include "FlashAlgoBase.h"
20 
21 namespace lightana {
22  /**
23  \class FlashFactoryBase
24  \brief Abstract base class for factory (to be implemented per flash)
25  */
26 
28 
29  public:
30  /// Default ctor
32  /// Default dtor (virtual)
34  /// Abstract constructor method
35  virtual FlashAlgoBase* create(const std::string instance_name) = 0;
36  };
37 
38  /**
39  \class FlashAlgoFactory
40  \brief Factory class for instantiating flash algorithm instance
41  */
43  private:
44  /// Default ctor, shouldn't be used
46  public:
47  /// Default dtor
49  /// Static sharable instance getter
50  static FlashAlgoFactory& get()
51  { if(!_me) _me = new FlashAlgoFactory; return *_me; }
52  /// Factory registration method (should be called by global factory instance in algorithm header)
53  void add_factory(const std::string name, lightana::FlashAlgoFactoryBase* factory)
54  { _factory_map[name] = factory; }
55  /// Factory creation method (should be called by clients, possibly you!)
56  FlashAlgoBase* create(const std::string name, const std::string instance_name) {
57  auto iter = _factory_map.find(name);
58  if(iter == _factory_map.end() || !((*iter).second)) {
59  std::cerr << "Found no registered class " << name << std::endl;
60  return nullptr;
61  }
62  auto ptr = (*iter).second->create(instance_name);
63  return ptr;
64  }
65 
66  private:
67  /// Static factory container
68  std::map<std::string,lightana::FlashAlgoFactoryBase*> _factory_map;
69  /// Static self
71  };
72 }
73 #endif
74 /** @} */ // end of doxygen group
BEGIN_PROLOG could also be cerr
void add_factory(const std::string name, lightana::FlashAlgoFactoryBase *factory)
Factory registration method (should be called by global factory instance in algorithm header) ...
Factory class for instantiating flash algorithm instance.
std::map< std::string, lightana::FlashAlgoFactoryBase * > _factory_map
Static factory container.
then echo fcl name
FlashAlgoBase * create(const std::string name, const std::string instance_name)
Factory creation method (should be called by clients, possibly you!)
virtual FlashAlgoBase * create(const std::string instance_name)=0
Abstract constructor method.