Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vsnet_debug.h
Go to the documentation of this file.
1 #ifndef VSNET_DEBUG_H
2 #define VSNET_DEBUG_H
3 
4 #include <boost/version.hpp>
5 #include <config.h>
6 #ifdef USE_PTHREAD
7 #include <pthread.h>
8 #endif
9 #include <iostream>
10 
11 #ifndef NDEBUG
12 #define VSNET_DEBUG
13 #else
14 #undef VSNET_DEBUG
15 #endif
16 
17 #undef VSNET_DEBUG
18 
19 extern std::ostream& vsnetDbgOut( const char *file, int line );
20 
21 #if !defined (COUT)
22  #if defined (_WIN32) && defined (_MSC_VER) && _MSC_VER < 1300 && _MSC_VEBOOST_VERSION != 102800 //wierd error in MSVC
23  #define COUT vsnetDbgOut( __FILE__, 0 )
24  #else
25  #define COUT vsnetDbgOut( __FILE__, __LINE__ )
26  #endif
27 #endif
28 
29 #define FIND_WIN_NBIO
30 
31 /* --- BEGIN memory debugging macros --- */
37 #ifdef USE_PTHREAD
38 #define PTHREAD_SELF_OR_NONE pthread_self()
39 #else
40 #define PTHREAD_SELF_OR_NONE 0
41 #endif
42 
43 #ifndef NDEBUG
44 
45  #include <assert.h>
46  #include <stdio.h>
47 
48  #define DECLARE_VALID \
49 private: \
50  bool _valid; \
51  bool _invalid; \
52 public: \
53  void validate( const char *file, int line ) const { \
54  if (!_valid || _invalid) { \
55  fprintf( stderr, "object invalid in %s:%d:%d\n", file, line, PTHREAD_SELF_OR_NONE ); \
56  } \
57  assert( _valid ); \
58  assert( !_invalid ); \
59  }
60 
61  #define MAKE_VALID \
62  _valid = true; \
63  _invalid = false;
64 
65  #define MAKE_INVALID \
66  _valid = false; \
67  _invalid = true;
68 
69  #define CHECK_VALID \
70  validate( __FILE__, __LINE__ );
71 
72  #define CHECK_VALID_OBJ( a ) \
73  (a).validate( __FILE__, __LINE__ );
74 
75  #define ASSERT( a ) \
76  if ( !(a) ) {std::cerr<<__FILE__<<":"<<__LINE__ \
77  <<" assertion failed, forcing segfault for postmortem debugging"; int x = 1/0; }
78 
79 #else /* NDEBUG */
80  #define DECLARE_VALID
81  #define MAKE_VALID
82  #define MAKE_INVALID
83  #define CHECK_VALID
84  #define CHECK_VALID_OBJ( a )
85  #define ASSERT( a )
86 #endif /* NDEBUG */
87 /* --- END memory debugging macros --- */
88 
89 #if !defined (_WIN32) || defined (__CYGWIN__)
90  #define PSEUDO__LINE__( x ) __LINE__
91 #else
92  #ifndef __PRETTY_FUNCTION
93  #ifdef __FUNCTION__
94  #define __PRETTY_FUNCTION__ __FUNCTION__
95  #else
96  #define __PRETTY_FUNCTION__ "<Unknown>"
97  #endif
98  #endif
99 
100  #ifndef __FUNCTION__
101  #define __FUNCTION__ "<Unknown>"
102  #endif
103 
104  #if (defined (_WIN32) && defined (_MSC_VER) && (_MSC_VER < 1300) && defined (_DEBUG) && (BOOST_VERSION != 102800 ) )
105  #define PSEUDO__LINE__( x ) x
106  #else
107  #define PSEUDO__LINE__( x ) __LINE__
108  #endif
109 
110 #endif
111 
112 #endif /* VSNET_DEBUG_H */
113