IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
AttributeFactory.h
1 // AttributeFactory.h:
3 // -------------------
4 //
14 
15 #ifndef __IPSDKBASEPROCESSING_ATTRIBUTEFACTORY_H__
16 #define __IPSDKBASEPROCESSING_ATTRIBUTEFACTORY_H__
17 
18 // suppression warnings
19 // warning C4275: non dll-interface class 'boost::noncopyable_::noncopyable' used as base for dll-interface class 'ipsdk::processor::AttributeFactory'
20 // warning C4251: 'ipsdk::processor::AttributeFactory::_factoryMap' : class 'std::map<_Kty,_Ty>' needs to have dll-interface to be used by clients of class 'ipsdk::processor::AttributeFactory'
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 AttributeFactory : public boost::noncopyable
38 {
39 public:
41  static AttributeFactory& getInstance();
42 
43 protected:
49 
50 // methods
51 public:
53  bool isRegistredAttribute(const std::string& className) const;
54 
56  std::set<std::string> getRegistredAttributes() const;
57 
61  template <typename AttributeType>
62  void registerAttribute();
63 
67  template <typename AttributeType>
68  void unRegisterAttribute();
69 
73  const std::string& getAttributeName(const std::string& className) const;
74 
78  const std::string& getAttributeToolTip(const std::string& className) const;
79 
83  const std::string& getAttributeLibraryName(const std::string& className) const;
84 
89  const boost::filesystem::path& getAttributeHeaderPath(const std::string& className) const;
90 
94  AttributePtr createAttribute(const std::string& className) const;
95 
96 protected:
100  {
102  std::string _attributeName;
103 
105  std::string _attributeToolTip;
106 
109 
111  boost::filesystem::path _attributeHeaderPath;
112 
115  };
116 
120  void registerAttribute(const std::string& className,
121  const AttributeInfo& attributeInfo);
122 
126  void unRegisterAttribute(const std::string& className);
127 
128 // attributes
129 protected:
131  typedef std::map<std::string, AttributeInfo> FactoryMap;
132 
135 };
136 
139 
140 template <typename AttributeType>
141 inline void
143 {
144  // retrieve attribute class name
145  const std::string& className = AttributeType::getTypeName();
146 
147  // create an attribute information structure
148  AttributeInfo attributeInfo;
149  attributeInfo._attributeName = AttributeType::getObjectNameStr();
150  attributeInfo._attributeToolTip = AttributeType::getToolTipStr();
151  attributeInfo._attributeLibraryName = AttributeType::getLibraryNameStr();
152  attributeInfo._attributeHeaderPath = AttributeType::getHeaderPathStr();
153  attributeInfo._attributeCreator = &AttributeType::createBaseAttribute;
154 
155  // register attribute into collection
156  registerAttribute(className, attributeInfo);
157 }
158 
159 template <typename AttributeType>
160 inline void
162 {
163  // retrieve attribute class name
164  const std::string& className = AttributeType::getTypeName();
165 
166  // register attribute into collection
167  unRegisterAttribute(className);
168 }
169 
172 
173 } // end of namespace processor
174 } // end of namespace ipsdk
175 
176 #pragma warning (pop)
177 
178 #endif // __IPSDKBASEPROCESSING_ATTRIBUTEFACTORY_H__
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
#define IPSDKBASEPROCESSING_API
Import/Export macro for library IPSDKBaseProcessing.
Definition: IPSDKBaseProcessingExports.h:27
std::string _attributeName
attribute name
Definition: AttributeFactory.h:102
std::string _attributeLibraryName
attribute library name
Definition: AttributeFactory.h:108
Factory singleton allowing dynamic creation of registred attributes.
Definition: AttributeFactory.h:37
AttributeCreator _attributeCreator
attribute creation function
Definition: AttributeFactory.h:114
Predefined types for processing attributes managment.
Base types for multiplatform compatibility.
std::string _attributeToolTip
attribute tooltip
Definition: AttributeFactory.h:105
struct used to store attribute informations
Definition: AttributeFactory.h:99
boost::shared_ptr< BaseAttribute > AttributePtr
shared pointer to attribute
Definition: AttributeTypes.h:52
Definition of import/export macro for library.
boost::filesystem::path _attributeHeaderPath
attribute header path
Definition: AttributeFactory.h:111
AttributePtr(* AttributeCreator)()
attribute creator function
Definition: AttributeTypes.h:67
void unRegisterAttribute()
un register a previously registred attribute from factory
Definition: AttributeFactory.h:161
void registerAttribute()
register a new attribute into factory
Definition: AttributeFactory.h:142
FactoryMap _factoryMap
map storing string to attribute informations association
Definition: AttributeFactory.h:134
std::map< std::string, AttributeInfo > FactoryMap
map associating a class name to attribute informations
Definition: AttributeFactory.h:131