#pragma once
|
#ifndef _FUNCTIONS_HPP_
|
#define _FUNCTIONS_HPP_
|
|
static int AnsiToW(CStringA & Src, CStringW & Dest)
|
{
|
int j,l;
|
l=Src.GetLength();
|
j=MultiByteToWideChar(CP_ACP,0,Src,l,Dest.GetBuffer(l),l);
|
Dest.ReleaseBuffer(j);
|
return 0;
|
}
|
static int WToAnsi(CStringW & Src, CStringA & Dest)
|
{
|
int j,l;
|
l=Src.GetLength();
|
j=WideCharToMultiByte(CP_ACP,0,Src,l,Dest.GetBuffer(l*2),l*2,NULL,0);
|
Dest.ReleaseBuffer(j);
|
return 0;
|
}
|
inline int AnsiToT(CStringA & Src, CString & Dest)
|
{
|
#ifdef UNICODE
|
AnsiToW(Src,Dest);
|
#else
|
Dest=Src;
|
#endif
|
return 0;
|
}
|
static int TToAnsi(CString & Src, CStringA & Dest)
|
{
|
#ifdef UNICODE
|
WToAnsi(Src,Dest);
|
#else
|
Dest=Src;
|
#endif
|
return 0;
|
}
|
static int TToW(CString & Src, CStringW & Dest)
|
{
|
#ifdef UNICODE
|
Dest=Src;
|
#else
|
AnsiToW(Src,Dest);
|
#endif
|
return 0;
|
}
|
static int WToT(CStringW & Src, CString & Dest)
|
{
|
#ifdef UNICODE
|
Dest=Src;
|
#else
|
WToAnsi(Src,Dest);
|
#endif
|
return 0;
|
}
|
|
inline double GetTickCountmS()
|
{
|
LARGE_INTEGER perfreq;
|
LARGE_INTEGER percounter1; //,percounter2;
|
double time1; //,time2,timeinter1;
|
QueryPerformanceFrequency(&perfreq);
|
QueryPerformanceCounter(&percounter1);
|
// percounter1.QuadPart=rdtsc();
|
/* _asm {
|
RDTSC;
|
mov percounter1.LowPart,eax;
|
mov percounter1.HighPart,edx;
|
}
|
*/
|
time1=(double)percounter1.QuadPart/perfreq.QuadPart ;
|
// time2=(double)percounter2.QuadPart/perfreq.QuadPart ;
|
// timeinter1=time2-time1;
|
return (time1*1000);
|
};
|
inline double GetTimemS()
|
{
|
LARGE_INTEGER perfreq;
|
LARGE_INTEGER percounter1; //,percounter2;
|
double time1; //,time2,timeinter1;
|
QueryPerformanceFrequency(&perfreq);
|
QueryPerformanceCounter(&percounter1);
|
// percounter1.QuadPart=rdtsc();
|
/* _asm {
|
RDTSC;
|
mov percounter1.LowPart,eax;
|
mov percounter1.HighPart,edx;
|
}
|
*/
|
time1 = (double)percounter1.QuadPart / perfreq.QuadPart;
|
// time2=(double)percounter2.QuadPart/perfreq.QuadPart ;
|
// timeinter1=time2-time1;
|
return (time1 * 1000);
|
};
|
/*
|
template <class ST>
|
int Split(ST s1,ST divider, ST resultstr[])
|
{
|
int i,j,k,l;
|
// CString s2;
|
k=0;
|
i=0;
|
l=s1.GetLength();
|
for (i=0;k<l&&i<1024;i++)
|
{
|
j=s1.Find(divider,k);
|
if (j==-1)
|
{
|
resultstr[i]=s1.Mid(k);
|
i++;
|
break;
|
}
|
resultstr[i]=s1.Mid(k,j-k);
|
// s2.Format(_T("%d %d %d \r\n"),i,j,k);
|
// ::SysLog(s2);
|
k=j+divider.GetLength();
|
}
|
return i;
|
}
|
*/
|
//template int Split<CStringA>(CStringA a,CStringA b,CStringA c[]);
|
///*
|
static inline int Xtoi(const char * hexstr)
|
{
|
int i,j,k;
|
unsigned char ch;
|
k=0;j=0;
|
int len=(int)strlen(hexstr);
|
for (i=0;i<len;i++)
|
{
|
ch=hexstr[i];
|
if (ch>='0'&&ch<='9')
|
{
|
k=ch-'0';
|
j=j*16+k;
|
continue;
|
}
|
if (ch>='A'&&ch<='F')
|
{
|
k=ch-'A'+10;
|
j=j*16+k;
|
continue;
|
}
|
if (ch>='a'&&ch<='f')
|
{
|
k=ch-'a'+10;
|
j=j*16+k;
|
continue;
|
}
|
if (ch==' '||ch==' ')
|
{
|
continue;
|
}
|
break;
|
}
|
return j;
|
}
|
static inline int Xtoi(CString hexstr)
|
{
|
int i,j,k;
|
TCHAR ch;
|
k=0;j=0;
|
int len=hexstr.GetLength();
|
for (i=0;i<len;i++)
|
{
|
ch=hexstr[i];
|
if (ch>=_T('0')&&ch<=_T('9'))
|
{
|
k=ch-_T('0');
|
j=j*16+k;
|
continue;
|
}
|
if (ch>=_T('A')&&ch<=_T('F'))
|
{
|
k=ch-_T('A')+10;
|
j=j*16+k;
|
continue;
|
}
|
if (ch>=_T('a')&&ch<=_T('f'))
|
{
|
k=ch-_T('a')+10;
|
j=j*16+k;
|
continue;
|
}
|
if (ch==_T(' ')||ch==_T(' '))
|
{
|
continue;
|
}
|
break;
|
}
|
return j;
|
}
|
inline int Split(CString s1,CString divider,CString resultstr[])
|
{
|
int i,j,k,l;
|
// CString s2;
|
k=0;
|
i=0;
|
l=s1.GetLength();
|
for (i=0;k<l&&i<1024;i++)
|
{
|
j=s1.Find(divider,k);
|
if (j==-1)
|
{
|
resultstr[i]=s1.Mid(k);
|
i++;
|
break;
|
}
|
resultstr[i]=s1.Mid(k,j-k);
|
// s2.Format(_T("%d %d %d \r\n"),i,j,k);
|
// ::SysLog(s2);
|
k=j+divider.GetLength();
|
}
|
return i;
|
}
|
|
inline int Split(CStringA s1,CStringA divider,CStringA resultstr[])
|
{
|
int i,j,k,l;
|
// CString s2;
|
k=0;
|
i=0;
|
l=s1.GetLength();
|
for (i=0;k<l&&i<2048;i++)
|
{
|
j=s1.Find(divider,k);
|
if (j==-1)
|
{
|
resultstr[i]=s1.Mid(k);
|
i++;
|
break;
|
}
|
resultstr[i]=s1.Mid(k,j-k);
|
// s2.Format(_T("%d %d %d \r\n"),i,j,k);
|
// ::SysLog(s2);
|
k=j+divider.GetLength();
|
}
|
return i;
|
}
|
inline void DivideStringToArray(const CString& strSrc, const CString& strSeparator, CStringArray &arrayDest)
|
{
|
int startIndex = 0;
|
while (startIndex < strSrc.GetLength())
|
{
|
int endIndex = strSrc.Find(strSeparator, startIndex);
|
|
if (endIndex == -1)
|
{
|
endIndex = strSrc.GetLength();
|
}
|
|
arrayDest.Add(
|
strSrc.Mid(startIndex, endIndex - startIndex));
|
|
startIndex = endIndex + strSeparator.GetLength();
|
}
|
}
|
//*/
|
inline WCHAR* ToWChar(char * str)
|
{
|
//ÔÚGDI£«ÖУ¬ÓйØ×Ö·ûµÄ²ÎÊýÀàÐÍÈ«²¿¶¼ÊÇWCHARÀàÐ͵Ä
|
//¸Ãº¯ÊýÊǽ«´«Í³×Ö·û´®½øÐÐת»»
|
|
static WCHAR buffer[1024];
|
wmemset(buffer,0,1024);
|
//_wcsset(buffer,0);
|
MultiByteToWideChar(CP_ACP,0,str,(int)strlen(str),buffer,1024);
|
//LPCSTR
|
//WideCharToMultiByte(
|
return buffer;
|
}
|
|
|
inline void X_aligned_memcpy_sse2(void* dest, const void* src, const unsigned long size_t)
|
{
|
/*
|
__asm
|
{
|
mov esi, src; //src pointer
|
mov edi, dest; //dest pointer
|
|
mov ebx, size_t; //ebx is our counter
|
shr ebx, 7; //divide by 128 (8 * 128bit registers)
|
|
loop_copy:
|
prefetchnta 128[ESI]; //SSE2 prefetch
|
prefetchnta 160[ESI];
|
prefetchnta 192[ESI];
|
prefetchnta 224[ESI];
|
|
movdqa xmm0, 0[ESI]; //move data from src to registers
|
movdqa xmm1, 16[ESI];
|
movdqa xmm2, 32[ESI];
|
movdqa xmm3, 48[ESI];
|
movdqa xmm4, 64[ESI];
|
movdqa xmm5, 80[ESI];
|
movdqa xmm6, 96[ESI];
|
movdqa xmm7, 112[ESI];
|
|
movntdq 0[EDI], xmm0; //move data from registers to dest
|
movntdq 16[EDI], xmm1;
|
movntdq 32[EDI], xmm2;
|
movntdq 48[EDI], xmm3;
|
movntdq 64[EDI], xmm4;
|
movntdq 80[EDI], xmm5;
|
movntdq 96[EDI], xmm6;
|
movntdq 112[EDI], xmm7;
|
|
add esi, 128;
|
add edi, 128;
|
dec ebx;
|
|
jnz loop_copy; //loop please
|
sfence
|
//loop_copy_end:
|
}
|
*/
|
}
|
//*/
|
#endif //_FUNCTIONS_HPP_
|