/** @file stringtable.h
 *	Definition of string table for EABaseTypes
 *	@author Chris Burns (cburns@ea.com)
 *
 *	EABaseTypes
 *	(c) 2012 Electronic Arts Inc.
 */

#ifndef EABASETYPES_STRINGTABLE_H_
#define EABASETYPES_STRINGTABLE_H_

#include "EABaseTypes/string.h"

#include "eathread/eathread_futex.h"
#include "EASTLICA/hash_map.h"

namespace EA
{
	namespace Allocator
	{
		class ICoreAllocator;
	}

	class StringTable
	{
	public:

		StringTable(EA::Allocator::ICoreAllocator* allocator);

		~StringTable();

		//lint -efunc(904, EA::StringTable::Intern) 
		const RawString* Intern(const char* val);
		
		const RawString* Intern(const char* val, size_t length);

		void Release(const RawString* str);

#if defined(EA_RUNTIME_TESTING)
		int GetRefCount(const RawString* str);

		unsigned int GetSize();
#endif

		inline RawString* GetEmptyString() { return &mEmptyString; }

	private:

		EA::Thread::Futex				mLock;
		EA::Allocator::ICoreAllocator*	mAllocator;

		typedef EASTLICA::HashMap<RawString, int>	StringInternMap;
		StringInternMap					mTable;
		RawString						mEmptyString;

		StringTable(const StringTable& other);
		const StringTable& operator=(const StringTable& rhs);
	};
}

#endif // EABASETYPES_STRINGTABLE_H_
