Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Patterns/Registry_impl.hpp

    rb59da6 r311d688  
    1515
    1616#include "Helpers/Assert.hpp"
    17 #include <iostream>
     17#include <iosfwd>
    1818
    1919/** Constructor for class Registry.
     
    2525 */
    2626template <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}
    2834
    2935/** Returns pointer to an instance named by \a name.
     
    3137 * \return pointer to instance
    3238 */
    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;
     39template <class T> T* Registry<T>::getByName(const std::string name){
     40  typename std::map<const std::string,T*>::iterator iter;
    3641  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");
    3843  return iter->second;
    3944}
     
    4247 * \note This is needed as Registry<T>::getByName() ASSERT()s that instance is in std::map.
    4348 * \param name name of instance
    44  * \return true - present, false - instance absent
     49 * \return true - v present, false - instance absent
    4550 */
    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;
     51template <class T>bool Registry<T>::isPresentByName(const std::string name){
     52  typename std::map<const std::string,T*>::iterator iter;
    4953  iter = InstanceMap.find(name);
    5054  return iter!=InstanceMap.end();
     
    5660template <class T>void Registry<T>::registerInstance(T* instance){
    5761  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;
    5963  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");
    6165}
    6266
     
    6569 */
    6670template <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;
    6872  InstanceMap.erase(instance->getName());
    6973}
    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 
    8274
    8375/** Returns an iterator pointing to the start of the std::map of instance's.
     
    136128 * at a chosen place.
    137129 */
    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;
    147139
    148140
Note: See TracChangeset for help on using the changeset viewer.