📄 trace.h
字号:
#ifndef _TRACE_H#define _TRACE_H/********************************************************************* $Id: Trace.h,v 1.2 1999/08/31 02:22:05 cullen Exp $ ********************************************************************* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. In addition to the terms and conditions set forth in the GNU Lesser General Public License, as a condition of using this library you are required to grant to all users of this library or any implementation utilizing or derived from this library a reciprocal, no cost, worldwide, perpetual, non-exclusive, non-transferable, unrestricted license to your claims of all patents and patent applications throughout the world that are infringed by the library or any implementation utilizing or derived from this library. In the event you redistribute this library or any implementation utilizing or derived from this library, you must prominently display the foregoing terms and conditions with the library or the implementation utilizing or derived from this library. In the event of a conflict of terms between the foregoing license grant and the terms set forth in the GNU Lesser General Public License, the foregoing terms and conditions shall be deemed to govern. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not; write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. Copyright 1999 Vovida Networks, Inc. All Rights Reserved. ********************************************************************* $Log: Trace.h,v $ Revision 1.2 1999/08/31 02:22:05 cullen updated header **********************************************************************/#include <string>#include <strstream>#include <iomanip.h>#include "Mutex.h"#define INIT_MHTRACE(level,stream) mh323::Tracer mh323::g_xTrace(level,stream)#define MHTRACE(level,message) \do{mh323::CriticalSection xCritical(mh323::g_xTrace.GetMutex()); \ if(!mh323::g_xTrace.isBusy()) \ {\ mh323::g_xTrace.setBusy(true); \ if(level<=mh323::g_xTrace.GetLevel()) \ { \ mh323::g_xTrace.PutTime(); \ mh323::g_xTrace.PutThreadId(); \ int i=mh323::g_xTrace.GetShift();\ while(i--) (*(mh323::g_xTrace.GetStream())) << " "; \ (*mh323::g_xTrace.GetStream())<< message <<endl; \ }\ mh323::g_xTrace.GetStream()->flush(); \ mh323::g_xTrace.setBusy(false); \ }\ } while (0)#define IN(functionName) mh323::AutoTrace xAT(functionName)/*#define MHTRACE(level,message) \{ \ std::ostrstream xTraceStream; \ xTraceStream<<message << ends;\ g_xTrace.trace(level,xTraceStream.str()); \ xTraceStream.freeze(); \}*/ namespace mh323{ class Tracer { public: Tracer(int iLevel, ostream * pxOstream); static void SetTraceLevel(int iLevel); static void SetTraceStream(ostream * pxOstream); void trace(int iLevel, const char * pxMessage); int GetLevel (void); void IncShift(void); void DecShift(void); int GetShift(void); void PutTime ( void ); void PutThreadId( void ); void setBusy( bool); bool isBusy( void ); ostream * GetStream (void); Mutex * GetMutex (void); protected: ostream * m_pxOstream; int m_iLevel; int m_iShift; bool m_bBusy; Mutex m_xMutex; }; extern Tracer g_xTrace; class AutoTrace { public: AutoTrace(const char * pcFunction) { m_pxName = pcFunction; MHTRACE(9,"in "<< m_pxName ); m_bflag=false; if(g_xTrace.GetLevel()>=9) { m_bflag = true; g_xTrace.IncShift(); }; } ~AutoTrace(void) { if (m_bflag) g_xTrace.DecShift(); MHTRACE(9,"out " << m_pxName ); } protected: std::string m_pxName; bool m_bflag; };}#endif // _TRACE_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -