Changes in src/Patterns/Registry_impl.hpp [b59da6:311d688]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Patterns/Registry_impl.hpp
rb59da6 r311d688 15 15 16 16 #include "Helpers/Assert.hpp" 17 #include <ios tream>17 #include <iosfwd> 18 18 19 19 /** Constructor for class Registry. … … 25 25 */ 26 26 template <class T> Registry<T>::~Registry() 27 {} 27 { 28 typename std::map<const std::string,T*>::iterator iter; 29 for(iter=InstanceMap.begin();iter!=InstanceMap.end();++iter) { 30 delete iter->second; 31 } 32 InstanceMap.clear(); 33 } 28 34 29 35 /** Returns pointer to an instance named by \a name. … … 31 37 * \return pointer to instance 32 38 */ 33 template <class T> T* Registry<T>::getByName(const std::string name) const 34 { 35 typename std::map<const std::string,T*>::const_iterator iter; 39 template <class T> T* Registry<T>::getByName(const std::string name){ 40 typename std::map<const std::string,T*>::iterator iter; 36 41 iter = InstanceMap.find(name); 37 ASSERT(iter!=InstanceMap.end(),"Query for an instance "+name+"not stored in registry");42 ASSERT(iter!=InstanceMap.end(),"Query for an instance not stored in registry"); 38 43 return iter->second; 39 44 } … … 42 47 * \note This is needed as Registry<T>::getByName() ASSERT()s that instance is in std::map. 43 48 * \param name name of instance 44 * \return true - present, false - instance absent49 * \return true - v present, false - instance absent 45 50 */ 46 template <class T>bool Registry<T>::isPresentByName(const std::string name) const 47 { 48 typename std::map<const std::string,T*>::const_iterator iter; 51 template <class T>bool Registry<T>::isPresentByName(const std::string name){ 52 typename std::map<const std::string,T*>::iterator iter; 49 53 iter = InstanceMap.find(name); 50 54 return iter!=InstanceMap.end(); … … 56 60 template <class T>void Registry<T>::registerInstance(T* instance){ 57 61 std::pair<typename std::map<const std::string,T*>::iterator,bool> ret; 58 // std::cout << "Trying to register instance of type " << typeid(T).name() << " with name " << instance->getName() << "." << std::endl;62 //cout << "Trying to register instance with name " << instance->getName() << "." << endl; 59 63 ret = InstanceMap.insert(typename std::pair<const std::string,T*>(instance->getName(),instance)); 60 ASSERT(ret.second,"Two instances with the same name "+instance->getName()+"added to registry");64 ASSERT(ret.second,"Two instances with the same name added to registry"); 61 65 } 62 66 … … 65 69 */ 66 70 template <class T>void Registry<T>::unregisterInstance(T* instance){ 67 // std::cout << "Unregistering instance of type " << typeid(T).name() << " with name " << instance->getName() << "." << std::endl;71 //cout << "Unregistering instance with name " << instance->getName() << "." << endl; 68 72 InstanceMap.erase(instance->getName()); 69 73 } 70 71 /** Removes every instance from the registry.72 */73 template <class T>void Registry<T>::cleanup()74 {75 typename std::map<const std::string,T*>::iterator iter;76 for(iter=InstanceMap.begin();iter!=InstanceMap.end();++iter) {77 delete iter->second;78 }79 InstanceMap.clear();80 }81 82 74 83 75 /** Returns an iterator pointing to the start of the std::map of instance's. … … 136 128 * at a chosen place. 137 129 */ 138 #define CONSTRUCT_REGISTRY( InstanceType) \139 template InstanceType* Registry<InstanceType>::getByName(const std::string) const; \140 template bool Registry< InstanceType>::isPresentByName(const std::string) const; \141 template void Registry< InstanceType>::registerInstance(InstanceType*); \142 template void Registry< InstanceType>::unregisterInstance(InstanceType*); \143 template std::map<const std::string, InstanceType*>::iterator Registry<InstanceType>::getBeginIter(); \144 template std::map<const std::string, InstanceType*>::const_iterator Registry<InstanceType>::getBeginIter() const; \145 template std::map<const std::string, InstanceType*>::iterator Registry<InstanceType>::getEndIter(); \146 template std::map<const std::string, InstanceType*>::const_iterator Registry<InstanceType>::getEndIter() const;130 #define CONSTRUCT_REGISTRY(name) \ 131 template name* Registry<name>::getByName(const std::string name); \ 132 template bool Registry<name>::isPresentByName(const std::string name); \ 133 template void Registry<name>::registerInstance(name*); \ 134 template void Registry<name>::unregisterInstance(name*); \ 135 template std::map<const std::string,name*>::iterator Registry<name>::getBeginIter(); \ 136 template std::map<const std::string,name*>::const_iterator Registry<name>::getBeginIter() const; \ 137 template std::map<const std::string,name*>::iterator Registry<name>::getEndIter(); \ 138 template std::map<const std::string,name*>::const_iterator Registry<name>::getEndIter() const; 147 139 148 140
Note:
See TracChangeset
for help on using the changeset viewer.