// Copyright (C) 2004-2009 Christoph Kubisch & Eike Decker
// This file is part of the "Luxinia Engine".
// For conditions of distribution and use, see copyright notice in luxiniapublicsdk.txt
//
// <Author: Christoph Kubisch>


#ifndef __LUXCORE_STRINGMAP_H__
#define __LUXCORE_STRINGMAP_H__

#include <luxplatform/luxplatform.h>
#include <luxcore/memorygeneric.h>

#ifdef __cplusplus
extern "C"{
#endif

	//////////////////////////////////////////////////////////////////////////
	// CharStrDict
	//	uses a hash to manage a reference counted map of strings
	//	MemoryList used for allocations, ideally strings are <= 256
	
	typedef struct lxStrDict_s* lxStrDictPTR;

	lxStrDictPTR	lxStrDict_new(uint numBins);
	void			lxStrDict_delete(lxStrDictPTR dc);

	// returns hashkey
	uint32		lxStrDict_add(lxStrDictPTR dc, const char *str);
	const char* lxStrDict_getFromKey(lxStrDictPTR dc, uint32 key);
	uint32		lxStrDict_getKey(lxStrDictPTR dc, const char *str);

	// returns current reference count
	int			lxStrDict_rem(lxStrDictPTR dc, const char *str);
	int			lxStrDict_remKey(lxStrDictPTR dc, uint32 key);


	////////////////////////////////////////////////////////////////////////////////
	// CharStrMap
	//	associative char*->void* array
	//	data is put in a hash using the same keys the dictionary creates
	//	can use a shared dictionary, or creates its own


typedef struct lxStrMap_s*	lxStrMapPTR;

typedef void* (lxStrMap_Iterator_fn)(void* fnData,const char *,void *browseData);


#if defined(MEMORY_GENERIC_STATS)
	#define lxStrMap_new(bins,val,dc) lxStrMap_newTrace(bins,val,dc,__FILE__,__LINE__)
	lxStrMapPTR  lxStrMap_newTrace(uint numBins, uint valueSize, lxStrDictPTR dc, const char *file, int line);
#else
	lxStrMapPTR  lxStrMap_new(uint numBins, uint valueSize, lxStrDictPTR dc);
#endif

// returns TRUE when key was overwritten
booln	lxCharStrMap_set(lxStrMapPTR	self, const char *key, void *value);
void*	lxCharStrMap_get(lxStrMapPTR	self, const char *key);
void*	lxCharStrMap_getNth(lxStrMapPTR	self, uint n);
uint	lxCharStrMap_getCount(lxStrMapPTR	self);

// returns 1 on success
booln	lxCharStrMap_remove(lxStrMapPTR	self, const char *key);
booln	lxCharStrMap_isSet(lxStrMapPTR	self, const char *key);
void	lxCharStrMap_delete(lxStrMapPTR		self, void (*fnFree)(void*));

// iterator returns fnData for next call
void	lxCharStrMap_iterate(lxStrMapPTR	self, lxStrMap_Iterator_fn *itfunc, void *fnData);

#ifdef __cplusplus
}
#endif

#endif

