MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
helpers.hpp
1 /*
2  Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 /*
18  * helpers.hpp
19  */
20 
21 #ifndef helpers_hpp
22 #define helpers_hpp
23 
24 //#include <cstdio>
25 #include <cstdlib>
26 #include <iostream>
27 #include <cstring>
28 
29 //using namespace std;
30 using std::cout;
31 using std::endl;
32 using std::flush;
33 
34 /************************************************************
35  * Helper Macros & Functions
36  ************************************************************/
37 
38 // JNI crashes with gcc & operator<<(ostream &, long/int)
39 // so, we use C99's __func__ and also convert to string using sprintf()
40 #define ABORT_ERROR(message) \
41  do { \
42  char l[1024]; \
43  sprintf(l, "%d", __LINE__); \
44  cout << "!!! error, file: " << (__FILE__) \
45  << ", function: " << (__func__) \
46  << ", line: " << l \
47  << ", msg: " << message << "." << endl; \
48  exit(-1); \
49  } while (0)
50 
51 // an output stream for debug messages
52 #if DEBUG
53 #define CDBG if (0); else cout
54 #else
55 #define CDBG if (1); else cout
56 #endif
57 
58 // some macros for tracing
59 #define ENTER(name) \
60  CDBG << "--> " << name << endl;
61 
62 #define LEAVE(name) \
63  CDBG << "<-- " << name << endl;
64 
65 #define TRACE(name) \
66  Tracer _tracer_(name);
67 
68 // use as:
69 // myfunction() {
70 // TRACE("myfunction()");
71 // ...
72 // }
73 class Tracer
74 {
75  const char* const name;
76 public:
77  Tracer(const char* name) : name(name) {
78  ENTER(name);
79  }
80 
81  ~Tracer() {
82  LEAVE(name);
83  }
84 };
85 
86 #endif // helpers_hpp