ADbg.h 3.4 KB

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