DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SegmentationFactory.h
Go to the documentation of this file.
1 /*
2  * SegmentationFactory.h
3  *
4  * Factory and helper classes to allow instantiation of segmentations by name.
5  *
6  * Created on: Dec 15, 2013
7  * Author: Christian Grefe, CERN
8  */
9 
10 #ifndef DDSegmentation_SEGMENTATIONFACTORY_H_
11 #define DDSegmentation_SEGMENTATIONFACTORY_H_
12 
14 
15 #include <map>
16 #include <vector>
17 #include <string>
18 
19 namespace DD4hep {
20 namespace DDSegmentation {
21 
23 class Segmentation;
24 class SegmentationCreatorBase;
25 
28 public:
30  SegmentationCreatorBase(const std::string& name);
34  virtual Segmentation* create(const std::string& identifier) const = 0;
35 };
36 
38 template<class TYPE> class SegmentationCreator : public SegmentationCreatorBase {
39 public:
41  SegmentationCreator<TYPE>(const std::string& name) : SegmentationCreatorBase(name) {};
43  virtual ~SegmentationCreator() {};
45  Segmentation* create(const std::string& identifier) const {return new TYPE(identifier);};
46 };
47 
52 public:
54  static SegmentationFactory* instance();
56  Segmentation* create(const std::string& name, const std::string& identifier = "") const;
58  std::vector<std::string> registeredSegmentations() const;
59 protected:
65  virtual ~SegmentationFactory() {};
67  void registerSegmentation(const std::string& name, SegmentationCreatorBase* creator);
69  std::map<std::string, SegmentationCreatorBase*> _segmentations;
70 private:
73 };
74 
75 } /* namespace DDSegmentation */
76 } /* namespace DD4hep */
77 #endif /* DDSegmentation_SEGMENTATIONFACTORY_H_ */
SegmentationFactory(const SegmentationFactory &)
Copy constructor.
static SegmentationFactory * _instance
The global factory instance.
Segmentation * create(const std::string &name, const std::string &identifier="") const
Create a new segmentation object with the given type name. Returns NULL if type name is unknown...
Base class for the SegmentationCreator objects. Allows to use the factory without template...
SegmentationCreatorBase(const std::string &name)
Default constructor. Takes the class name as argument and takes care of registration with the factory...
Factory for creating segmentation objects by type name.
void registerSegmentation(const std::string &name, SegmentationCreatorBase *creator)
Registers a new SegmentationCreator with the factory.
Segmentation * create(const std::string &identifier) const
Create a new object of the given type.
Base class for all segmentations.
Definition: Segmentation.h:68
Concrete class to create segmentation objects. Every segmentation needs to instantiate a static insta...
std::map< std::string, SegmentationCreatorBase * > _segmentations
Map to store SegmentationCreators by name.
virtual Segmentation * create(const std::string &identifier) const =0
Create a new object.
std::vector< std::string > registeredSegmentations() const
Access to the list of registered segmentations.
static SegmentationFactory * instance()
Access to the global factory instance.