📄 debug.cpp
字号:
// Debug.cpp: implementation of the CDebug class.
//
//////////////////////////////////////////////////////////////////////
#include "Debug.h"
#include <utf.h>
#include <eikenv.h>
_LIT(KEndLine, "\n");
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDebug::CDebug()
{
}
CDebug::~CDebug()
{
iFile.Flush();
iFile.Close();
iRFs.Close();
}
void CDebug::ConstructL(const TDesC& aFileName)
{
//_LIT(KFilename,"c:\\debug.txt"); // filename
User::LeaveIfError(iRFs.Connect());
User::LeaveIfError(iFile.Replace(iRFs, aFileName, EFileWrite));
}
CDebug* CDebug::NewL(const TDesC& aFileName)
{
CDebug* self = CDebug::NewLC(aFileName);
CleanupStack::Pop();
return self;
}
CDebug* CDebug::NewLC(const TDesC& aFileName)
{
CDebug* self = new (ELeave) CDebug;
CleanupStack::PushL(self);
self->ConstructL(aFileName);
return self;
}
void CDebug::WriteInfo(const TDesC& aInformation)
{
TInt size = aInformation.Size();
HBufC8* hBuf = HBufC8::NewLC(size);
TPtr8 ptr(hBuf->Des());
ConvertTDes16ToTDes8(aInformation, ptr);
iFile.Write(ptr);
CleanupStack::PopAndDestroy(hBuf);
}
void CDebug::EndLine()
{
WriteInfo(KEndLine);
iFile.Flush();
}
void CDebug::WriteInfoN(const TDesC& aInformation)
{
WriteInfo(aInformation);
WriteInfo(KEndLine);
}
TInt CDebug::ConvertTDes8ToTDes16(const TDesC8& aFrom, TDes16& aTo)
{
return(CnvUtfConverter::ConvertToUnicodeFromUtf8(aTo, aFrom));
}
TInt CDebug::ConvertTDes16ToTDes8(const TDesC16& aFrom, TDes8& aTo)
{
return(CnvUtfConverter::ConvertFromUnicodeToUtf8(aTo, aFrom));
}
/////////////////////////////////////////////////////////////////////////////
void CStaticDebug::WriteInt(const TInt aInteger)
{
TBuf<16> integerString;
integerString.Num(aInteger);
WriteInfo(integerString);
}
void CStaticDebug::WriteIntN(const TInt aInteger)
{
TBuf<18> integerString;
integerString.Num(aInteger);
integerString.Append(KEndLine);
WriteInfo(integerString);
}
void CStaticDebug::WriteReal(const TReal aReal)
{
TBuf<KDefaultRealWidth> x;
x.Num(aReal, TRealFormat(KDefaultRealWidth, 3));
WriteInfo(x);
}
void CStaticDebug::WriteRealN(const TReal aReal)
{
TBuf<KDefaultRealWidth+2> x;
x.Num(aReal, TRealFormat(KDefaultRealWidth, 3));
x.Append(KEndLine);
WriteInfo(x);
}
void CStaticDebug::WriteInfo(const TDesC& aInformation)
{
RFs rfs;
RFile file;
CleanupClosePushL(rfs);
CleanupClosePushL(file);
User::LeaveIfError(rfs.Connect());
if (file.Create(rfs, _L("c:\\debugStatic.txt"), EFileWrite) == KErrAlreadyExists)
{
User::LeaveIfError(file.Open(rfs, _L("c:\\debugStatic.txt"), EFileWrite));
TInt size2 = 0;
User::LeaveIfError(file.Seek(ESeekEnd, size2));
}
TInt size = aInformation.Size();
HBufC8* hBuf = HBufC8::NewLC(size);
TPtr8 ptr(hBuf->Des());
ConvertTDes16ToTDes8(aInformation, ptr);
file.Write(ptr);
file.Flush();
CleanupStack::PopAndDestroy(&file);
CleanupStack::PopAndDestroy(&rfs);
CleanupStack::PopAndDestroy(hBuf);
}
void CStaticDebug::EndLine()
{
WriteInfo(KEndLine);
}
void CStaticDebug::WriteInfoN(const TDesC& aInformation)
{
RFs rfs;
RFile file;
CleanupClosePushL(rfs);
CleanupClosePushL(file);
User::LeaveIfError(rfs.Connect());
if (file.Create(rfs, _L("c:\\debugStatic.txt"), EFileWrite) == KErrAlreadyExists)
{
User::LeaveIfError(file.Open(rfs, _L("c:\\debugStatic.txt"), EFileWrite));
TInt size2 = 0;
User::LeaveIfError(file.Seek(ESeekEnd, size2));
}
TInt size = aInformation.Size();
HBufC8* hBuf = HBufC8::NewLC(size);
TPtr8 ptr(hBuf->Des());
ConvertTDes16ToTDes8(aInformation, ptr);
file.Write(ptr);
file.Flush();
CleanupStack::PopAndDestroy(hBuf);
size = ((const TDesC&)KEndLine).Size();
hBuf = HBufC8::NewLC(size);
TPtr8 ptr2(hBuf->Des());
ConvertTDes16ToTDes8(KEndLine, ptr2);
file.Write(ptr2);
file.Flush();
CleanupStack::PopAndDestroy(hBuf);
CleanupStack::PopAndDestroy(&file);
CleanupStack::PopAndDestroy(&rfs);
}
void CStaticDebug::Delete()
{
RFs rfs;
CleanupClosePushL(rfs);
User::LeaveIfError(rfs.Connect());
rfs.Delete(_L("c:\\debugStatic.txt"));
CleanupStack::PopAndDestroy(&rfs);
}
TInt CStaticDebug::ConvertTDes8ToTDes16(const TDesC8& aFrom, TDes16& aTo)
{
return CnvUtfConverter::ConvertToUnicodeFromUtf8(aTo,aFrom);
}
TInt CStaticDebug::ConvertTDes16ToTDes8(const TDesC16& aFrom, TDes8& aTo)
{
return CnvUtfConverter::ConvertFromUnicodeToUtf8(aTo,aFrom);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -