|
Packit |
47f805 |
/************************************************************************
|
|
Packit |
47f805 |
Project : C++ debugging class
|
|
Packit |
47f805 |
File version : 0.4
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
BSD License post 1999 :
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
Copyright (c) 2001, Steve Lhomme
|
|
Packit |
47f805 |
All rights reserved.
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
Redistribution and use in source and binary forms, with or without
|
|
Packit |
47f805 |
modification, are permitted provided that the following conditions are met:
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
- Redistributions of source code must retain the above copyright notice, this
|
|
Packit |
47f805 |
list of conditions and the following disclaimer.
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
- Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit |
47f805 |
this list of conditions and the following disclaimer in the documentation
|
|
Packit |
47f805 |
and/or other materials provided with the distribution.
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
- The name of the author may not be used to endorse or promote products derived
|
|
Packit |
47f805 |
from this software without specific prior written permission.
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
Packit |
47f805 |
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
Packit |
47f805 |
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
Packit |
47f805 |
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
Packit |
47f805 |
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
|
Packit |
47f805 |
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
47f805 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
47f805 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
Packit |
47f805 |
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
|
Packit |
47f805 |
OF SUCH DAMAGE.
|
|
Packit |
47f805 |
************************************************************************/
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
#if !defined(_DBG_H__INCLUDED_)
|
|
Packit |
47f805 |
#define _DBG_H__INCLUDED_
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
#include <windows.h>
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
static const int MAX_PREFIX_LENGTH = 128;
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
#if !defined(NDEBUG)
|
|
Packit |
47f805 |
// define the working debugging class
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
class ADbg
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
public:
|
|
Packit |
47f805 |
ADbg(int level = 0);
|
|
Packit |
47f805 |
virtual ~ADbg();
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
/// \todo make an inline function to test the level first and the process
|
|
Packit |
47f805 |
int OutPut(int level, const char * format,...) const;
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
int OutPut(const char * format,...) const;
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
inline int setLevel(const int level) {
|
|
Packit |
47f805 |
return my_level = level;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
inline bool setIncludeTime(const bool included = true) {
|
|
Packit |
47f805 |
return my_time_included = included;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
bool setDebugFile(const char * NewFilename);
|
|
Packit |
47f805 |
bool unsetDebugFile();
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
inline bool setUseFile(const bool usefile = true) {
|
|
Packit |
47f805 |
return my_use_file = usefile;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
inline const char * setPrefix(const char * string) {
|
|
Packit |
47f805 |
return strncpy(prefix, string, MAX_PREFIX_LENGTH);
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
private:
|
|
Packit |
47f805 |
int my_level;
|
|
Packit |
47f805 |
bool my_time_included;
|
|
Packit |
47f805 |
bool my_use_file;
|
|
Packit |
47f805 |
bool my_debug_output;
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
int _OutPut(const char * format,va_list params) const;
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
char prefix[MAX_PREFIX_LENGTH];
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
HANDLE hFile;
|
|
Packit |
47f805 |
};
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
#else // !defined(NDEBUG)
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
// define a class that does nothing (no output)
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
class ADbg
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
public:
|
|
Packit |
47f805 |
ADbg(int level = 0){}
|
|
Packit |
47f805 |
virtual ~ADbg() {}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
inline int OutPut(int level, const char * format,...) const {
|
|
Packit |
47f805 |
return 0;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
inline int OutPut(const char * format,...) const {
|
|
Packit |
47f805 |
return 0;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
inline int setLevel(const int level) {
|
|
Packit |
47f805 |
return level;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
inline bool setIncludeTime(const bool included = true) {
|
|
Packit |
47f805 |
return true;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
inline bool setDebugFile(const char * NewFilename) {
|
|
Packit |
47f805 |
return true;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
inline bool unsetDebugFile() {
|
|
Packit |
47f805 |
return true;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
inline bool setUseFile(const bool usefile = true) {
|
|
Packit |
47f805 |
return true;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
inline const char * setPrefix(const char * string) {
|
|
Packit |
47f805 |
return string;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
};
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
#endif // !defined(NDEBUG)
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
#endif // !defined(_DBG_H__INCLUDED_)
|