FOX/ObjCryst++  1.10.X (development)
VFNDebug.h
1 /* ObjCryst++ Object-Oriented Crystallographic Library
2  (c) 2000-2002 Vincent Favre-Nicolin vincefn@users.sourceforge.net
3  2000-2001 University of Geneva (Switzerland)
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 /* VFNDebug.h
20 * header file for debugging objects & functions
21 *
22 */
23 #ifndef __VFN_DEBUG__H__
24 #define __VFN_DEBUG__H__
25 
26 #ifdef __DEBUG__
27 
28 #ifdef _MSC_VER
29 #include "windows.h"
30 #include <sstream>
31 #endif
32 
34 void LibCrystDebugGlobalLevel(const int level);
35 
39 void LibCrystDebugLocalLevel(const int level);
40 
41 extern int gVFNDebugMessageGlobalLevel;
42 extern int gVFNDebugMessageLevel;
43 extern unsigned int gVFNDebugMessageIndent;
44 
45 //Debug messages are printed only if __DEBUG__ is on, and if their level
46 //is greater or equal to debugMessageGlobalLevel
47 // 0 : messages from low-level routines,
48 // 5
49 // 10 : messages from top LibCryst++ routines
50 #ifdef _MSC_VER
51 #define VFN_DEBUG_MESSAGE(message,level) \
52  if(level >= gVFNDebugMessageLevel) \
53  {\
54  stringstream ss;\
55  for(unsigned int iii=0;iii<gVFNDebugMessageIndent;iii++) ss <<" ";\
56  ss << "%DEBUG:"<< level << " "\
57  << message << " (at " << __FILE__ << "," << __LINE__ << ")" <<endl;\
58  OutputDebugStringA(ss.str().c_str());\
59  }
60 
61 #define VFN_DEBUG_MESSAGE_SHORT(message,level) \
62  if(level >= gVFNDebugMessageLevel)\
63  {\
64  stringstream ss;\
65  ss << message;\
66  OutputDebugStringA(ss.str().c_str());\
67  }
68 
69 #define VFN_DEBUG_ENTRY(message,level) \
70  if(level >= gVFNDebugMessageLevel) \
71  {\
72  stringstream ss;\
73  for(unsigned int iii=0;iii<gVFNDebugMessageIndent;iii++) ss <<" ";\
74  ss << "%DEBUG:"<< level << " <"\
75  << message << " (at " << __FILE__ << "," << __LINE__ << ")" <<endl;\
76  gVFNDebugMessageIndent++;\
77  OutputDebugStringA(ss.str().c_str());\
78  }
79 
80 #define VFN_DEBUG_EXIT(message,level) \
81  if(level >= gVFNDebugMessageLevel) \
82  {\
83  stringstream ss;\
84  if(gVFNDebugMessageIndent>0) gVFNDebugMessageIndent--;\
85  for(unsigned int iii=0;iii<gVFNDebugMessageIndent;iii++) ss <<" ";\
86  ss << "%DEBUG:"<< level << " \\"\
87  << message << "> (at " << __FILE__ << "," << __LINE__ << ")" <<endl;\
88  OutputDebugStringA(ss.str().c_str());\
89  }
90 
91 #else
92 #define VFN_DEBUG_MESSAGE(message,level) \
93  if(level >= gVFNDebugMessageLevel) \
94  {\
95  for(unsigned int iii=0;iii<gVFNDebugMessageIndent;iii++) cout <<" ";\
96  cout << "%DEBUG:"<< level << " "\
97  << message << " (at " << __FILE__ << "," << __LINE__ << ")" <<endl;\
98  }
99 
100 #define VFN_DEBUG_MESSAGE_SHORT(message,level) \
101  if(level >= gVFNDebugMessageLevel) cout << message;
102 
103 #define VFN_DEBUG_ENTRY(message,level) \
104  if(level >= gVFNDebugMessageLevel) \
105  {\
106  for(unsigned int iii=0;iii<gVFNDebugMessageIndent;iii++) cout <<" ";\
107  cout << "%DEBUG:"<< level << " <"\
108  << message << " (at " << __FILE__ << "," << __LINE__ << ")" <<endl;\
109  gVFNDebugMessageIndent++;\
110  }
111 
112 #define VFN_DEBUG_EXIT(message,level) \
113  if(level >= gVFNDebugMessageLevel) \
114  {\
115  if(gVFNDebugMessageIndent>0) gVFNDebugMessageIndent--;\
116  for(unsigned int iii=0;iii<gVFNDebugMessageIndent;iii++) cout <<" ";\
117  cout << "%DEBUG:"<< level << " \\"\
118  << message << "> (at " << __FILE__ << "," << __LINE__ << ")" <<endl;\
119  }
120 #endif
121 
122 #define VFN_DEBUG_GLOBAL_LEVEL(level) gVFNDebugMessageGlobalLevel=level;\
123  gVFNDebugMessageLevel=gVFNDebugMessageGlobalLevel;
124 
125 #define VFN_DEBUG_LOCAL_LEVEL(level) if(level != -1) gVFNDebugMessageLevel=level; else gVFNDebugMessageLevel=gVFNDebugMessageGlobalLevel;
126 
127 #else //__DEBUG__
128 
129 #define VFN_DEBUG_MESSAGE(message,level)
130 #define VFN_DEBUG_MESSAGE_SHORT(message,level)
131 #define VFN_DEBUG_ENTRY(message,level)
132 #define VFN_DEBUG_EXIT(message,level)
133 #define VFN_DEBUG_GLOBAL_LEVEL(level)
134 #define VFN_DEBUG_LOCAL_LEVEL(level)
135 
136 
137 #endif //__DEBUG__
138 
139 #endif // __VFN_DEBUG__H__