~ubuntu-branches/ubuntu/raring/blitz++/raring

« back to all changes in this revision

Viewing changes to blitz/bzdebug.h

  • Committer: Bazaar Package Importer
  • Author(s): Konstantinos Margaritis
  • Date: 2005-02-28 20:25:01 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050228202501-3i4f2sknnprsqfhz
Tags: 1:0.8-4
Added missing build-depends (Closes: #297323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
2
 * blitz/bzdebug.h      Debugging macros
3
3
 *
4
 
 * $Id: bzdebug.h,v 1.1.1.1 2000/06/19 12:26:08 tveldhui Exp $
 
4
 * $Id: bzdebug.h,v 1.6 2004/10/06 21:58:33 julianc Exp $
5
5
 *
6
 
 * Copyright (C) 1997-1999 Todd Veldhuizen <tveldhui@oonumerics.org>
 
6
 * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
7
7
 *
8
8
 * This program is free software; you can redistribute it and/or
9
9
 * modify it under the terms of the GNU General Public License
21
21
 * For more information, please see the Blitz++ Home Page:
22
22
 *    http://oonumerics.org/blitz/
23
23
 *
24
 
 ***************************************************************************
25
 
 * $Log: bzdebug.h,v $
26
 
 * Revision 1.1.1.1  2000/06/19 12:26:08  tveldhui
27
 
 * Imported sources
28
 
 *
29
 
 * Revision 1.7  1998/03/14 00:04:47  tveldhui
30
 
 * 0.2-alpha-05
31
 
 *
32
 
 * Revision 1.6  1998/02/26 18:09:36  tveldhui
33
 
 * Added testsuite support for precondition fail checking
34
 
 *
35
 
 * Revision 1.5  1997/07/16 14:51:20  tveldhui
36
 
 * Update: Alpha release 0.2 (Arrays)
37
 
 *
38
 
 * Revision 1.4  1997/01/24 14:42:00  tveldhui
39
 
 * Periodic RCS update
40
 
 *
41
 
 * Revision 1.3  1997/01/13 22:19:58  tveldhui
42
 
 * Periodic RCS update
43
 
 *
44
 
 * Revision 1.2  1996/11/11 17:29:13  tveldhui
45
 
 * Periodic RCS update
46
 
 *
47
 
 * Revision 1.1  1996/04/14  12:36:45  todd
48
 
 * Initial revision
49
 
 *
50
 
 *
51
 
 */
 
24
 ***************************************************************************/
52
25
 
53
26
#ifndef BZ_DEBUG_H
54
27
#define BZ_DEBUG_H
55
28
 
56
 
#include <stdlib.h>
 
29
#ifdef BZ_HAVE_STDLIB_H
 
30
 #include <stdlib.h>
 
31
#endif
57
32
#include <assert.h>
58
33
 
59
 
#ifdef BZ_RTTI
 
34
#ifdef BZ_HAVE_RTTI
60
35
 #include <typeinfo>
61
36
#endif
62
37
 
68
43
 * "extern" elsewhere.
69
44
 */
70
45
 
71
 
_bz_global _bz_bool assertFailMode     BZ_GLOBAL_INIT(_bz_false);
72
 
_bz_global int      assertFailCount    BZ_GLOBAL_INIT(0);
73
 
_bz_global int      assertSuccessCount BZ_GLOBAL_INIT(0);
74
 
 
75
 
 
76
 
#ifdef BZ_TESTSUITE
 
46
_bz_global bool assertFailMode     BZ_GLOBAL_INIT(false);
 
47
_bz_global int  assertFailCount    BZ_GLOBAL_INIT(0);
 
48
_bz_global int  assertSuccessCount BZ_GLOBAL_INIT(0);
 
49
 
 
50
 
 
51
#if defined(BZ_TESTSUITE)
77
52
  /*
78
53
   * In testsuite mode, these routines allow a test suite to check
79
54
   * that precondition checking is being done properly.  A typical
93
68
   * to halt and issue an error code.   -- TV 980226
94
69
   */
95
70
 
96
 
  inline void checkAssert(_bz_bool condition, const char* where=0, 
 
71
  inline void checkAssert(bool condition, const char* where=0, 
97
72
    int line=0)
98
73
  {
99
 
    if (assertFailMode == _bz_true)
 
74
    if (assertFailMode == true)
100
75
    {
101
 
      if (condition == _bz_true)
 
76
      if (condition == true)
102
77
        ++assertSuccessCount;
103
78
      else
104
79
        ++assertFailCount;
117
92
 
118
93
  inline void beginCheckAssert()
119
94
  {
120
 
    assertFailMode = _bz_true;
 
95
    assertFailMode = true;
121
96
    assertSuccessCount = 0;
122
97
    assertFailCount = 0;
123
98
  }
124
99
 
125
100
  inline void endCheckAssert()
126
101
  {
127
 
    assert(assertFailMode == _bz_true);
128
 
    assertFailMode = _bz_false;
 
102
    assert(assertFailMode == true);
 
103
    assertFailMode = false;
129
104
    if (assertFailCount == 0)
130
105
    {
131
106
      cerr << "Assert check failed!" << endl;
139
114
    #define BZSTATECHECK(X,Y)  checkAssert(X == Y, __FILE__, __LINE__)
140
115
    #define BZPRECHECK(X,Y)                                    \
141
116
        {                                                      \
142
 
            if ((assertFailMode == _bz_false) && (!(X)))       \
 
117
            if ((assertFailMode == false) && (!(X)))       \
143
118
                cerr << Y << endl;                             \
144
119
            checkAssert(X, __FILE__, __LINE__);                \
145
120
        }
146
121
 
147
 
    #define BZ_DEBUG_MESSAGE(X) \
148
 
        { if (assertFailMode == _bz_false) { cout << __FILE__ << ":" << __LINE__ << " " << X << endl; } }
 
122
    #define BZ_DEBUG_MESSAGE(X)                                          \
 
123
        {                                                                \
 
124
            if (assertFailMode == false)                             \
 
125
            {                                                            \
 
126
                cout << __FILE__ << ":" << __LINE__ << " " << X << endl; \
 
127
            }                                                            \
 
128
        }
149
129
 
 
130
    #define BZ_DEBUG_PARAM(X) X
150
131
    #define BZ_PRE_FAIL        checkAssert(0)
151
 
#else 
152
 
#ifdef BZ_DEBUG
 
132
    #define BZ_ASM_DEBUG_MARKER
 
133
 
 
134
#elif defined(BZ_DEBUG)
 
135
 
153
136
    #define BZASSERT(X)        assert(X)
154
137
    #define BZPRECONDITION(X)  assert(X)
155
138
    #define BZPOSTCONDITION(X) assert(X)
156
139
    #define BZSTATECHECK(X,Y)  assert(X == Y)
157
 
    #define BZPRECHECK(X,Y)        \
158
 
        { if (!(X))                                                           \
 
140
    #define BZPRECHECK(X,Y)                                                 \
 
141
        { if (!(X))                                                         \
159
142
          { cerr << "[Blitz++] Precondition failure: Module " << __FILE__   \
160
143
               << " line " << __LINE__ << endl                              \
161
144
               << Y << endl;                                                \
164
147
          }                                                                 \
165
148
        }
166
149
 
 
150
    #define BZ_DEBUG_MESSAGE(X) \
 
151
        { cout << __FILE__ << ":" << __LINE__ << " " << X << endl; }
 
152
 
 
153
    #define BZ_DEBUG_PARAM(X) X
167
154
    #define BZ_PRE_FAIL      assert(0)
168
155
 
169
 
    #define BZ_DEBUG_MESSAGE(X) \
170
 
        { cout << __FILE__ << ":" << __LINE__ << " " << X << endl; }
171
 
 
 
156
// This routine doesn't exist anywhere; it's used to mark a
 
157
// position of interest in assembler (.s) files
172
158
    void _bz_debug_marker();
173
159
    #define BZ_ASM_DEBUG_MARKER   _bz_debug_marker();
174
 
#else   // !BZ_DEBUG
 
160
 
 
161
#else   // !BZ_TESTSUITE && !BZ_DEBUG
 
162
 
175
163
    #define BZASSERT(X)
176
164
    #define BZPRECONDITION(X)
177
165
    #define BZPOSTCONDITION(X)
178
166
    #define BZSTATECHECK(X,Y)
179
167
    #define BZPRECHECK(X,Y)
 
168
    #define BZ_DEBUG_MESSAGE(X)
 
169
    #define BZ_DEBUG_PARAM(X)
180
170
    #define BZ_PRE_FAIL
181
 
    #define BZ_DEBUG_MESSAGE(X)
182
 
#endif  // !BZ_DEBUG
183
 
#endif  // !BZ_TESTSUITE
 
171
    #define BZ_ASM_DEBUG_MARKER
184
172
 
185
 
// This routine doesn't exist anywhere; it's used to mark a
186
 
// position of interest in assembler (.s) files
187
 
void _bz_debug_marker();
 
173
#endif  // !BZ_TESTSUITE && !BZ_DEBUG
188
174
 
189
175
#define BZ_NOT_IMPLEMENTED()   { cerr << "[Blitz++] Not implemented: module " \
190
176
    << __FILE__ << " line " << __LINE__ << endl;                \
191
177
    exit(1); }
192
178
 
193
 
#ifdef BZ_RTTI
 
179
#ifdef BZ_HAVE_RTTI
194
180
#define BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(X)  typeid(X).name()
195
181
#else
196
182
 
197
 
template<class T>
 
183
template<typename T>
198
184
class _bz_stringLiteralForNumericType {
199
185
public:
200
186
    static const char* string()
209
195
     { return Y; }                             \
210
196
 }
211
197
 
212
 
#ifdef BZ_BOOL
 
198
#ifdef BZ_HAVE_BOOL
213
199
BZ_DECL_SLFNT(bool, "bool");
214
200
#endif
215
201
 
234
220
#define BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(X) \
235
221
    _bz_stringLiteralForNumericType<X>::string()
236
222
 
237
 
#endif // !BZ_RTTI
 
223
#endif // !BZ_HAVE_RTTI
238
224
 
239
225
BZ_NAMESPACE_END
240
226