#ifndef GRAPHIC_MAPPER_H
#define GRAPHIC_MAPPER_H

#include "configurator\CALreader.h"
#include "softProj\clientServer\sharedStructures.h"
#include "math\MyMath.h"
#include <map>
#include <string>
#include <vector>
#include <exception>

///Deterministic graphic generator.
/**
*	GraphicMapper is singleton class. At the begining graphic database is 
*	inserted into #GraphicMapper::graphicGeneratorDatabase and then
*	graphic data can be returned according to the internal deterministic value generator.
*/
class GraphicMapper
{
private:
	static GraphicMapper *instance;			/**<singleton instance*/
	
	GraphicMapper(void);					/**<singleton class, private constructor*/
	GraphicMapper( const GraphicMapper& ); /**<cannot be copied*/
	GraphicMapper& operator=( const GraphicMapper& ); /**<cannot be assigned*/

public:
	calSpace::GraphicGeneratorContainer graphicGeneratorDatabase;	/**<graphic database, graphic is selected from this database*/
	bool generateBaselineData( const ID baselineId, const string &planetType, BaselineData &dstData );	/**<returns generated BaselineData from #GraphicMapper::graphicGeneratorDatabase for given id and type*/
	bool generateOuterSurfaceTexure( const ID planetId, const string &planetType, string &dstTexName ); /**<returns generated textureName from #GraphicMapper::graphicGeneratorDatabase for given id and type*/
	static GraphicMapper* getInstance(void);	/**<returns instance of class*/
};


template< typename Item, typename Container >
Item getRandItemFromContainer( Container &container )
{
	assert( container.size() != 0 && "Container cannot be empty!!!" );
	float randNum = getRandomNumberFrom0To1();

	double newRandNum =  pow( randNum * container.size() + container.size() * container.size(), sqrtf(container.size()) );

	unsigned int randIdx = (unsigned int ) ( newRandNum ) %  container.size() ;
	return container.at(randIdx);
}

#endif