SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
debug_new.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
2 // vim:tabstop=4:shiftwidth=4:expandtab:
3 
4 /*
5  * Copyright (C) 2004-2010 Wu Yongwei <adah at users dot sourceforge dot net>
6  *
7  * This software is provided 'as-is', without any express or implied
8  * warranty. In no event will the authors be held liable for any
9  * damages arising from the use of this software.
10  *
11  * Permission is granted to anyone to use this software for any purpose,
12  * including commercial applications, and to alter it and redistribute
13  * it freely, subject to the following restrictions:
14  *
15  * 1. The origin of this software must not be misrepresented; you must
16  * not claim that you wrote the original software. If you use this
17  * software in a product, an acknowledgement in the product
18  * documentation would be appreciated but is not required.
19  * 2. Altered source versions must be plainly marked as such, and must
20  * not be misrepresented as being the original software.
21  * 3. This notice may not be removed or altered from any source
22  * distribution.
23  *
24  * This file is part of Stones of Nvwa:
25  * http://sourceforge.net/projects/nvwa
26  *
27  */
28 
39 #ifndef _DEBUG_NEW_H
40 #define _DEBUG_NEW_H
41 
42 #include <new>
43 #include <stdio.h>
44 
69 #ifndef _DEBUG_NEW_REDEFINE_NEW
70 #define _DEBUG_NEW_REDEFINE_NEW 1
71 #endif
72 
84 #ifndef _DEBUG_NEW_TYPE
85 #define _DEBUG_NEW_TYPE 1
86 #endif
87 
88 /* Prototypes */
89 int check_leaks();
91 void* operator new(size_t size, const char* file, int line);
92 void* operator new[](size_t size, const char* file, int line);
93 void operator delete(void* pointer, const char* file, int line) throw();
94 void operator delete[](void* pointer, const char* file, int line) throw();
95 #if defined(_MSC_VER) && _MSC_VER < 1300
96 // MSVC 6 requires the following declarations; or the non-placement
97 // new[]/delete[] will not compile.
98 void* operator new[](size_t) throw(std::bad_alloc);
99 void operator delete[](void*) throw();
100 #endif
101 
102 /* Control variables */
103 extern bool new_autocheck_flag; // default to true: call check_leaks() on exit
104 extern bool new_verbose_flag; // default to false: no verbose information
105 extern FILE* new_output_fp; // default to stderr: output to console
106 extern const char* new_progname;// default to NULL; should be assigned argv[0]
107 
116 #if _DEBUG_NEW_TYPE == 1
117 #define DEBUG_NEW __debug_new_recorder(__FILE__, __LINE__) ->* new
118 #else
119 #define DEBUG_NEW new(__FILE__, __LINE__)
120 #endif
121 
122 # if _DEBUG_NEW_REDEFINE_NEW
123 # define new DEBUG_NEW
124 # endif
125 # ifdef _DEBUG_NEW_EMULATE_MALLOC
126 # include <stdlib.h>
127 # ifdef new
128 # define malloc(s) ((void*)(new char[s]))
129 # else
130 # define malloc(s) ((void*)(DEBUG_NEW char[s]))
131 # endif
132 # define free(p) delete[] (char*)(p)
133 # endif
134 
141 {
142  const char* _M_file;
143  const int _M_line;
144  void _M_process(void* pointer);
145 public:
150  __debug_new_recorder(const char* file, int line)
151  : _M_file(file), _M_line(line) {}
158  template <class _Tp> _Tp* operator->*(_Tp* pointer)
159  { _M_process(pointer); return pointer; }
160 private:
163 };
164 
172 {
173  static int _S_count;
174 public:
177 };
180 
181 #endif // _DEBUG_NEW_H
const char * new_progname
__debug_new_recorder & operator=(const __debug_new_recorder &)
bool new_verbose_flag
void _M_process(void *pointer)
bool new_autocheck_flag
__debug_new_recorder(const char *file, int line)
Definition: debug_new.h:150
static __debug_new_counter __debug_new_count
Definition: debug_new.h:179
FILE * new_output_fp
int check_mem_corruption()
int check_leaks()
static int _S_count
Definition: debug_new.h:173
const char * _M_file
Definition: debug_new.h:142
_Tp * operator->*(_Tp *pointer)
Definition: debug_new.h:158