All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FlashFilterFactory.h
Go to the documentation of this file.
1 /**
2  * \file FlashFilterFactory.h
3  *
4  * \ingroup Base
5  *
6  * \brief Class def header for a class FlashFilterFactory
7  *
8  * @author kazuhiro
9  */
10 
11 /** \addtogroup Base
12 
13  @{*/
14 #ifndef FLASHFILTERFACTORY_H
15 #define FLASHFILTERFACTORY_H
16 
17 #include <iostream>
18 #include <map>
19 #include "BaseFlashFilter.h"
20 namespace flashmatch {
21 
22  /**
23  \class FlashFilterFactoryBase
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 BaseFlashFilter* create(const std::string instance_name) = 0;
34  };
35 
36  /**
37  \class FlashFilterFactory
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 FlashFilterFactory& get()
49  { if(!_me) _me = new FlashFilterFactory; 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::FlashFilterFactoryBase* factory)
52  { _factory_map[name] = factory; }
53  /// Factory creation method (should be called by clients, possibly you!)
54  BaseFlashFilter* 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::FlashFilterFactoryBase*> _factory_map;
67  /// Static self
69  };
70 }
71 #endif
72 /** @} */ // end of doxygen group
73 
Factory class for instantiating flash algorithm instance.
BaseFlashFilter * create(const std::string name, const std::string instance_name)
Factory creation method (should be called by clients, possibly you!)
BEGIN_PROLOG could also be cerr
FlashFilterFactory()
Default ctor, shouldn&#39;t be used.
Abstract base class for factory (to be implemented per flash)
void add_factory(const std::string name, flashmatch::FlashFilterFactoryBase *factory)
Factory registration method (should be called by global factory instance in algorithm header) ...
Class def header for a class BaseFlashFilter.
virtual BaseFlashFilter * create(const std::string instance_name)=0
Abstract constructor method.
std::map< std::string, flashmatch::FlashFilterFactoryBase * > _factory_map
Static factory container.
static FlashFilterFactory * _me
Static self.
virtual ~FlashFilterFactoryBase()
Default dtor (virtual)
then echo fcl name