關于仿制的一個ACE跟蹤類
系統
1868 0
ACE有一個跟蹤類ACE_Trace,本文為了弄清這個跟蹤類,并增強一些功能,自己仿制一個Trace跟蹤類,這個類完全模仿ACE_Trace類,只是在開始增加了一個標題。這個標題你可以在#define時進行定制。
以下為頭文件:
//Trace.h
//
Trace.h:
//
#pragma
once
#define
ACE_NDEBUG0
#define
ACE_NTRACE0
#include
"
ace/log_msg.h
"
#include
"
ace/Object_Manager.h
"
class
Trace
...
{
public
:
Trace(
const
ACE_TCHAR
*
prefix,
const
ACE_TCHAR
*
name,
int
line,
const
ACE_TCHAR
*
file)
...
{
this
->
prefix_
=
prefix;
this
->
name_
=
name;
this
->
line_
=
line;
this
->
file_
=
file;
ACE_Log_Msg
*
lm
=
ACE_LOG_MSG;
if
(lm
->
tracing_enabled()
&&
lm
->
trace_active()
==
0
)
...
{
lm
->
trace_active(
1
);
ACE_DEBUG((LM_TRACE,
ACE_TEXT(
"
%s%*s(%t)calling%sinfile'%s'
"
)
ACE_TEXT(
"
online%d
"
),
this
->
prefix_,
Trace::nesting_indent_
*
lm
->
inc(),
ACE_TEXT(
""
),
this
->
name_,
this
->
file_,
this
->
line_));
lm
->
trace_active(
0
);
}
}
void
setLine(
int
line)
...
{
this
->
line_
=
line;
}
~
Trace(
void
)
...
{
ACE_Log_Msg
*
lm
=
ACE_LOG_MSG;
if
(lm
->
tracing_enabled()
&&
lm
->
trace_active()
==
0
)
...
{
lm
->
trace_active(
1
);
ACE_DEBUG
((LM_TRACE,
ACE_TEXT(
"
%s%*s(%t)leaving%sinfile'%s'
"
)
ACE_TEXT(
"
online%d
"
),
this
->
prefix_,
Trace::nesting_indent_
*
lm
->
dec(),
ACE_TEXT(
""
),
this
->
name_,
this
->
file_,
this
->
line_));
lm
->
trace_active(
0
);
}
}
private
:
enum
...
{nesting_indent_
=
3
}
;
const
ACE_TCHAR
*
prefix_;
const
ACE_TCHAR
*
name_;
const
ACE_TCHAR
*
file_;
int
line_;
}
;
#define
TRACE_PREFIXACE_TEXT("TRACE")
#if
(ACE_NTRACE==1)
#defineTRACE(X)
#defineTRACE_RETURN(V)
#defineTRACE_RETURN_VOID()
#else
#defineTRACE(X)
Trace____(TRACE_PREFIX,
ACE_TEXT(X),
__LINE__,
ACE_TEXT(__FILE__))
#defineTRACE_RETURN(V)
do
...
{____.setLine(__LINE__);
return
V;}
while
(
0
)
#defineTRACE_RETURN_VOID()
do
...
{____.setLine(__LINE__);}
while
(
0
)
#endif
下面為測試程序:
//
testTrace.cpp:Definestheentrypointfortheconsoleapplication.
//
#include
"
stdafx.h
"
#include
"
trace.h
"
int
test2()
...
{
TRACE(ACE_TEXT(
"
test2
"
));
return
0
;
}
int
test()
...
{
TRACE(ACE_TEXT(
"
Test
"
));
test2();
return
0
;
}
int
_tmain(
int
argc,_TCHAR
*
argv[])
...
{
TRACE(ACE_TEXT(
"
main
"
));
test();
return
0
;
}
以上程序皆是在vs2005上測試通過。
關于仿制的一個ACE跟蹤類
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元