LifeV
LifeDebug.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5 Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6 Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8 This file is part of LifeV.
9 
10 LifeV is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14 
15 LifeV is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 /*!
27  @file
28  @brief Classes for debugging
29 
30  @date 13-12-2010
31  @author Christophe Prud'homme <christophe.prudhomme@epfl.ch>
32 
33  @maintainer Radu Popescu <radu.popescu@epfl.ch>
34 */
35 
36 #ifndef LIFE_DEBUG_H
37 #define LIFE_DEBUG_H 1
38 
39 #include <cstdio>
40 #include <iosfwd>
41 #include <sstream>
42 
43 #include <lifev/core/LifeV.hpp>
44 
45 namespace LifeV
46 {
47 
48 // Forward declarations
49 class DebugStream;
50 class NdebugStream;
51 
52 typedef DebugStream& (*LManipFunction) ( DebugStream&); // manipulator function
53 typedef NdebugStream& (*LNManipFunction) ( NdebugStream&); // manipulator function
54 
55 #ifdef __GNUC__
56 # define LIFEV_FUNCINFO "[" << __PRETTY_FUNCTION__ << "] "
57 #else
58 # define LIFEV_FUNCINFO "[" << __FILE__ << ":" << __LINE__ << "] "
59 #endif
60 
61 #define LIFEV_LINEINFO "[" << __FILE__ << ":" << __LINE__ << "] "
62 
64 {
65 public:
66  //! @name Public typedefs and structures
67  //@{
68  struct Private;
69  typedef int (*stprintf) ( const char* format, ... );
70  //@}
71 
72  /** @name Constructors, destructor
73  */
74  //@{
75  DebugStream (int area = 0, int level = 1, bool print = true);
76  DebugStream (const char* initialString, int area = 0, int level = 1, bool print = true);
77  DebugStream ( DebugStream const& );
78  ~DebugStream();
79  //@}
80 
81  //! @name Operators
82  //@{
83  DebugStream& operator<< ( char const* c);
84  DebugStream& operator<< ( double d);
85  DebugStream& operator<< ( std::string const& str);
86  DebugStream& operator<< ( LManipFunction f);
87  //@}
88 
89  //! @name Methods
90  //@{
91  void setFlush ( stprintf = 0 );
92  void flush();
93 
94  static void attach ( std::string const& logfile );
95  static void attach ( std::string const& logfile, int area );
96  static void detach ( std::string const& logfile, int area );
97  static void detachAll();
98  //@}
99 
100 private:
102 };
103 
104 // ===================================
105 // Debug Stream Implementation
106 // ===================================
107 
108 template<typename T>
109 DebugStream& operator<< ( DebugStream& stream, T const* data )
110 {
111  std::ostringstream out_stream;
112  out_stream << data;
113  stream << out_stream.str();
114  return stream;
115 }
116 
117 #ifdef HAVE_BACKTRACE
118 std::string backtrace ();
119 std::string backtrace ( int val);
120 #endif
121 
122 
124 {
125 public:
126  //! @name Public typedefs
127  //@{
128  typedef int (*stprintf) ( const char* format, ... );
129  //@}
130 
131  //! @name Constructors, destructor
132  //@{
135  //@}
136 
137  //! @name Operators
138  //@{
139  NdebugStream& operator<< ( char const* /*code*/ )
140  {
141  return *this;
142  }
143  NdebugStream& operator<< ( std::string const& /*str*/)
144  {
145  return *this;
146  }
147  NdebugStream& operator<< ( double /*code*/)
148  {
149  return *this;
150  }
151  NdebugStream& operator<< ( LNManipFunction /*f*/ )
152  {
153  return *this;
154  }
155  //@}
156 
157  //! @name Methods
158  //@{
159  void flush ( stprintf = 0 ) {}
160  //@}
161 };
162 
164 {
165  return s;
166 }
168 {
169  return s;
170 }
172 {
173  return s;
174 }
175 
176 #ifdef HAVE_LIFEV_DEBUG
178 DebugStream debugStream ( bool cond, int area = 0, DebugStream::stprintf = 0 );
180 LIFEV_DEPRECATED ( DebugStream Debug ( bool cond, int area = 0, DebugStream::stprintf func = 0 ) );
181 #else
182 #define debugStream noDebugStream
183 inline NdebugStream noDebugStream ( int = 0, NdebugStream::stprintf = &printf )
184 {
185  return NdebugStream();
186 }
187 #endif
188 
189 DebugStream Warning ( int area = 0 );
190 DebugStream Warning ( bool cond, int area = 0 );
191 
192 DebugStream Error ( int area = 0 );
193 DebugStream Error ( bool cond, int area = 0 );
194 
195 DebugStream Fatal ( int area = 0 );
196 DebugStream Fatal ( bool cond, int area = 0 );
197 
198 }
199 
203 
204 #endif // LIFE_DEBUG_H
NdebugStream & perror(NdebugStream &s)
Definition: LifeDebug.hpp:163
DebugStream Warning(bool cond, int area=0)
Definition: LifeDebug.cpp:403
DebugStream Fatal(int area=0)
Definition: LifeDebug.cpp:436
DebugStream(DebugStream const &)
Definition: LifeDebug.cpp:229
static void detachAll()
Definition: LifeDebug.cpp:360
int(* stprintf)(const char *format,...)
Definition: LifeDebug.hpp:128
DebugStream(int area=0, int level=1, bool print=true)
Definition: LifeDebug.cpp:186
void setFlush(stprintf=0)
Definition: LifeDebug.cpp:294
LifeV::DebugStream & flush(LifeV::DebugStream &s)
Definition: LifeDebug.cpp:501
LifeV::DebugStream & perror(LifeV::DebugStream &s)
Definition: LifeDebug.cpp:489
DebugStream Warning(int area=0)
Definition: LifeDebug.cpp:398
void updateInverseJacobian(const UInt &iQuadPt)
NdebugStream & flush(NdebugStream &s)
Definition: LifeDebug.hpp:171
DebugStream Error(bool cond, int area=0)
Definition: LifeDebug.cpp:422
int(* stprintf)(const char *format,...)
Definition: LifeDebug.hpp:69
NdebugStream & endl(NdebugStream &s)
Definition: LifeDebug.hpp:167
DebugStream Fatal(bool cond, int area=0)
Definition: LifeDebug.cpp:442
DebugStream Error(int area=0)
Definition: LifeDebug.cpp:416
void flush(stprintf=0)
Definition: LifeDebug.hpp:159
NdebugStream noDebugStream(int=0, NdebugStream::stprintf=&printf)
Definition: LifeDebug.hpp:183
DebugStream(const char *initialString, int area=0, int level=1, bool print=true)
Definition: LifeDebug.cpp:209
LifeV::DebugStream & endl(LifeV::DebugStream &s)
Definition: LifeDebug.cpp:495