1 /************************************************************************ 2 Project : C++ debugging class 3 File version : 0.4 4 5 BSD License post 1999 : 6 7 Copyright (c) 2001, Steve Lhomme 8 All rights reserved. 9 10 Redistribution and use in source and binary forms, with or without 11 modification, are permitted provided that the following conditions are met: 12 13 - Redistributions of source code must retain the above copyright notice, this 14 list of conditions and the following disclaimer. 15 16 - Redistributions in binary form must reproduce the above copyright notice, 17 this list of conditions and the following disclaimer in the documentation 18 and/or other materials provided with the distribution. 19 20 - The name of the author may not be used to endorse or promote products derived 21 from this software without specific prior written permission. 22 23 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 24 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 26 EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 28 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 OF SUCH DAMAGE. 33 ************************************************************************/ 34 35 #if !defined(_DBG_H__INCLUDED_) 36 #define _DBG_H__INCLUDED_ 37 38 #include <windows.h> 39 40 static const int MAX_PREFIX_LENGTH = 128; 41 42 #if !defined(NDEBUG) 43 // define the working debugging class 44 45 class ADbg 46 { 47 public: 48 ADbg(int level = 0); 49 virtual ~ADbg(); 50 51 /// \todo make an inline function to test the level first and the process 52 int OutPut(int level, const char * format,...) const; 53 54 int OutPut(const char * format,...) const; 55 setLevel(const int level)56 inline int setLevel(const int level) { 57 return my_level = level; 58 } 59 60 inline bool setIncludeTime(const bool included = true) { 61 return my_time_included = included; 62 } 63 64 bool setDebugFile(const char * NewFilename); 65 bool unsetDebugFile(); 66 67 inline bool setUseFile(const bool usefile = true) { 68 return my_use_file = usefile; 69 } 70 setPrefix(const char * string)71 inline const char * setPrefix(const char * string) { 72 return strncpy(prefix, string, MAX_PREFIX_LENGTH); 73 } 74 75 private: 76 int my_level; 77 bool my_time_included; 78 bool my_use_file; 79 bool my_debug_output; 80 81 int _OutPut(const char * format,va_list params) const; 82 83 char prefix[MAX_PREFIX_LENGTH]; 84 85 HANDLE hFile; 86 }; 87 88 #else // !defined(NDEBUG) 89 90 // define a class that does nothing (no output) 91 92 class ADbg 93 { 94 public: 95 ADbg(int level = 0){} ~ADbg()96 virtual ~ADbg() {} 97 OutPut(int level,const char * format,...)98 inline int OutPut(int level, const char * format,...) const { 99 return 0; 100 } 101 OutPut(const char * format,...)102 inline int OutPut(const char * format,...) const { 103 return 0; 104 } 105 setLevel(const int level)106 inline int setLevel(const int level) { 107 return level; 108 } 109 110 inline bool setIncludeTime(const bool included = true) { 111 return true; 112 } 113 setDebugFile(const char * NewFilename)114 inline bool setDebugFile(const char * NewFilename) { 115 return true; 116 } 117 unsetDebugFile()118 inline bool unsetDebugFile() { 119 return true; 120 } 121 122 inline bool setUseFile(const bool usefile = true) { 123 return true; 124 } 125 setPrefix(const char * string)126 inline const char * setPrefix(const char * string) { 127 return string; 128 } 129 }; 130 131 #endif // !defined(NDEBUG) 132 133 #endif // !defined(_DBG_H__INCLUDED_) 134