00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00037 #ifndef LIBEBML_DEBUG_H
00038 #define LIBEBML_DEBUG_H
00039
00040 #include <stdarg.h>
00041 #include <string.h>
00042
00043 #ifdef WIN32
00044 #include <windows.h>
00045 #else
00046 #include <stdio.h>
00047 #endif // WIN32
00048
00049 #include "EbmlConfig.h"
00050
00051 START_LIBEBML_NAMESPACE
00052
00053 static const int MAX_PREFIX_LENGTH = 128;
00054
00055 #if !defined(NDEBUG)
00056
00057
00058 class EBML_DLL_API ADbg
00059 {
00060 public:
00061 ADbg(int level = 0);
00062 virtual ~ADbg();
00063
00065 int OutPut(int level, const char * format,...) const;
00066
00067 int OutPut(const char * format,...) const;
00068
00069 inline int setLevel(const int level) {
00070 return my_level = level;
00071 }
00072
00073 inline bool setIncludeTime(const bool included = true) {
00074 return my_time_included = included;
00075 }
00076
00077 bool setDebugFile(const char * NewFilename);
00078 bool unsetDebugFile();
00079
00080 inline bool setUseFile(const bool usefile = true) {
00081 return my_use_file = usefile;
00082 }
00083
00084 inline const char * setPrefix(const char * string) {
00085 return strncpy(prefix, string, MAX_PREFIX_LENGTH);
00086 }
00087
00088 private:
00089 int my_level;
00090 bool my_time_included;
00091 bool my_use_file;
00092 bool my_debug_output;
00093
00094 int _OutPut(const char * format,va_list params) const;
00095
00096 char prefix[MAX_PREFIX_LENGTH];
00097
00098 #ifdef WIN32
00099 HANDLE hFile;
00100 #else
00101 FILE *hFile;
00102 #endif // WIN32
00103 };
00104
00105 #else // !defined(NDEBUG)
00106
00107
00108
00109 class EBML_DLL_API ADbg
00110 {
00111 public:
00112 ADbg(int level = 0){}
00113 virtual ~ADbg() {}
00114
00115 inline int OutPut(int level, const char * format,...) const {
00116 return 0;
00117 }
00118
00119 inline int OutPut(const char * format,...) const {
00120 return 0;
00121 }
00122
00123 inline int setLevel(const int level) {
00124 return level;
00125 }
00126
00127 inline bool setIncludeTime(const bool included = true) {
00128 return true;
00129 }
00130
00131 inline bool setDebugFile(const char * NewFilename) {
00132 return true;
00133 }
00134
00135 inline bool unsetDebugFile() {
00136 return true;
00137 }
00138
00139 inline bool setUseFile(const bool usefile = true) {
00140 return true;
00141 }
00142
00143 inline const char * setPrefix(const char * string) {
00144 return string;
00145 }
00146 };
00147
00148 #endif // !defined(NDEBUG)
00149
00150 extern class EBML_DLL_API ADbg globalDebug;
00151
00152
00153 #ifdef LIBEBML_DEBUG
00154 #define EBML_TRACE globalDebug.OutPut
00155 #else
00156 #define EBML_TRACE
00157 #endif
00158
00159
00160
00161
00162 #ifdef _MSC_VER
00163 #define EBML_ASSERT_NEW(p) if(p==0)throw std::bad_alloc()
00164 #else
00165 #define EBML_ASSERT_NEW(p) assert(p!=0)
00166 #endif
00167
00168 END_LIBEBML_NAMESPACE
00169
00170 #endif