📄 tracetool.cpp.svn-base
字号:
//-------------------------------------------------------------------------
/// <summary>
/// send a node then change the indentation
/// </summary>
/// <param name="leftMsg" >Left message</param>
/// <param name="rightMsg">Optional right message</param>
void TraceNode::Indent (const wchar_t *leftMsg, const wchar_t *rightMsg)
{
if (enabled == false)
return ;
TraceNodeEx * Node;
Node = CreateChildEx (leftMsg, rightMsg) ; // create a new node using the last context as parent
Node->Send() ;
PushContextId (Node->id) ; // create a context based on the node id and the current thread
delete Node ;
}
//-------------------------------------------------------------------------
/// <summary>
/// Decrement indentation
/// </summary>
/// <param name="leftMsg" >Optional left message</param>
/// <param name="rightMsg">Optional right message</param>
void TraceNode::UnIndent (const char *leftMsg, const char *rightMsg)
{
if (enabled == false)
return ;
deleteLastContext() ;
TraceNodeEx * Node;
Node = CreateChildEx (leftMsg, rightMsg) ; // create a new node using the last context as parent
Node->Send() ;
delete Node ;
}
//-------------------------------------------------------------------------
/// <summary>
/// Decrement indentation
/// </summary>
/// <param name="leftMsg" >Optional left message</param>
/// <param name="rightMsg">Optional right message</param>
void TraceNode::UnIndent (const wchar_t *leftMsg, const wchar_t *rightMsg)
{
if (enabled == false)
return ;
deleteLastContext() ;
TraceNodeEx * Node;
Node = CreateChildEx (leftMsg, rightMsg) ; // create a new node using the last context as parent
Node->Send() ;
delete Node ;
}
//-------------------------------------------------------------------------
/// <summary>
/// create a context based on the node id and the current thread
/// </summary>
/// <param name="contextId" >Node id</param>
void TraceNode::PushContextId (const char * contextId)
{
NodeContext * context = new NodeContext() ;
context->nodeId = contextId ; // string copy (nodeId is a string not a char *)
context->threadId = GetCurrentThreadId() ;
if (contextList == NULL)
contextList = new deque <NodeContext *> ;
// enter the node context critical section
EnterCriticalSection (&criticalSection) ;
contextList->push_front (context) ;
LeaveCriticalSection (&criticalSection) ;
}
//-------------------------------------------------------------------------
/// <summary>
/// delete the last context for the current thread
/// </summary>
void TraceNode::deleteLastContext (void)
{
if (contextList == NULL) // should not happens
return ;
// if empty, no need to enter critical section
if (contextList->empty()) // should not happens
return ;
deque <NodeContext *>::iterator stack_end ;
deque <NodeContext *>::iterator stack_ptr ;
NodeContext * context ;
context = NULL ;
DWORD thid = GetCurrentThreadId();
// enter the node context critical section
EnterCriticalSection (&criticalSection) ;
// loop context for the current thread
stack_end = contextList->end() ;
for (stack_ptr = contextList->begin() ; stack_ptr < stack_end ; stack_ptr++)
{
NodeContext * context = * stack_ptr ;
if (context->threadId == thid)
{
delete context ;
contextList->erase (stack_ptr) ;
LeaveCriticalSection (&criticalSection) ;
return ;
}
}
LeaveCriticalSection (&criticalSection) ;
return ;
}
//-------------------------------------------------------------------------
/// <summary>
/// Retun the last context id for the current thread
/// </summary>
// called by CreateChildEx()
const char * TraceNode::GetLastContextId()
{
if (contextList == NULL)
return id ;
// if empty, no need to enter critical section
if (contextList->empty())
return id ;
char * result ;
result = id ;
deque<NodeContext *>::const_iterator stack_end ;
deque<NodeContext *>::const_iterator stack_ptr ;
DWORD thid = GetCurrentThreadId();
// enter the node context critical section
EnterCriticalSection (&criticalSection) ;
// loop context for the current thread
stack_end = contextList->end() ;
for (stack_ptr = contextList->begin() ; stack_ptr < stack_end ; stack_ptr++)
{
NodeContext * context = * stack_ptr ;
if (context->threadId == thid)
{
LeaveCriticalSection (&criticalSection) ;
return context->nodeId.c_str() ;
}
}
LeaveCriticalSection (&criticalSection) ;
return id ;
} ;
//-------------------------------------------------------------------------
/// <summary>
/// Create and send a trace node to the viewer
/// </summary>
/// <param name="leftMsg">the left message</param>
/// <param name="rightMsg">the optional right message</param>
void TraceNode::Send(const char *leftMsg, const char *rightMsg /* = NULL */)
{
if (enabled == false)
return ;
TraceNodeEx * Node;
Node = CreateChildEx (leftMsg, rightMsg) ;
Node->Send() ;
delete Node ;
}
//-------------------------------------------------------------------------
/// <summary>
/// Create and send a trace node to the viewer
/// </summary>
/// <param name="leftMsg">the left message</param>
/// <param name="rightMsg">the optional right message</param>
void TraceNode::Send(const wchar_t *wLeftMsg, const wchar_t *wRightMsg /* = NULL */)
{
if (enabled == false)
return ;
TraceNodeEx * Node;
char * LeftMsg = TTrace::WideToMbs (wLeftMsg) ;
char * RightMsg = TTrace::WideToMbs (wRightMsg) ;
Node = CreateChildEx (LeftMsg, RightMsg) ;
Node->Send() ;
delete Node ;
free (LeftMsg) ;
if (RightMsg != NULL)
free (RightMsg) ;
}
//-------------------------------------------------------------------------
/// <summary>
/// send a dump to the viewer
/// </summary>
/// <param name="leftMsg">Left message</param>
/// <param name="rightMsg">Optional right message</param>
/// <param name="title">The title that appears on top of the dump</param>
/// <param name="memory">The memory to dump</param>
/// <param name="byteCount"></param>
void TraceNode::SendDump (const char *leftMsg, const char *rightMsg, const char * title, const char * memory, const unsigned byteCount)
{
if (enabled == false)
return ;
TraceNodeEx * Node;
Node = CreateChildEx (leftMsg, rightMsg) ;
Node->AddDump (title, memory, 0 , byteCount) ;
Node->Send() ;
delete Node ;
}
//-------------------------------------------------------------------------
/// <summary>
/// send a dump to the viewer
/// </summary>
/// <param name="leftMsg">Left message</param>
/// <param name="rightMsg">Optional right message</param>
/// <param name="title">The title that appears on top of the dump</param>
/// <param name="memory">The memory to dump</param>
/// <param name="byteCount"></param>
void TraceNode::SendDump (const wchar_t *leftMsg, const wchar_t *rightMsg, const wchar_t * title, const char * memory, const unsigned byteCount)
{
if (enabled == false)
return ;
TraceNodeEx * Node;
Node = CreateChildEx (leftMsg, rightMsg) ;
Node->AddDump (title, memory, 0 , byteCount) ;
Node->Send() ;
delete Node ;
}
//==========================================================================
// TraceNodeEx
/// <summary>
/// Construct a new trace node, derived from a parent node
/// TraceNodeEx can also be created from another node (TraceNode or TraceNodeEx)
/// sample : TTrace::Debug()->CreateChildEx (left,right) ;
/// </summary>
/// <param name="parentNode">Parent node</param>
/// <param name="newNodeId">Node Id. If NULL, an unique Id is generated </param>
TraceNodeEx::TraceNodeEx(TraceNode * parentNode , const char * newNodeId )
: TraceNode( parentNode,newNodeId )
{
m_Members = NULL ; // create members only when needed
m_FontDetails = NULL ;
Commands = new CommandList() ;
// the only place where the node is created
if (parentNode == NULL)
{
Commands->Add(CST_NEW_NODE, NULL); // Parameter : Parent Node ID
} else {
Commands->Add(CST_NEW_NODE, parentNode->GetLastContextId()); // Parameter : Parent Node ID
}
Commands->Add(CST_TRACE_ID, id); // Id of the new node
}
//-------------------------------------------------------------------------
/// <summary>
/// Construct a new trace node, derived from a parent node
/// TraceNodeEx can also be created from another node (TraceNode or TraceNodeEx)
/// sample : TTrace::Debug()->CreateChildEx (left,right) ;
/// </summary>
/// <param name="parentNode">Parent node</param>
/// <param name="newNodeId">Node Id. If NULL, an unique Id is generated </param>
TraceNodeEx::TraceNodeEx(TraceNode * parentNode , const wchar_t * newNodeId )
: TraceNode( parentNode,newNodeId )
{
m_Members = NULL ; // create members only when needed
m_FontDetails = NULL ;
Commands = new CommandList() ;
// the only place where the node is created
if (parentNode == NULL)
{
Commands->Add(CST_NEW_NODE, NULL); // Parameter : Parent Node ID
} else {
Commands->Add(CST_NEW_NODE, parentNode->GetLastContextId()); // Parameter : Parent Node ID
}
Commands->Add(CST_TRACE_ID, id); // Id of the new node
}
//-------------------------------------------------------------------------
TraceNodeEx::TraceNodeEx(TraceNode * parentNode , bool generateUniqueId )
: TraceNode( parentNode,generateUniqueId )
{
m_Members = NULL ; // create members only when needed
m_FontDetails = NULL ;
Commands = new CommandList() ;
// the only place where the node is created
if (parentNode == NULL)
{
Commands->Add(CST_NEW_NODE, NULL); // Parameter : Parent Node ID
} else {
Commands->Add(CST_NEW_NODE, parentNode->GetLastContextId()); // Parameter : Parent Node ID
}
Commands->Add(CST_TRACE_ID, id); // Id of the new node
}
//-------------------------------------------------------------------------
/// <summary>
/// Normally destructors are not needed : TTrace::Send clear the node content.
/// It's usefull only if you create a node without sending it.
/// </summary>
TraceNodeEx::~TraceNodeEx(void)
{
delete Commands ;
if (m_Members != NULL) // happens only if the nodeEx is not send
delete m_Members ;
if (m_FontDetails != NULL) // happens only if the nodeEx is not send
{
deque <FontDetail *>::const_iterator FontDetailBegin;
deque <FontDetail *>::const_iterator FontDetailEnd;
FontDetailEnd = m_FontDetails->end () ;
for (FontDetailBegin = m_FontDetails->begin (); FontDetailBegin < FontDetailEnd ; FontDetailBegin++)
{
FontDetail * fontDetail = * FontDetailBegin ;
delete fontDetail ;
}
delete m_FontDetails ;
m_FontDetails = NULL ;
}
}
//-------------------------------------------------------------------------
/// <summary>
/// Set the IconIndex. This Method can be called only once.
/// Usefull only if you create the TraceNodeEx with NULL parentNode
/// <//summary>
void TraceNodeEx::SetIconIndex (const int newInconIndex)
{
iconIndex = newInconIndex ;
Commands->Add(CST_ICO_INDEX, iconIndex);
}
//-------------------------------------------------------------------------
/// <summary>
/// return the protected "members" list (and create it if needed)
/// <//summary>
TMemberNode * TraceNodeEx::Members()
{
if (m_Members == NULL)
m_Members = new TMemberNode() ;
return m_Members ;
}
//-------------------------------------------------------------------------
// Send must be reintroduce , because TraceNodeEx add a Send function without parameter.
void TraceNodeEx::Send (const char *leftMsg, const char *rightMsg)
{
TraceNode::Send (leftMsg, rightMsg) ;
}
//-------------------------------------------------------------------------
// Send must be reintroduce , because TraceNodeEx add a Send function without parameter.
void TraceNodeEx::Send (const wchar_t *leftMsg, const wchar_t *rightMsg)
{
TraceNode::Send (leftMsg, rightMsg) ;
}
//-------------------------------------------------------------------------
/// <summary>
/// Send the extended node to the viewer
/// <summary>
void TraceNodeEx::Send(void)
{
if (enabled == false
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -