7 #ifndef __FWCORE_UTIL_FACTORYREGISTRY_HPP__ 8 #define __FWCORE_UTIL_FACTORYREGISTRY_HPP__ 10 #include "fwCore/mt/types.hpp" 26 template <
typename FACTORY_SIGNATURE,
typename KEY_TYPE = std::string,
27 typename FACTORY_HOLDER = std::function< FACTORY_SIGNATURE > >
31 typedef FACTORY_SIGNATURE FactorySignatureType;
32 typedef KEY_TYPE KeyType;
34 typedef FACTORY_HOLDER FactoryType;
35 typedef std::map< KeyType, FactoryType > RegistryType;
36 typedef std::vector<KeyType> KeyVectorType;
53 m_registry[name] = factory;
63 typename RegistryType::const_iterator iter = m_registry.find(key);
65 if(iter != m_registry.end())
67 factory = iter->second;
78 KeyVectorType vectKeys;
79 std::transform( m_registry.begin(), m_registry.end(),
80 std::back_inserter(vectKeys),
81 std::bind(&RegistryType::value_type::first, std::placeholders::_1) );
87 RegistryType m_registry;
88 mutable ::fwCore::mt::ReadWriteMutex m_mutex;
94 template <
typename F,
typename KEY_TYPE = std::
string,
typename FACTORY_HOLDER = std::function< F > >
97 template<
typename RETURN_TYPE,
typename KEY_TYPE,
typename FACTORY_HOLDER >
101 typedef RETURN_TYPE (FactorySignatureType)();
102 typedef FACTORY_HOLDER FactoryType;
103 typedef RETURN_TYPE ReturnType;
104 typedef KEY_TYPE KeyType;
112 ReturnType
create(
const KeyType& key)
const 125 template<
typename RETURN_TYPE,
typename ARG1_TYPE,
typename KEY_TYPE,
typename FACTORY_HOLDER >
129 typedef RETURN_TYPE (FactorySignatureType)(ARG1_TYPE);
130 typedef FACTORY_HOLDER FactoryType;
131 typedef RETURN_TYPE ReturnType;
132 typedef ARG1_TYPE Arg1Type;
133 typedef KEY_TYPE KeyType;
141 ReturnType
create(
const KeyType& key, Arg1Type &arg1)
const virtual KeyVectorType getFactoryKeys() const
returns the registered factory keys.
This namespace fwCore provides common foundations for FW4SPL.
::boost::unique_lock< ReadWriteMutex > WriteLock
Defines a lock of write type for read/write mutex.
Contains fwAtomsFilter::factory utilities.
ReturnType create(const KeyType &key, Arg1Type &arg1) const
Instantiates an object with the factory associated with the specified key, passing arg1 to the factor...
FactoryRegistryBase is a class used to store factories.
::boost::shared_lock< ReadWriteMutex > ReadLock
Defines a lock of read type for read/write mutex.
FactoryRegistry is a class used to store factories and create instance object with these factories...
void addFactory(const KeyType &name, FactoryType factory)
Add a factory to the registry.
ReturnType create(const KeyType &key) const
Instantiates an object with the factory associated with the specified key.
virtual FactoryType getFactory(const KeyType &key) const
returns the factory associated with the key.