1159b3361Sopenharmony_ci/************************************************************************
2159b3361Sopenharmony_ciProject               : C++ debugging class
3159b3361Sopenharmony_ciFile version          : 0.4
4159b3361Sopenharmony_ci
5159b3361Sopenharmony_ciBSD License post 1999 :
6159b3361Sopenharmony_ci
7159b3361Sopenharmony_ciCopyright (c) 2001, Steve Lhomme
8159b3361Sopenharmony_ciAll rights reserved.
9159b3361Sopenharmony_ci
10159b3361Sopenharmony_ciRedistribution and use in source and binary forms, with or without
11159b3361Sopenharmony_cimodification, are permitted provided that the following conditions are met:
12159b3361Sopenharmony_ci
13159b3361Sopenharmony_ci- Redistributions of source code must retain the above copyright notice, this
14159b3361Sopenharmony_cilist of conditions and the following disclaimer.
15159b3361Sopenharmony_ci
16159b3361Sopenharmony_ci- Redistributions in binary form must reproduce the above copyright notice,
17159b3361Sopenharmony_cithis list of conditions and the following disclaimer in the documentation
18159b3361Sopenharmony_ciand/or other materials provided with the distribution.
19159b3361Sopenharmony_ci
20159b3361Sopenharmony_ci- The name of the author may not be used to endorse or promote products derived
21159b3361Sopenharmony_cifrom this software without specific prior written permission.
22159b3361Sopenharmony_ci
23159b3361Sopenharmony_ciTHIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
24159b3361Sopenharmony_ciWARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25159b3361Sopenharmony_ciMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
26159b3361Sopenharmony_ciEVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27159b3361Sopenharmony_ciEXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
28159b3361Sopenharmony_ciOF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29159b3361Sopenharmony_ciINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30159b3361Sopenharmony_ciCONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31159b3361Sopenharmony_ciIN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32159b3361Sopenharmony_ciOF SUCH DAMAGE.
33159b3361Sopenharmony_ci************************************************************************/
34159b3361Sopenharmony_ci
35159b3361Sopenharmony_ci#if !defined(_DBG_H__INCLUDED_)
36159b3361Sopenharmony_ci#define _DBG_H__INCLUDED_
37159b3361Sopenharmony_ci
38159b3361Sopenharmony_ci#include <windows.h>
39159b3361Sopenharmony_ci
40159b3361Sopenharmony_cistatic const int MAX_PREFIX_LENGTH = 128;
41159b3361Sopenharmony_ci
42159b3361Sopenharmony_ci#if !defined(NDEBUG)
43159b3361Sopenharmony_ci// define the working debugging class
44159b3361Sopenharmony_ci
45159b3361Sopenharmony_ciclass ADbg
46159b3361Sopenharmony_ci{
47159b3361Sopenharmony_cipublic:
48159b3361Sopenharmony_ci	ADbg(int level = 0);
49159b3361Sopenharmony_ci	virtual ~ADbg();
50159b3361Sopenharmony_ci
51159b3361Sopenharmony_ci	/// \todo make an inline function to test the level first and the process
52159b3361Sopenharmony_ci	int OutPut(int level, const char * format,...) const;
53159b3361Sopenharmony_ci
54159b3361Sopenharmony_ci	int OutPut(const char * format,...) const;
55159b3361Sopenharmony_ci
56159b3361Sopenharmony_ci	inline int setLevel(const int level) {
57159b3361Sopenharmony_ci		return my_level = level;
58159b3361Sopenharmony_ci	}
59159b3361Sopenharmony_ci
60159b3361Sopenharmony_ci	inline bool setIncludeTime(const bool included = true) {
61159b3361Sopenharmony_ci		return my_time_included = included;
62159b3361Sopenharmony_ci	}
63159b3361Sopenharmony_ci
64159b3361Sopenharmony_ci	bool setDebugFile(const char * NewFilename);
65159b3361Sopenharmony_ci	bool unsetDebugFile();
66159b3361Sopenharmony_ci
67159b3361Sopenharmony_ci	inline bool setUseFile(const bool usefile = true) {
68159b3361Sopenharmony_ci		return my_use_file = usefile;
69159b3361Sopenharmony_ci	}
70159b3361Sopenharmony_ci
71159b3361Sopenharmony_ci	inline const char * setPrefix(const char * string) {
72159b3361Sopenharmony_ci		return strncpy(prefix, string, MAX_PREFIX_LENGTH);
73159b3361Sopenharmony_ci	}
74159b3361Sopenharmony_ci
75159b3361Sopenharmony_ciprivate:
76159b3361Sopenharmony_ci	int my_level;
77159b3361Sopenharmony_ci	bool my_time_included;
78159b3361Sopenharmony_ci	bool my_use_file;
79159b3361Sopenharmony_ci	bool my_debug_output;
80159b3361Sopenharmony_ci
81159b3361Sopenharmony_ci	int _OutPut(const char * format,va_list params) const;
82159b3361Sopenharmony_ci
83159b3361Sopenharmony_ci	char prefix[MAX_PREFIX_LENGTH];
84159b3361Sopenharmony_ci
85159b3361Sopenharmony_ci	HANDLE hFile;
86159b3361Sopenharmony_ci};
87159b3361Sopenharmony_ci
88159b3361Sopenharmony_ci#else // !defined(NDEBUG)
89159b3361Sopenharmony_ci
90159b3361Sopenharmony_ci// define a class that does nothing (no output)
91159b3361Sopenharmony_ci
92159b3361Sopenharmony_ciclass ADbg
93159b3361Sopenharmony_ci{
94159b3361Sopenharmony_cipublic:
95159b3361Sopenharmony_ci	ADbg(int level = 0){}
96159b3361Sopenharmony_ci	virtual ~ADbg() {}
97159b3361Sopenharmony_ci
98159b3361Sopenharmony_ci	inline int OutPut(int level, const char * format,...) const {
99159b3361Sopenharmony_ci		return 0;
100159b3361Sopenharmony_ci	}
101159b3361Sopenharmony_ci
102159b3361Sopenharmony_ci	inline int OutPut(const char * format,...) const {
103159b3361Sopenharmony_ci		return 0;
104159b3361Sopenharmony_ci	}
105159b3361Sopenharmony_ci
106159b3361Sopenharmony_ci	inline int setLevel(const int level) {
107159b3361Sopenharmony_ci		return level;
108159b3361Sopenharmony_ci	}
109159b3361Sopenharmony_ci
110159b3361Sopenharmony_ci	inline bool setIncludeTime(const bool included = true) {
111159b3361Sopenharmony_ci		return true;
112159b3361Sopenharmony_ci	}
113159b3361Sopenharmony_ci
114159b3361Sopenharmony_ci	inline bool setDebugFile(const char * NewFilename) {
115159b3361Sopenharmony_ci		return true;
116159b3361Sopenharmony_ci	}
117159b3361Sopenharmony_ci
118159b3361Sopenharmony_ci	inline bool unsetDebugFile() {
119159b3361Sopenharmony_ci		return true;
120159b3361Sopenharmony_ci	}
121159b3361Sopenharmony_ci
122159b3361Sopenharmony_ci	inline bool setUseFile(const bool usefile = true) {
123159b3361Sopenharmony_ci		return true;
124159b3361Sopenharmony_ci	}
125159b3361Sopenharmony_ci
126159b3361Sopenharmony_ci	inline const char * setPrefix(const char * string) {
127159b3361Sopenharmony_ci		return string;
128159b3361Sopenharmony_ci	}
129159b3361Sopenharmony_ci};
130159b3361Sopenharmony_ci
131159b3361Sopenharmony_ci#endif // !defined(NDEBUG)
132159b3361Sopenharmony_ci
133159b3361Sopenharmony_ci#endif // !defined(_DBG_H__INCLUDED_)
134