IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
ProcessorFactory.h
1 // ProcessorFactory.h:
3 // -------------------
4 //
14 
15 #ifndef __IPSDKBASEPROCESSING_PROCESSORFACTORY_H__
16 #define __IPSDKBASEPROCESSING_PROCESSORFACTORY_H__
17 
18 // suppression warnings
19 // warning C4275: non dll-interface class 'boost::noncopyable_::noncopyable' used as base for dll-interface class 'ipsdk::processor::ProcessorFactory'
20 // warning C4251: 'ipsdk::processor::ProcessorFactory::_factoryMap' : class 'std::map<_Kty,_Ty>' needs to have dll-interface to be used by clients of class 'ipsdk::processor::ProcessorFactory'
21 #pragma warning (push)
22 #pragma warning (disable : 4275 4251)
23 
26 #include <IPSDKUtil/BaseTypes.h>
27 #include <boost/noncopyable.hpp>
28 #include <map>
29 #include <set>
30 
31 namespace ipsdk {
32 namespace processor {
33 
36 
37 class IPSDKBASEPROCESSING_API ProcessorFactory : public boost::noncopyable
38 {
39 public:
41  static ProcessorFactory& getInstance();
42 
43 protected:
49 
50 // methods
51 public:
53  bool isRegistredProcessor(const std::string& className) const;
54 
56  std::set<std::string> getRegistredProcessors() const;
57 
61  template <typename ProcessorType>
62  void registerProcessor();
63 
67  template <typename ProcessorType>
68  void unRegisterProcessor();
69 
73  const std::string& getProcessorName(const std::string& className) const;
74 
78  const std::string& getProcessorToolTip(const std::string& className) const;
79 
83  const std::string& getProcessorLibraryName(const std::string& className) const;
84 
89  const boost::filesystem::path& getProcessorHeaderPath(const std::string& className) const;
90 
94  ProcessorPtr createProcessor(const std::string& className) const;
95 
96 protected:
100  {
102  std::string _processorName;
103 
105  std::string _processorToolTip;
106 
109 
111  boost::filesystem::path _processorHeaderPath;
112 
115  };
116 
120  void registerProcessor(const std::string& className,
121  const ProcessorInfo& processorInfo);
122 
126  void unRegisterProcessor(const std::string& className);
127 
128 // attributes
129 protected:
131  typedef std::map<std::string, ProcessorInfo> FactoryMap;
132 
135 };
136 
139 
140 template <typename ProcessorType>
141 inline void
143 {
144  // retrieve processor class name
145  const std::string& className = ProcessorType::getTypeName();
146 
147  // create an processor information structure
148  ProcessorInfo processorInfo;
149  processorInfo._processorName = ProcessorType::getObjectNameStr();
150  processorInfo._processorToolTip = ProcessorType::getToolTipStr();
151  processorInfo._processorLibraryName = ProcessorType::getLibraryNameStr();
152  processorInfo._processorHeaderPath = ProcessorType::getHeaderPathStr();
153  processorInfo._processorCreator = &ProcessorType::createBaseProcessor;
154 
155  // register processor into collection
156  registerProcessor(className, processorInfo);
157 }
158 
159 template <typename ProcessorType>
160 inline void
162 {
163  // retrieve processor class name
164  const std::string& className = ProcessorType::getTypeName();
165 
166  // register processor into collection
167  unRegisterProcessor(className);
168 }
169 
172 
173 } // end of namespace processor
174 } // end of namespace ipsdk
175 
176 #pragma warning (pop)
177 
178 #endif // __IPSDKBASEPROCESSING_PROCESSORFACTORY_H__
std::string _processorName
processor name
Definition: ProcessorFactory.h:102
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
boost::filesystem::path _processorHeaderPath
processor header path
Definition: ProcessorFactory.h:111
#define IPSDKBASEPROCESSING_API
Import/Export macro for library IPSDKBaseProcessing.
Definition: IPSDKBaseProcessingExports.h:27
std::map< std::string, ProcessorInfo > FactoryMap
map associating a class name to processor informations
Definition: ProcessorFactory.h:131
void registerProcessor()
register a new processor into factory
Definition: ProcessorFactory.h:142
ProcessorCreator _processorCreator
processor creation function
Definition: ProcessorFactory.h:114
FactoryMap _factoryMap
map storing string to processor informations association
Definition: ProcessorFactory.h:134
std::string _processorToolTip
processor tooltip
Definition: ProcessorFactory.h:105
ProcessorPtr(* ProcessorCreator)()
processor creator function
Definition: ProcessorTypes.h:112
Predefined types for processor management.
struct used to store processor informations
Definition: ProcessorFactory.h:99
Base types for multiplatform compatibility.
std::string _processorLibraryName
processor library name
Definition: ProcessorFactory.h:108
void unRegisterProcessor()
un register a previously registred processor from factory
Definition: ProcessorFactory.h:161
Factory singleton allowing dynamic creation of registred processors.
Definition: ProcessorFactory.h:37
Definition of import/export macro for library.
boost::shared_ptr< BaseProcessor > ProcessorPtr
shared pointer to processor class
Definition: ProcessorTypes.h:106