/*
 *
 * Description  : Generates unique IDs
 * Author       : Anton�n M�ek antonin.misek@skoda-auto.cz
 *
 * Purpose      : Common class for generation of unique IDs
 */

#ifndef __UID__H__
#define __UID__H__

#include <wx/hashmap.h>
//#include <wx/string.h>
#include <vector>
#include "common.h"

namespace VRUT
{
	class Uid
	{
	private:
		WX_DECLARE_STRING_HASH_MAP(bool, UidsList);
		///List of uids to assure they are unique
		UidsList uidsList;
		std::vector<size_t> unums;
	public:
		//constructor
		Uid()
		{
		}
		~Uid()
		{
		}
		///Check if given uid is unique, generate new if not and add to list
		const wxString getUniqueUid(const wxString & uid, size_t index=0)
		{
			wxString unqUid = CloneWxString(uid);
			while (uidsList.find(unqUid) != uidsList.end())
				unqUid = uid+wxString::Format(wxT("_%lu"), (unsigned long)getUnum(index));
			uidsList.insert(UidsList::value_type(unqUid, false));
			return unqUid;
		}

		///Returns most probably unique number (rotating by size_t range)
		const size_t getUnum(size_t index=0)
		{
			if (index>=unums.size())
				unums.insert(unums.end(), index-unums.size()+1, 0);
			return unums.at(index)++;
		}
	};
}

#endif
