DebugUtils.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: DebugUtils.hpp 2938 2011-10-23 19:39:11Z yanweignss $"
00002 
00008 #ifndef GPSTK_DEBUGUTILS_HPP
00009 #define GPSTK_DEBUGUTILS_HPP
00010 
00011 //============================================================================
00012 //
00013 //  This file is part of GPSTk, the GPS Toolkit.
00014 //
00015 //  The GPSTk is free software; you can redistribute it and/or modify
00016 //  it under the terms of the GNU Lesser General Public License as published
00017 //  by the Free Software Foundation; either version 2.1 of the License, or
00018 //  any later version.
00019 //
00020 //  The GPSTk is distributed in the hope that it will be useful,
00021 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 //  GNU Lesser General Public License for more details.
00024 //
00025 //  You should have received a copy of the GNU Lesser General Public
00026 //  License along with GPSTk; if not, write to the Free Software Foundation,
00027 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 //
00029 //  Wei Yan - Chinese Academy of Sciences . 2011
00030 //
00031 //============================================================================
00032 
00033 #include <string>
00034 #include "Exception.hpp"
00035 
00036 namespace gpstk
00037 {
00040    NEW_EXCEPTION_CLASS(AssertFailedException, Exception);
00041 
00045    class DebugUtils   
00046    {
00047    public:
00048       static void assertion(const char* cond, const char* file, int line);
00049 
00050       static void nullPointer(const char* ptr, const char* file, int line);
00051 
00052    protected:
00053       static std::string what(const char* msg, const char* file, int line);
00054    
00055    private:
00056       DebugUtils(){}
00057          
00058    };   // End of class 'DebugUtils'
00059    
00060 
00061    //
00062    // useful macros (these automatically supply line number and file name)
00063    //
00064 #if defined(_DEBUG)
00065 #define GPSTK_ASSERT_DBG(cond) \
00066    if (!(cond)) DebugUtils::assertion(#cond, __FILE__, __LINE__); else (void) 0
00067 #else
00068 #define GPSTK_ASSERT_DBG(cond)
00069 #endif
00070 
00071 
00072 #define GPSTK_ASSERT(cond) \
00073    if (!(cond)) DebugUtils::assertion(#cond, __FILE__, __LINE__); else (void) 0
00074 
00075 
00076 #define GPSTK_CHECK_PTR(ptr) \
00077    if (!(ptr)) DebugUtils::nullPointer(#ptr, __FILE__, __LINE__); else (void) 0
00078 
00079 
00080 #if defined(_DEBUG)
00081 #       define GPSTK_STDOUT_DBG(outstr) \
00082    std::cout << __FILE__ << '(' << std::dec << __LINE__ << "):" << outstr << std::endl;
00083 #else
00084 #       define GPSTK_STDOUT_DBG(outstr)
00085 #endif
00086 
00087 
00088 #if defined(_DEBUG)
00089 #       define GPSTK_STDERR_DBG(outstr) \
00090    std::cerr << __FILE__ << '(' << std::dec << __LINE__ << "):" << outstr << std::endl;
00091 #else
00092 #       define GPSTK_STDERR_DBG(outstr)
00093 #endif
00094 
00095 
00096 }   // End of namespace gpstk
00097 
00098 
00099 #endif  //GPSTK_DEBUGUTILS_HPP
00100 

Generated on Tue May 22 03:30:57 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1