提交 | 用户 | age
|
4b03ae
|
1 |
#pragma once
|
Q |
2 |
#ifndef _FUNCTIONS_HPP_
|
|
3 |
#define _FUNCTIONS_HPP_
|
|
4 |
|
|
5 |
static int AnsiToW(CStringA & Src, CStringW & Dest)
|
|
6 |
{
|
|
7 |
int j,l;
|
|
8 |
l=Src.GetLength();
|
|
9 |
j=MultiByteToWideChar(CP_ACP,0,Src,l,Dest.GetBuffer(l),l);
|
|
10 |
Dest.ReleaseBuffer(j);
|
|
11 |
return 0;
|
|
12 |
}
|
|
13 |
static int WToAnsi(CStringW & Src, CStringA & Dest)
|
|
14 |
{
|
|
15 |
int j,l;
|
|
16 |
l=Src.GetLength();
|
|
17 |
j=WideCharToMultiByte(CP_ACP,0,Src,l,Dest.GetBuffer(l*2),l*2,NULL,0);
|
|
18 |
Dest.ReleaseBuffer(j);
|
|
19 |
return 0;
|
|
20 |
}
|
|
21 |
inline int AnsiToT(CStringA & Src, CString & Dest)
|
|
22 |
{
|
|
23 |
#ifdef UNICODE
|
|
24 |
AnsiToW(Src,Dest);
|
|
25 |
#else
|
|
26 |
Dest=Src;
|
|
27 |
#endif
|
|
28 |
return 0;
|
|
29 |
}
|
|
30 |
static int TToAnsi(CString & Src, CStringA & Dest)
|
|
31 |
{
|
|
32 |
#ifdef UNICODE
|
|
33 |
WToAnsi(Src,Dest);
|
|
34 |
#else
|
|
35 |
Dest=Src;
|
|
36 |
#endif
|
|
37 |
return 0;
|
|
38 |
}
|
|
39 |
static int TToW(CString & Src, CStringW & Dest)
|
|
40 |
{
|
|
41 |
#ifdef UNICODE
|
|
42 |
Dest=Src;
|
|
43 |
#else
|
|
44 |
AnsiToW(Src,Dest);
|
|
45 |
#endif
|
|
46 |
return 0;
|
|
47 |
}
|
|
48 |
static int WToT(CStringW & Src, CString & Dest)
|
|
49 |
{
|
|
50 |
#ifdef UNICODE
|
|
51 |
Dest=Src;
|
|
52 |
#else
|
|
53 |
WToAnsi(Src,Dest);
|
|
54 |
#endif
|
|
55 |
return 0;
|
|
56 |
}
|
|
57 |
|
|
58 |
inline double GetTickCountmS()
|
|
59 |
{
|
|
60 |
LARGE_INTEGER perfreq;
|
|
61 |
LARGE_INTEGER percounter1; //,percounter2;
|
|
62 |
double time1; //,time2,timeinter1;
|
|
63 |
QueryPerformanceFrequency(&perfreq);
|
|
64 |
QueryPerformanceCounter(&percounter1);
|
|
65 |
// percounter1.QuadPart=rdtsc();
|
|
66 |
/* _asm {
|
|
67 |
RDTSC;
|
|
68 |
mov percounter1.LowPart,eax;
|
|
69 |
mov percounter1.HighPart,edx;
|
|
70 |
}
|
|
71 |
*/
|
|
72 |
time1=(double)percounter1.QuadPart/perfreq.QuadPart ;
|
|
73 |
// time2=(double)percounter2.QuadPart/perfreq.QuadPart ;
|
|
74 |
// timeinter1=time2-time1;
|
|
75 |
return (time1*1000);
|
|
76 |
};
|
0ed438
|
77 |
inline double GetTimemS()
|
Q |
78 |
{
|
|
79 |
LARGE_INTEGER perfreq;
|
|
80 |
LARGE_INTEGER percounter1; //,percounter2;
|
|
81 |
double time1; //,time2,timeinter1;
|
|
82 |
QueryPerformanceFrequency(&perfreq);
|
|
83 |
QueryPerformanceCounter(&percounter1);
|
|
84 |
// percounter1.QuadPart=rdtsc();
|
|
85 |
/* _asm {
|
|
86 |
RDTSC;
|
|
87 |
mov percounter1.LowPart,eax;
|
|
88 |
mov percounter1.HighPart,edx;
|
|
89 |
}
|
|
90 |
*/
|
|
91 |
time1 = (double)percounter1.QuadPart / perfreq.QuadPart;
|
|
92 |
// time2=(double)percounter2.QuadPart/perfreq.QuadPart ;
|
|
93 |
// timeinter1=time2-time1;
|
|
94 |
return (time1 * 1000);
|
|
95 |
};
|
4b03ae
|
96 |
/*
|
Q |
97 |
template <class ST>
|
|
98 |
int Split(ST s1,ST divider, ST resultstr[])
|
|
99 |
{
|
|
100 |
int i,j,k,l;
|
|
101 |
// CString s2;
|
|
102 |
k=0;
|
|
103 |
i=0;
|
|
104 |
l=s1.GetLength();
|
|
105 |
for (i=0;k<l&&i<1024;i++)
|
|
106 |
{
|
|
107 |
j=s1.Find(divider,k);
|
|
108 |
if (j==-1)
|
|
109 |
{
|
|
110 |
resultstr[i]=s1.Mid(k);
|
|
111 |
i++;
|
|
112 |
break;
|
|
113 |
}
|
|
114 |
resultstr[i]=s1.Mid(k,j-k);
|
|
115 |
// s2.Format(_T("%d %d %d \r\n"),i,j,k);
|
|
116 |
// ::SysLog(s2);
|
|
117 |
k=j+divider.GetLength();
|
|
118 |
}
|
|
119 |
return i;
|
|
120 |
}
|
|
121 |
*/
|
|
122 |
//template int Split<CStringA>(CStringA a,CStringA b,CStringA c[]);
|
|
123 |
///*
|
|
124 |
static inline int Xtoi(const char * hexstr)
|
|
125 |
{
|
|
126 |
int i,j,k;
|
|
127 |
unsigned char ch;
|
|
128 |
k=0;j=0;
|
|
129 |
int len=(int)strlen(hexstr);
|
|
130 |
for (i=0;i<len;i++)
|
|
131 |
{
|
|
132 |
ch=hexstr[i];
|
|
133 |
if (ch>='0'&&ch<='9')
|
|
134 |
{
|
|
135 |
k=ch-'0';
|
|
136 |
j=j*16+k;
|
|
137 |
continue;
|
|
138 |
}
|
|
139 |
if (ch>='A'&&ch<='F')
|
|
140 |
{
|
|
141 |
k=ch-'A'+10;
|
|
142 |
j=j*16+k;
|
|
143 |
continue;
|
|
144 |
}
|
|
145 |
if (ch>='a'&&ch<='f')
|
|
146 |
{
|
|
147 |
k=ch-'a'+10;
|
|
148 |
j=j*16+k;
|
|
149 |
continue;
|
|
150 |
}
|
|
151 |
if (ch==' '||ch==' ')
|
|
152 |
{
|
|
153 |
continue;
|
|
154 |
}
|
|
155 |
break;
|
|
156 |
}
|
|
157 |
return j;
|
|
158 |
}
|
|
159 |
static inline int Xtoi(CString hexstr)
|
|
160 |
{
|
|
161 |
int i,j,k;
|
|
162 |
TCHAR ch;
|
|
163 |
k=0;j=0;
|
|
164 |
int len=hexstr.GetLength();
|
|
165 |
for (i=0;i<len;i++)
|
|
166 |
{
|
|
167 |
ch=hexstr[i];
|
|
168 |
if (ch>=_T('0')&&ch<=_T('9'))
|
|
169 |
{
|
|
170 |
k=ch-_T('0');
|
|
171 |
j=j*16+k;
|
|
172 |
continue;
|
|
173 |
}
|
|
174 |
if (ch>=_T('A')&&ch<=_T('F'))
|
|
175 |
{
|
|
176 |
k=ch-_T('A')+10;
|
|
177 |
j=j*16+k;
|
|
178 |
continue;
|
|
179 |
}
|
|
180 |
if (ch>=_T('a')&&ch<=_T('f'))
|
|
181 |
{
|
|
182 |
k=ch-_T('a')+10;
|
|
183 |
j=j*16+k;
|
|
184 |
continue;
|
|
185 |
}
|
|
186 |
if (ch==_T(' ')||ch==_T(' '))
|
|
187 |
{
|
|
188 |
continue;
|
|
189 |
}
|
|
190 |
break;
|
|
191 |
}
|
|
192 |
return j;
|
|
193 |
}
|
|
194 |
inline int Split(CString s1,CString divider,CString resultstr[])
|
|
195 |
{
|
|
196 |
int i,j,k,l;
|
|
197 |
// CString s2;
|
|
198 |
k=0;
|
|
199 |
i=0;
|
|
200 |
l=s1.GetLength();
|
|
201 |
for (i=0;k<l&&i<1024;i++)
|
|
202 |
{
|
|
203 |
j=s1.Find(divider,k);
|
|
204 |
if (j==-1)
|
|
205 |
{
|
|
206 |
resultstr[i]=s1.Mid(k);
|
|
207 |
i++;
|
|
208 |
break;
|
|
209 |
}
|
|
210 |
resultstr[i]=s1.Mid(k,j-k);
|
|
211 |
// s2.Format(_T("%d %d %d \r\n"),i,j,k);
|
|
212 |
// ::SysLog(s2);
|
|
213 |
k=j+divider.GetLength();
|
|
214 |
}
|
|
215 |
return i;
|
|
216 |
}
|
|
217 |
|
|
218 |
inline int Split(CStringA s1,CStringA divider,CStringA resultstr[])
|
|
219 |
{
|
|
220 |
int i,j,k,l;
|
|
221 |
// CString s2;
|
|
222 |
k=0;
|
|
223 |
i=0;
|
|
224 |
l=s1.GetLength();
|
|
225 |
for (i=0;k<l&&i<2048;i++)
|
|
226 |
{
|
|
227 |
j=s1.Find(divider,k);
|
|
228 |
if (j==-1)
|
|
229 |
{
|
|
230 |
resultstr[i]=s1.Mid(k);
|
|
231 |
i++;
|
|
232 |
break;
|
|
233 |
}
|
|
234 |
resultstr[i]=s1.Mid(k,j-k);
|
|
235 |
// s2.Format(_T("%d %d %d \r\n"),i,j,k);
|
|
236 |
// ::SysLog(s2);
|
|
237 |
k=j+divider.GetLength();
|
|
238 |
}
|
|
239 |
return i;
|
|
240 |
}
|
0ed438
|
241 |
inline void DivideStringToArray(const CString& strSrc, const CString& strSeparator, CStringArray &arrayDest)
|
Q |
242 |
{
|
|
243 |
int startIndex = 0;
|
|
244 |
while (startIndex < strSrc.GetLength())
|
|
245 |
{
|
ad1b4b
|
246 |
int endIndex = strSrc.Find(strSeparator, startIndex);
|
0ed438
|
247 |
|
Q |
248 |
if (endIndex == -1)
|
|
249 |
{
|
|
250 |
endIndex = strSrc.GetLength();
|
|
251 |
}
|
|
252 |
|
|
253 |
arrayDest.Add(
|
|
254 |
strSrc.Mid(startIndex, endIndex - startIndex));
|
|
255 |
|
|
256 |
startIndex = endIndex + strSeparator.GetLength();
|
|
257 |
}
|
|
258 |
}
|
4b03ae
|
259 |
//*/
|
Q |
260 |
inline WCHAR* ToWChar(char * str)
|
|
261 |
{
|
|
262 |
//在GDI+中,有关字符的参数类型全部都是WCHAR类型的
|
|
263 |
//该函数是将传统字符串进行转换
|
|
264 |
|
|
265 |
static WCHAR buffer[1024];
|
|
266 |
wmemset(buffer,0,1024);
|
|
267 |
//_wcsset(buffer,0);
|
|
268 |
MultiByteToWideChar(CP_ACP,0,str,(int)strlen(str),buffer,1024);
|
|
269 |
//LPCSTR
|
|
270 |
//WideCharToMultiByte(
|
|
271 |
return buffer;
|
|
272 |
}
|
|
273 |
|
|
274 |
|
|
275 |
inline void X_aligned_memcpy_sse2(void* dest, const void* src, const unsigned long size_t)
|
|
276 |
{
|
|
277 |
/*
|
|
278 |
__asm
|
|
279 |
{
|
|
280 |
mov esi, src; //src pointer
|
|
281 |
mov edi, dest; //dest pointer
|
|
282 |
|
|
283 |
mov ebx, size_t; //ebx is our counter
|
|
284 |
shr ebx, 7; //divide by 128 (8 * 128bit registers)
|
|
285 |
|
|
286 |
loop_copy:
|
|
287 |
prefetchnta 128[ESI]; //SSE2 prefetch
|
|
288 |
prefetchnta 160[ESI];
|
|
289 |
prefetchnta 192[ESI];
|
|
290 |
prefetchnta 224[ESI];
|
|
291 |
|
|
292 |
movdqa xmm0, 0[ESI]; //move data from src to registers
|
|
293 |
movdqa xmm1, 16[ESI];
|
|
294 |
movdqa xmm2, 32[ESI];
|
|
295 |
movdqa xmm3, 48[ESI];
|
|
296 |
movdqa xmm4, 64[ESI];
|
|
297 |
movdqa xmm5, 80[ESI];
|
|
298 |
movdqa xmm6, 96[ESI];
|
|
299 |
movdqa xmm7, 112[ESI];
|
|
300 |
|
|
301 |
movntdq 0[EDI], xmm0; //move data from registers to dest
|
|
302 |
movntdq 16[EDI], xmm1;
|
|
303 |
movntdq 32[EDI], xmm2;
|
|
304 |
movntdq 48[EDI], xmm3;
|
|
305 |
movntdq 64[EDI], xmm4;
|
|
306 |
movntdq 80[EDI], xmm5;
|
|
307 |
movntdq 96[EDI], xmm6;
|
|
308 |
movntdq 112[EDI], xmm7;
|
|
309 |
|
|
310 |
add esi, 128;
|
|
311 |
add edi, 128;
|
|
312 |
dec ebx;
|
|
313 |
|
|
314 |
jnz loop_copy; //loop please
|
|
315 |
sfence
|
|
316 |
//loop_copy_end:
|
|
317 |
}
|
|
318 |
*/
|
|
319 |
}
|
|
320 |
//*/
|
|
321 |
#endif //_FUNCTIONS_HPP_ |