Changes in src/Patterns/Registry_impl.hpp [311d688:b59da6]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Patterns/Registry_impl.hpp
r311d688 rb59da6 15 15 16 16 #include "Helpers/Assert.hpp" 17 #include <ios fwd>17 #include <iostream> 18 18 19 19 /** Constructor for class Registry. … … 25 25 */ 26 26 template <class T> Registry<T>::~Registry() 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 } 27 {} 34 28 35 29 /** Returns pointer to an instance named by \a name. … … 37 31 * \return pointer to instance 38 32 */ 39 template <class T> T* Registry<T>::getByName(const std::string name){ 40 typename std::map<const std::string,T*>::iterator iter; 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; 41 36 iter = InstanceMap.find(name); 42 ASSERT(iter!=InstanceMap.end(),"Query for an instance not stored in registry");37 ASSERT(iter!=InstanceMap.end(),"Query for an instance "+name+" not stored in registry"); 43 38 return iter->second; 44 39 } … … 47 42 * \note This is needed as Registry<T>::getByName() ASSERT()s that instance is in std::map. 48 43 * \param name name of instance 49 * \return true - vpresent, false - instance absent44 * \return true - present, false - instance absent 50 45 */ 51 template <class T>bool Registry<T>::isPresentByName(const std::string name){ 52 typename std::map<const std::string,T*>::iterator iter; 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; 53 49 iter = InstanceMap.find(name); 54 50 return iter!=InstanceMap.end(); … … 60 56 template <class T>void Registry<T>::registerInstance(T* instance){ 61 57 std::pair<typename std::map<const std::string,T*>::iterator,bool> ret; 62 // cout << "Trying to register instance with name " << instance->getName() << "." <<endl;58 //std::cout << "Trying to register instance of type " << typeid(T).name() << " with name " << instance->getName() << "." << std::endl; 63 59 ret = InstanceMap.insert(typename std::pair<const std::string,T*>(instance->getName(),instance)); 64 ASSERT(ret.second,"Two instances with the same name added to registry");60 ASSERT(ret.second,"Two instances with the same name "+instance->getName()+" added to registry"); 65 61 } 66 62 … … 69 65 */ 70 66 template <class T>void Registry<T>::unregisterInstance(T* instance){ 71 // cout << "Unregistering instance with name " << instance->getName() << "." <<endl;67 //std::cout << "Unregistering instance of type " << typeid(T).name() << " with name " << instance->getName() << "." << std::endl; 72 68 InstanceMap.erase(instance->getName()); 73 69 } 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 74 82 75 83 /** Returns an iterator pointing to the start of the std::map of instance's. … … 128 136 * at a chosen place. 129 137 */ 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;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; 139 147 140 148
Note:
See TracChangeset
for help on using the changeset viewer.