
#ifndef DKUTIL_PARSER_RADIX_CONVERT_HPP
#define DKUTIL_PARSER_RADIX_CONVERT_HPP

#include <dkutil/macro.hpp>
#include <ctype.h>
#include <math.h>

namespace dkutil{

#ifdef UNICODE
#	error "多分、UNICODEだとradix_convertはエラーするでしょう。"
#endif
class radix_convert{
public://MessageBox

#define RADIX_CONVERT_LOCAL(R,PLUS){\
		const char enuCTOI_CHECK=48;\
		const char enuCTOI16_LOWER=97;\
		const char enuCTOI16_WUPPER=65;\
		const char *begin = s;\
		R ret;\
		ret = 0;\
		s = s+2;\
		register int i=strlen(s) - 1;\
		while(*s){\
			R tmp;\
			if('0'<=(*s) && '9' >= (*s))\
			{\
				tmp = static_cast<R>(pow(16,i));\
				ret += ((*s) - enuCTOI_CHECK) * tmp;\
			}else{\
				tmp = static_cast<R>(pow(16,i));\
				if(iswupper(*s))\
				{\
					ret += ((*s) - enuCTOI16_WUPPER + 10) * tmp;\
				}else{\
					ret += ((*s) - enuCTOI16_LOWER + 10) * tmp;\
				}\
			}\
			s++;\
			i--;\
		}\
		return ret + (PLUS);\
	}
	inline ULONGLONG a16toull(const char *s){
		RADIX_CONVERT_LOCAL(ULONGLONG,0)
	}
	inline UINT a16toui(const char *s){
		RADIX_CONVERT_LOCAL(UINT,0)
	}
	inline INT a16toi(const char *s){
		RADIX_CONVERT_LOCAL(INT,0)
	}
	inline LONGLONG a16toll(const char *s){
		RADIX_CONVERT_LOCAL(LONGLONG,0)
	}
};

/*
@param value[in] 変換する数字
@param stringoo[out] 結果の文字列
@param size[in] stringooバッファのサイズ
@param radix[in] value の値 (2 - 36 の範囲内)
@return trueなら成功

template<typename PARAM_>
class functor ...
inline bool integertoa(PARAM_ value,char *stringoo,size_t size,int radix){



}
*/
///ULONGLONG型の変数を文字列に変える
inline bool ulltoa(ULONGLONG ull,char *stringoo,size_t size){
	if(size <= ULONGLONG_MAX_STR_LEN) return false;//NULL文字考慮のため <= で比較
	_ui64toa(ull,stringoo,10);
	return true;
}

}//end of dkutil namespace




#endif//end of include once
