Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
includeLinks/MsqDebug.hpp
Go to the documentation of this file.
1 /* *****************************************************************
2  MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4  Copyright 2004 Sandia Corporation and Argonne National
5  Laboratory. Under the terms of Contract DE-AC04-94AL85000
6  with Sandia Corporation, the U.S. Government retains certain
7  rights in this software.
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 2.1 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 License
20  (lgpl.txt) along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 
23  ***************************************************************** */
24 
25 #ifndef MSQ_DEBUG_HPP
26 #define MSQ_DEBUG_HPP
27 
28 
29 #include "Mesquite.hpp"
30 
31 #ifdef MSQ_USE_OLD_STD_HEADERS
32 # include <vector.h>
33 #else
34 # include <vector>
35 #endif
36 
37 #ifdef MSQ_USE_OLD_IO_HEADERS
38 # include <iostream.h>
39 #else
40 # include <iostream>
41 #endif
42 
43 #ifdef MSQ_USE_OLD_C_HEADERS
44 # include <stdio.h>
45 #else
46 # include <cstdio>
47 #endif
48 
49 namespace Mesquite {
50 
55 
87 class MsqDebug
88 {
89  public:
90 
91  // some pre-defined meanings of debug flags
92  enum {
93  WARN = 1,
94  INFO = 2
95  };
96 
98  static void enable( unsigned flag ) { set( flag, true ); }
100  static void disable( unsigned flag ) { set( flag, false ); }
102  static void set( unsigned flag, bool state );
104  static bool get( unsigned flag );
105 
107  static void disable_all();
108 
110  static msq_stdio::ostream& get_stream( unsigned flag );
112  static void set_stream( unsigned flag, msq_stdio::ostream& stream );
113 
114  // Work around limitations of preprocessor macros.
115  // You probably don't want to use this directly. See
116  // MSQ_PRINT macro below.
118  public:
119  FormatPrinter( unsigned flag ) : myFlag(flag) {}
120  void print( const char* format, ... ) const
121  #ifdef __GNUC__
122  __attribute__ ((format (printf, 2, 3)))
123  #endif
124  ;
125  const unsigned myFlag;
126  };
127 
128  // Static initialize function (declare a static instance of this
129  // such that the constructor can be used as a function to initialize
130  // static data.)
132  public:
133  InitializeFlags();
134  };
135 
136  private:
137 
138  static msq_std::vector<msq_stdio::ostream*> streams;
139  static msq_std::vector<bool> flags;
141 };
142 
145 #ifdef MSQ_ENABLE_DEBUG
146 # define MSQ_DBG(flag) Mesquite::MsqDebug::get(flag)
147 #else
148 # define MSQ_DBG(flag) false
149 #endif
150 
158 #define MSQ_DBGOUT(flag) if (MSQ_DBG(flag)) Mesquite::MsqDebug::get_stream(flag)
159 
167 #define MSQ_PRINT(flag) if (MSQ_DBG(flag)) Mesquite::MsqDebug::FormatPrinter(flag).print
168 
171 } // namespace Mesquite
172 
173 #endif
static msq_std::vector< msq_stdio::ostream * > streams
static msq_stdio::ostream & get_stream(unsigned flag)
Get the output stream to be used for a given debug flag.
static msq_std::vector< bool > flags
static void set(unsigned flag, bool state)
Set a debug flag.
static InitializeFlags init
static void set_stream(unsigned flag, msq_stdio::ostream &stream)
Set the output stream to be used for a given debug flag.
static void enable(unsigned flag)
Enable a debug flag.
static void disable(unsigned flag)
Disable a debug flag.
Run-time activation/deactivation of debug flags.
void print(const char *format,...) const
static void disable_all()
Disable all debug streams.