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