Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
debug.hpp
Go to the documentation of this file.
1 /*
2  This file is part of the Feel library.
3 
4  Author: Christophe Prud'homme (christophe.prudhomme@feelpp.org)
5 
6  Copyright (C) 2009 Université de Grenoble 1
7  Copyright (C) 2004 EPFL
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 3.0 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 #ifndef __Debug_H
24 #define __Debug_H 1
25 
26 #include <cstdio>
27 #include <iosfwd>
28 
29 #include <string>
30 #include <sstream>
31 
33 
34 
35 namespace Feel
36 {
37 class DebugStream;
38 class NdebugStream;
39 
40 typedef DebugStream & ( *LManipFunction )( DebugStream & ); // manipulator function
41 typedef NdebugStream & ( *LNManipFunction )( NdebugStream& ); // manipulator function
42 
43 #ifdef __GNUC__
44 # define FEELPP_FUNCINFO "[" << __PRETTY_FUNCTION__ << "] "
45 #else
46 # define FEELPP_FUNCINFO "[" << __FILE__ << ":" << __LINE__ << "] "
47 #endif
48 
49 #define FEELPP_LINEINFO "[" << __FILE__ << ":" << __LINE__ << "] "
50 
51 namespace detail
52 {
53 #if 0
54 class print
55 {
56 public:
57  explicit print ( std::ostream& __os ) : M_os ( __os ) {}
58 
59  template<typename T>
60  std::ostream& operator<< ( T const& __t )
61  {
62  __print ( __t, St::SInt2Type<St::STypeTraits<T>::isFundamental>() );
63  return M_os;
64  }
65  template<typename T>
66  std::ostream& operator<< ( T const* __t )
67  {
68  //__print ( __t, St::SInt2Type<St::STypeTraits<T>::isFundamental>() );
69  M_os << __t;
70  return M_os;
71  }
72 private:
73  template<typename T>
74  void __print ( T const& __t, St::SInt2Type<true> )
75  {
76  M_os << __t;
77  }
78  template<typename T>
79  void __print ( T const& __t, St::SInt2Type<false> )
80  {
81 
82  }
83 private:
84  std::ostream& M_os;
85 };
86 #endif
87 } // end namespace detail
88 
89 class DebugStream
90 {
91 public:
92 
93 
97 
98  struct Private;
99 
100  typedef int ( *stprintf )( const char* format, ... );
102 
106 
107  DebugStream( int area = 0, int level = 1, bool print = true );
108  DebugStream( const char* initialString, int area = 0, int level = 1, bool print = true );
109  DebugStream( DebugStream const& );
110  ~DebugStream();
111 
113 
117 
119  bool doPrint() const;
120 
122  void setFlush( stprintf = 0 );
123 
127 
128  static void addDebugArea( uint16_type area, std::string const& description );
129  static void showDebugAreas( std::string const& areas );
130  static void attach( std::string const& __logfile );
131  static void attach( std::string const& __logfile, int area );
132  static void detach( std::string const& __logfile, int area );
133  static void detachAll();
134  void flush();
135 
136 
137  DebugStream& operator<<( bool );
138  DebugStream& operator<<( int16_type );
139  DebugStream& operator<<( int32_type );
140  DebugStream& operator<<( uint16_type );
141  DebugStream& operator<<( uint32_type );
142 #if defined (__s390x__) || defined( __s390__ )
143  DebugStream& operator<<( size_type );
144 #endif
145 #if defined( __APPLE__ )
146  DebugStream& operator<<( size_type );
147  DebugStream& operator<<( ptrdiff_t );
148 #endif
149 
150 #if !defined( BOOST_NO_INT64_T )
151  DebugStream& operator<<( int64_type );
152  DebugStream& operator<<( uint64_type );
153 #endif
154 
155  DebugStream& operator<<( double );
156  DebugStream& operator<<( std::complex<double> );
157 #if defined(FEELPP_HAS_QD_H)
158  DebugStream& operator<<( dd_real );
159  DebugStream& operator<<( qd_real );
160 #endif /* FEELPP_HAS_QD_H */
161 
162  DebugStream& operator<<( const char* );
163  DebugStream& operator<<( std::string const& );
164  DebugStream& operator<<( LManipFunction f );
166 
167 protected:
168 
169 private:
170  Private* __p;
171 
172 };
173 
174 template<typename T>
175 DebugStream& operator<< ( DebugStream& __s, T const* __t )
176 {
177  std::ostringstream __os;
178  __os << __t;
179  __s << __os.str();
180  return __s;
181 }
182 std::string backtrace ();
183 std::string backtrace ( int );
184 
185 class NdebugStream
186 {
187 public:
191  typedef int ( *stprintf )( const char* format, ... );
192 
193  NdebugStream() {}
194  ~NdebugStream() {}
195 
197 
201  static void attach( std::string const& ) {}
202  static void attach( std::string const&, int ) {}
203  static void detach( std::string const&, int ) {}
204  static void detachAll() {}
205  void flush( stprintf = 0 ) {}
206  NdebugStream& operator<<( char const* )
207  {
208  return *this;
209  }
210 
211  NdebugStream& operator<<( bool )
212  {
213  return *this;
214  }
215  NdebugStream& operator<<( int16_type )
216  {
217  return *this;
218  }
219  NdebugStream& operator<<( int32_type )
220  {
221  return *this;
222  }
223  NdebugStream& operator<<( uint16_type )
224  {
225  return *this;
226  }
227  NdebugStream& operator<<( uint32_type )
228  {
229  return *this;
230  }
231 #if defined (__s390x__) || defined( __s390__ )
232  NdebugStream& operator<<( size_type )
233  {
234  return *this;
235  }
236 #endif
237 #if defined( __APPLE__ )
238  NdebugStream& operator<<( size_type )
239  {
240  return *this;
241  }
242  NdebugStream& operator<<( ptrdiff_t )
243  {
244  return *this;
245  }
246 #endif
247 
248 #if !defined( BOOST_NO_INT64_T )
249  NdebugStream& operator<<( uint64_type )
250  {
251  return *this;
252  }
253  NdebugStream& operator<<( int64_type )
254  {
255  return *this;
256  }
257 #endif
258 
259  NdebugStream& operator<<( double )
260  {
261  return *this;
262  }
263  NdebugStream& operator<<( std::complex<double> )
264  {
265  return *this;
266  }
267 #if defined(FEELPP_HAS_QD_H)
268  NdebugStream& operator<<( dd_real )
269  {
270  return *this;
271  }
272  NdebugStream& operator<<( qd_real )
273  {
274  return *this;
275  }
276 #endif /* FEELPP_HAS_QD_H */
277 
278  NdebugStream& operator<<( std::string const& )
279  {
280  return *this;
281  }
282  NdebugStream& operator<<( LManipFunction )
283  {
284  return *this;
285  }
286 
288 };
289 
290 inline NdebugStream& perror( NdebugStream& s )
291 {
292  return s;
293 }
294 inline NdebugStream& endl( NdebugStream& s )
295 {
296  return s;
297 }
298 inline NdebugStream& flush( NdebugStream& s )
299 {
300  return s;
301 }
302 
303 DebugStream Log( int area = 0, DebugStream::stprintf = 0 ) FEELPP_DEPRECATED;
304 DebugStream Log( bool cond, int area = 0, DebugStream::stprintf = 0 ) FEELPP_DEPRECATED;
305 
306 
307 #ifndef NDEBUG
308 DebugStream Debug( int area = 0, DebugStream::stprintf = 0 ) FEELPP_DEPRECATED;
309 DebugStream Debug( bool cond, int area = 0, DebugStream::stprintf = 0 ) FEELPP_DEPRECATED;
310 #else
311 #define Debug Ndebug
312 inline NdebugStream Ndebug( int = 0, NdebugStream::stprintf = &printf )
313 {
314  return NdebugStream();
315 }
316 inline NdebugStream Ndebug( bool /*cond*/, int = 0, NdebugStream::stprintf = &printf )
317 {
318  return NdebugStream();
319 }
320 #endif
321 
322 
323 DebugStream Warning( int area = 0 );
324 DebugStream Warning( bool cond, int area = 0 );
325 
326 DebugStream Error( int area = 0 );
327 DebugStream Error( bool cond, int area = 0 );
328 
329 DebugStream Fatal( int area = 0 );
330 DebugStream Fatal( bool cond, int area = 0 );
331 
333 #define FEELPP_DEBUG_FUNC_INFO(area) Debug(area) << FEELPP_FUNCINFO << "\n";
334 
336 #define FEELPP_DEBUG_BEGIN(area) Debug(area) << "BEGIN: " << __PRETTY_FUNCTION__ << "\n";
337 #define FEELPP_DEBUG_END(area) Debug(area) << "END: " << __PRETTY_FUNCTION__ << "\n";
338 
339 }
340 
341 
342 
343 
344 Feel::DebugStream& perror( Feel::DebugStream& s );
345 Feel::DebugStream& endl( Feel::DebugStream& s );
346 Feel::DebugStream& flush( Feel::DebugStream& );
347 
348 
349 #endif /* __Debug_H */

Generated on Sun Oct 20 2013 08:24:56 for Feel++ by doxygen 1.8.4