#pragma once
#pragma warning (disable:4996)
#define MAXLEN 256
#include <iostream>
namespace _Liuxb
{
class Conver
{
public:
static CString PChar2CString(const char* pParam)
{
return CString(pParam);
}
static CString PTCHAR2CString(const TCHAR* pParam)
{
return CString(pParam);
}
static TCHAR* CString2PTCHAR(CString &str,TCHAR* pTCHAR,int len)
{
TCHAR* pTemp = pTCHAR;
if(len>=str.GetLength()&&pTemp!=0)
{
lstrcpy(pTemp,str.GetBuffer(str.GetLength()));
str.ReleaseBuffer();
}
else
{
pTemp = 0;
}
return pTemp;
}
static char* TCHAR2Char(const TCHAR* pTCHAR,char* pCHAR,int charlen)
{
char* pTemp = pCHAR;
int tcharLen = 2*wcslen(pTCHAR);
if(tcharLen+1>charlen)
{
pTemp = 0;
}
else
{
wcstombs(pTemp,pTCHAR,tcharLen+1);
}
return pTemp;
}
static char* CString2PChar(CString& str,char* pChar,int len)
{
int size = 2*str.GetLength();
char* pTemp = pChar;
if(size+1>len)
{
pTemp = 0;
}
else
{
//wcstombs(pTemp,str,size+1);
USES_CONVERSION;
strcpy((LPSTR)pTemp,OLE2A(str.LockBuffer()));
}
return pTemp;
}
static int CStringToInt(const CString& srv)
{
return _tstoi(LPCTSTR(srv));
}
static CString IntToCString(int val)
{
CString text;
text.Format(_T("%d"),val);
return text;
}
};
template<BOOL ErrorMsg>
class MsgPrint
{
public:
MsgPrint(CString& msg):_msg(msg)
{
}
MsgPrint(LPCTSTR msg):_msg(msg)
{
}
public:
void operator ()()
{
::MessageBox(NULL,(LPCTSTR)_msg,_T("Error"),MB_OK);
}
private:
MsgPrint(MsgPrint& error);
private:
CString _msg;
};
template<>
class MsgPrint<FALSE>
{
public:
MsgPrint(CString& msg):_msg(msg)
{
}
MsgPrint(LPCTSTR msg):_msg(msg)
{
}
public:
void operator ()()
{
::MessageBox(NULL,(LPCTSTR)_msg,_T("Message"),MB_OK);
}
private:
MsgPrint(MsgPrint& error);
private:
CString _msg;
};
///用于debug跟踪测试内容
template<BOOL IsDebug>
class DebugPrint
{
public:
DebugPrint(CString printInfo)
{
_printInfo = CString(printInfo);
}
DebugPrint(TCHAR* pPrintInfo)
{
_printInfo = CString(pPrintInfo);
}
void operator ()()
{
char pTemp[MAXLEN];
memset(pTemp,0,MAXLEN);
Conver::CString2PChar(_printInfo,pTemp,MAXLEN);
std::cout<<pTemp<<std::endl;
}
inline DebugPrint operator+(DebugPrint& print)
{
_printInfo = _printInfo + print._printInfo;
return *this;
}
inline DebugPrint operator+(CString& print)
{
_printInfo = _printInfo + print;
return *this;
}
inline DebugPrint operator+(const TCHAR* pPrint)
{
CString print(pPrint);
*this = *this+print;
return *this;
}
~DebugPrint(void)
{}
private:
CString _printInfo;
};
///Release版本调试信息
template<>
class DebugPrint<FALSE>
{
public:
DebugPrint(CString printInfo)
{
}
DebugPrint(TCHAR* pPrintInfo)
{
}
void operator ()()
{
}
inline DebugPrint operator+(DebugPrint& print)
{
return *this;
}
inline DebugPrint operator+(CString& print)
{
return *this;
}
inline DebugPrint operator+(const TCHAR* pPrint)
{
return *this;
}
~DebugPrint(void)
{}
private:
CString _printInfo;
};
}
DebugPrint和字符串转换
最新推荐文章于 2021-05-17 01:31:36 发布