LCOV - code coverage report
Current view: top level - src/mesquite/Misc - MsqDebug.hpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 0 3 0.0 %
Date: 2020-07-18 00:09:26 Functions: 0 1 0.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       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                 :            : #include "Mesquite.hpp"
      29                 :            : 
      30                 :            : #include <vector>
      31                 :            : #include <iostream>
      32                 :            : #include <cstdio>
      33                 :            : 
      34                 :            : namespace MBMesquite
      35                 :            : {
      36                 :            : 
      37                 :            : /**
      38                 :            :  *\defgroup debug Mesquite debug output
      39                 :            :  */
      40                 :            : /*@{*/
      41                 :            : 
      42                 :            : /** \def MSQ_ENABLE_DEBUG
      43                 :            :  *\brief Enable debug output and optionally set initial debug flags
      44                 :            :  *
      45                 :            :  *If this preprocessor constant is undefined, all debug output will
      46                 :            :  *be disabled.  It is expected that this will not be defined for
      47                 :            :  *release builds of Mesquite.
      48                 :            :  *
      49                 :            :  *If MSQ_ENABLE_DEBUG is defined, it may optionally be set to a
      50                 :            :  *comma-separated list of positive, non-zero integers.  This list
      51                 :            :  *will be interpreted as a list of debug flags that should be
      52                 :            :  *activated automatically.
      53                 :            :  *
      54                 :            :  *To enable debug output but leave all debug flags deactivated:
      55                 :            :  *#define  MSQ_ENABLE_DEBUG
      56                 :            :  *
      57                 :            :  *To enable debug output and activated the first three debug flags:
      58                 :            :  *#define  MSQ_ENABLE_DEBUG 1,2,3
      59                 :            :  */
      60                 :            : 
      61                 :            : /**
      62                 :            :  *\class MsqDebug
      63                 :            :  *\brief Run-time activation/deactivation of debug flags
      64                 :            :  *\author Jason Kraftcheck
      65                 :            :  *\date 2004-10-18
      66                 :            :  *
      67                 :            :  *Wrap static functions for managing debug flags and associated
      68                 :            :  *output streams.  Output is expected do be done using the
      69                 :            :  *provided macros MSQ_DBGOUT(), MSQ_PRINT(), and MSQ_DBG().
      70                 :            :  *
      71                 :            :  *The default output stream for all flags is cout.
      72                 :            :  */
      73                 :            : class MsqDebug
      74                 :            : {
      75                 :            :   public:
      76                 :            :     // some pre-defined meanings of debug flags
      77                 :            :     enum
      78                 :            :     {
      79                 :            :         WARN = 1,
      80                 :            :         INFO = 2
      81                 :            :     };
      82                 :            : 
      83                 :            :     /**\brief Enable a debug flag */
      84                 :          0 :     static void enable( unsigned flag )
      85                 :            :     {
      86                 :          0 :         set( flag, true );
      87                 :          0 :     }
      88                 :            :     /**\brief Disable a debug flag */
      89                 :            :     static void disable( unsigned flag )
      90                 :            :     {
      91                 :            :         set( flag, false );
      92                 :            :     }
      93                 :            :     /**\brief Set a debug flag */
      94                 :            :     static void set( unsigned flag, bool state );
      95                 :            :     /**\brief Check a debug flag */
      96                 :            :     static bool get( unsigned flag );
      97                 :            : 
      98                 :            :     /**\brief Disable all debug streams */
      99                 :            :     static void disable_all();
     100                 :            : 
     101                 :            :     /**\brief Get the output stream to be used for a given debug flag */
     102                 :            :     static std::ostream& get_stream( unsigned flag );
     103                 :            :     /**\brief Set the output stream to be used for a given debug flag */
     104                 :            :     static void set_stream( unsigned flag, std::ostream& stream );
     105                 :            : 
     106                 :            :     // Work around limitations of preprocessor macros.
     107                 :            :     // You probably don't want to use this directly.  See
     108                 :            :     // MSQ_PRINT macro below.
     109                 :            :     class FormatPrinter
     110                 :            :     {
     111                 :            :       public:
     112                 :            :         FormatPrinter( unsigned flag ) : myFlag( flag ) {}
     113                 :            :         void print( const char* format, ... ) const
     114                 :            : #ifdef __GNUC__
     115                 :            :             __attribute__( ( format( printf, 2, 3 ) ) )
     116                 :            : #endif
     117                 :            :             ;
     118                 :            :         const unsigned myFlag;
     119                 :            :     };
     120                 :            : 
     121                 :            :     // Static initialize function (declare a static instance of this
     122                 :            :     // such that the constructor can be used as a function to initialize
     123                 :            :     // static data.)
     124                 :            :     class InitializeFlags
     125                 :            :     {
     126                 :            :       public:
     127                 :            :         InitializeFlags();
     128                 :            :     };
     129                 :            : 
     130                 :            :   private:
     131                 :            :     static std::vector< std::ostream* > streams;
     132                 :            :     static std::vector< bool > flags;
     133                 :            :     static InitializeFlags init;
     134                 :            : };
     135                 :            : 
     136                 :            : /** \brief Check if a debug flag is activated - evaluates to a bool.
     137                 :            :  */
     138                 :            : #ifdef MSQ_ENABLE_DEBUG
     139                 :            : #define MSQ_DBG( flag ) MBMesquite::MsqDebug::get( flag )
     140                 :            : #else
     141                 :            : #define MSQ_DBG( flag ) false
     142                 :            : #endif
     143                 :            : 
     144                 :            : /**
     145                 :            :  *\brief Check debug flag and return ostream associated with flag.
     146                 :            :  *
     147                 :            :  * Evaluates to a conditional calling of an ostream depending on the
     148                 :            :  * debug flag.  Example:
     149                 :            :  *   MSQ_DBGOUT(f) << "Debug flag " << f << " is activated" << endl;
     150                 :            :  */
     151                 :            : #define MSQ_DBGOUT( flag ) \
     152                 :            :     if( MSQ_DBG( flag ) ) MBMesquite::MsqDebug::get_stream( flag )
     153                 :            : 
     154                 :            : /**
     155                 :            :  *\brief Check debug flag and print printf-style formatted output.
     156                 :            :  *
     157                 :            :  * Evaluatues to a conditional print depending on the debug flag.
     158                 :            :  * Example:
     159                 :            :  *  MSQ_PRINT(f)("Debug flag %d is activated", f);
     160                 :            :  */
     161                 :            : #define MSQ_PRINT( flag ) \
     162                 :            :     if( MSQ_DBG( flag ) ) MBMesquite::MsqDebug::FormatPrinter( flag ).print
     163                 :            : 
     164                 :            : /*@}*/
     165                 :            : 
     166                 :            : }  // namespace MBMesquite
     167                 :            : 
     168                 :            : #endif

Generated by: LCOV version 1.11