LArOpenCV  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
ImageClusterFactory.h
Go to the documentation of this file.
1 
14 #ifndef IMAGECLUSTERFACTORY_H
15 #define IMAGECLUSTERFACTORY_H
16 
17 #include <iostream>
18 #include <map>
19 #include "Core/laropencv_base.h"
20 #include "Core/larbys.h"
21 namespace larcv {
22 
23  class ImageClusterBase;
24 
30  public:
36  virtual ImageClusterBase* create(const std::string instance_name) = 0;
37  };
38 
48 
49  public:
51  ImageClusterFactory() : laropencv_base("ImageClusterFactory")
52  {LARCV_WARNING((*this)) << "To have a factory access static object via ImageClusterFactory::get()!" << std::endl;}
56  static ImageClusterFactory& get()
57  { if(!_me) _me = new ImageClusterFactory; return *_me; }
59  void add_factory(const std::string name, larcv::ImageClusterFactoryBase* factory)
60  { _factory_map[name] = factory; }
62  ImageClusterBase* create(const std::string name, const std::string instance_name) {
63  auto iter = _factory_map.find(name);
64  if(iter == _factory_map.end() || !((*iter).second)) {
65  LARCV_ERROR((*this)) << "Found no registered class " << name << std::endl;
66  return nullptr;
67  }
68  return (*iter).second->create(instance_name);
69  }
70  private:
72  std::map<std::string,larcv::ImageClusterFactoryBase*> _factory_map;
75  };
76 }
77 #endif
78  // end of doxygen group
79