⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trace.hpp

📁 "More for C++" is a class library that provides some features that are usually common for object ori
💻 HPP
字号:
////  This file is part of the "More for C++" library////  Copyright (c) 1999-2003 by Thorsten Goertz (thorsten@morefor.org)////  The "More for C++" library is free software; you can redistribute it and/or//  modify it under the terms of the license that comes with this package.////  Read "license.txt" for more details.////  THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED//  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES//  OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.////////////////////////////////////////////////////////////////////////////////#ifndef MORE_UTIL_TRACE_HPP#define MORE_UTIL_TRACE_HPP////////////////////////////////////////////////////////////////////////////////#include <more/pointer.hpp>#include <more/stl.hpp>#include <more/string.hpp>/*//////////////////////////////////////////////////////////////////////////////Include this header and use the trace macros like this:  trace( Trace::WARN ) << "trace message" << end_trace;  -----                                      ---------There are four predefined trace levels:  Trace::DEBUG  Trace::INFO  Trace::WARN  Trace::ERRORThe set of trace levels could be modified easily with"addLevel" and "removeLevel".Per default, trace messages could be dumped to the consoleand/or a log file. Use "logToConsole" and/or "logToFile".The trace messages will be processed via the "Trace::Port"protocol. If an existing "legacy" trace implementationshould be used, you have to write an adapter classimplementing the "Trace::Port" interface. Thesesadapters will be activated and deactivatedvia "addPort" and "removePort"./*//////////////////////////////////////////////////////////////////////////////namespace more{  namespace util  {    class Trace    {      public:        static const size_t DEBUG; // = 0000 ( "Debug" )        static const size_t INFO;  // = 1000 ( "Info"  )        static const size_t WARN;  // = 2000 ( "Warn"  )        static const size_t ERROR; // = 3000 ( "Error" )        static const size_t NONE;  // = 4000 ( "None"  )        struct Level        {          size_t  value;          String  name;        };        typedef more::stl::Map<size_t, String> LevelMap;        static void addLevel( const Level& traceLevel );        static void removeLevel( size_t nLevel );        static p<LevelMap> getLevels( );        static String hex( size_t );        class Port        {          public:            virtual bool accept( size_t nLevel ) const = 0;            virtual void dump( size_t nLevel, const String& sMessage ) = 0;          protected:            virtual ~Port( );        };        static void addPort( const p<Port>& );        static void removePort( const p<Port>& );        static void logToConsole( size_t nMinLevel );        static void logToFile( const String& sFileName, size_t nMinLevel );        // will be used internally by the trace macros:        static bool accept( size_t nLevel );        static void dump( size_t nLevel, const String& sMessage );    };  }}////////////////////////////////////////////////////////////////////////////////#define trace( nLevel )                                                        \                                                                               \if( more::util::Trace::accept( nLevel ) )                                      \{                                                                              \  size_t        nPassedLevel = nLevel;                                         \  more::String  sTraceMessage;                                                 \                                                                               \  sTraceMessage#define trace_end "";                                                          \                                                                               \  more::util::Trace::dump( nPassedLevel, sTraceMessage );                      \}#define end_trace trace_end////////////////////////////////////////////////////////////////////////////////#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -