

/*!
  @author d金魚
  @since 2004/03/05
	@note
	licence:BSD Licence
*/


#ifndef _dkutil_random_access_adapter
#define _dkutil_random_access_adapter

namespace dkutil{

/*
Traitsとか勉強しなくちゃなぁ〜
まだ、未完成ナリ〜〜。
*/
template<class T,class CON_T,class MAP_T=std::map<unsigned long,CON_T::iterator> >
class random_access_adapter{
public:
	typedef T element_type;
	typedef T DATA_TYPE;
	typedef CON_T CONTAINER_TYPE;
	typedef MAP_T MAP_TYPE;
	typedef CON_T::size_type size_type;
private:
	MAP_TYPE mMap;
	CONTAINER_TYPE *mpList;
public:
	random_access_adapter(const CONTAINER_TYPE *ptr=NULL){
		reset(ptr);
	}
	virtual ~random_access_adapter(){
	
	}
	bool reset(const CONTAINER_TYPE *ptr){
		if(!ptr)return false;
		mpList = ptr;
		CONTAINER_TYPE &li = *ptr;
		CONTAINER_TYPE::const_iterator it=li.begin();
		for(size_type i=0;it != li.end();it++,i++)
		{
			mMap[i] = it;
		}
	}
	bool reset(cosnt CONTAINER_TYPE &x){
		return reset(&(x));
	}
	///添え字用の変数型はint ? size_type ?
	element_type &operator[](size_type po){
		return mMap[po];
	}
	const element_type &operator[](size_type po)const{
		return mMap[po];
	}



};

}//end of dkutil namepsace

#endif //end of include once