• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ut_debugmsg.h

Go to the documentation of this file.
00001 /* AbiSource Program Utilities
00002  * Copyright (C) 1998 AbiSource, Inc.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 #ifndef UT_DEBUGMSG_H
00021 #define UT_DEBUGMSG_H
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include "config.h"
00025 #endif
00026 
00027 /* pre-emptive dismissal; ut_types.h is needed by just about everything,
00028  * so even if it's commented out in-file that's still a lot of work for
00029  * the preprocessor to do...
00030  */
00031 #ifndef UT_TYPES_H
00032 #include "ut_types.h"
00033 #endif
00034 
00035 template<class T>
00036 class UT_DebugOnly
00037 {
00038 public:
00039 
00040 #if DEBUG
00041   T value;
00042   UT_DebugOnly()
00043   {
00044   }
00045   UT_DebugOnly(const T& other)
00046    : value(other)
00047   {
00048   }
00049   UT_DebugOnly& operator=(const T& rhs)
00050   {
00051       value = rhs;
00052       return *this;
00053   }
00054   void operator++(int)
00055   {
00056     value++;
00057   }
00058   void operator--(int)
00059   {
00060     value--;
00061   }
00062 
00063   operator T&()
00064   {
00065     return value;
00066   }
00067   operator const T&() const
00068   {
00069     return value;
00070   }
00071 
00072   T& operator->()
00073   {
00074     return value;
00075   }
00076 
00077 #else
00078   UT_DebugOnly()
00079   {
00080   }
00081   UT_DebugOnly(const T&)
00082   {
00083   }
00084   UT_DebugOnly& operator=(const T&)
00085   {
00086     return *this;
00087   }
00088   void operator++(int)
00089   {
00090   }
00091   void operator--(int)
00092   {
00093   }
00094 #endif
00095 
00096   ~UT_DebugOnly()
00097   {
00098   }
00099 };
00100 
00101 
00102 ABI_EXPORT void _UT_OutputMessage(const char *s, ...) ABI_PRINTF_FORMAT(1,2);
00103 
00104 #ifdef DEBUG
00105 #define UT_DEBUGMSG(M) _UT_OutputMessage M
00106 #else
00107 #define UT_DEBUGMSG(M)
00108 #endif
00109 
00110 // define a quick way to no-op a debug message that
00111 // you want to keep and without having to #if 0 it.
00112 
00113 #define xxx_UT_DEBUGMSG(M)
00114 
00115 
00116 /*
00117  * Similar to UT_DEBUGMSG, except exists even in production (non-debug) builds
00118  */
00119 #ifdef _WIN32
00120 ABI_EXPORT void _UT_WarningMessage(const char *s, ...);
00121 #else
00122 #define _UT_WarningMessage _UT_OutputMessage
00123 #endif
00124 #define UT_WARNINGMSG(M) _UT_WarningMessage M
00125 
00126 
00127 #endif /* UT_DEBUGMSG_H */

Generated on Wed Jun 19 2013 for AbiWord by  doxygen 1.7.1