#include <ptlib.h>

template <class V> class PNoCollisionDictionary
  : public PDictionary<PString, V>
{
public:

  PNoCollisionDictionary ()
    : PDictionary<PString, V> () {}

  void AddNoClash (const PString &key, V *val)
  {
    if (!PDictionary<PString, V>::Contains (key)) {

      (void)PDictionary<PString, V>::SetAt (key, val);
    } else {

      PString key_new = key + " [2]";
      for (int ii = 3; PDictionary<PString, V>::Contains (key_new); ii++)
	key_new = key + " [" + PString (ii) + "]";

      (void)PDictionary<PString, V>::SetAt (key_new, val);
    }
  }

  PStringList GetKeys ()
    {
      PStringList result;

      for (PINDEX index = 0; index < PContainer::GetSize (); index++)
	result += PDictionary<PString, V>::GetKeyAt (index);

      return result;
    }
};
