PdbClassMap.hh
#ifndef __PDBCLASSMAP_HH__
#define __PDBCLASSMAP_HH__
//
// This class is a singleton wrapper around the STL-map.
// It ensures EXACTLY one existing instance of 'classmap'.
//
// Author: Matthias Messer 6/22/99
#include <map>
#include <string.h>
//
// The char* comparison operator, required by the STL map
//
template <class T> PdbClassMap.hh.html">struct strless: binary_function<T, T, bool> {
bool operator()(const T& x, const T& y) const
{
return strcmp(x,y) < 0;
}
};
template <class T> class PdbClassMap {
public:
static PdbClassMap *instance();
virtual ~PdbClassMap();
T*& operator [] (const char * className) { return _map[className]; }
__rb_tree_iterator<pair<const char *const,T *>,pair<const char *const,T *> &,pair<const char *const,T *> *> find(const char * className) { return _map.find(className); }
__rb_tree_iterator<pair<const char *const,T *>,pair<const char *const,T *> &,pair<const char *const,T *> *> end() { return _map.end(); }
protected:
PdbClassMap();
private:
static PdbClassMap * _instance;
map<const char*, T*, strless<const char*> > _map;
};
template <class T> PdbClassMap<T>::PdbClassMap()
{
}
template <class T> PdbClassMap<T>::~PdbClassMap()
{
}
template <class T> PdbClassMap<T>* PdbClassMap<T>::instance()
{
if (!_instance)
_instance = new PdbClassMap<T>();
return _instance;
}
template <class T> PdbClassMap<T>* PdbClassMap<T>::_instance = 0;
#endif /* __PDBCLASSMAP_HH__ */