Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

btk_debug.h

Go to the documentation of this file.
00001 // -*- mode: c++; -*-
00002 //
00003 //The Biomolecule Toolkit (BTK) is a C++ library for use in the
00004 //modeling, analysis, and design of biological macromolecules.
00005 //Copyright (C) 2001, Tim Robertson <kid50@users.sourceforge.net>
00006 //
00007 //This program is free software; you can redistribute it and/or modify
00008 //it under the terms of the GNU Lesser General Public License as published
00009 //by the Free Software Foundation; either version 2.1 of the License, or (at
00010 //your option) any later version.
00011 //
00012 //This program is distributed in the hope that it will be useful,  but
00013 //WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 //Lesser General Public License for more details. 
00016 //
00017 //You should have received a copy of the GNU Lesser General Public License 
00018 //along with this program; if not, write to the Free Software Foundation, 
00019 //Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00025 #ifndef BTK_DEBUG_H
00026 #define BTK_DEBUG_H
00027 
00028 #include <exception>
00029 #include <string>
00030 
00031 namespace BTK {
00032 namespace debug {
00039 extern unsigned debug_level;
00040 
00051 #ifndef NDEBUG
00052 # define DBG_OUT(level) if (BTK::debug::debug_level >= (level)) std::cerr
00053 #else
00054 # define DBG_OUT(level) if (0) std::cerr
00055 #endif
00056 
00057 typedef enum {EXIT, CONTINUE, IGNORE} assert_code;
00058 
00059 typedef assert_code (*assert_handler)(std::string const &,
00060               std::string const &,
00061               unsigned);
00062 
00063 assert_code default_assert_handler(std::string const & msg,
00064            std::string const & file,
00065            unsigned line);
00066 
00067 extern assert_handler current_assert_handler;
00068 
00069 class BTKAssertion : public std::exception {
00070 public:
00071   BTKAssertion(std::string const & msg) throw() : _msg(msg.c_str()) {}
00072   BTKAssertion(char const * msg = "") throw() : _msg(msg) {}
00073   ~BTKAssertion() throw() {}
00074   virtual char const * what() const throw() {return _msg.c_str();}
00075 private:
00076   std::string _msg;
00077 };
00078  
00079 };  // namespace BTK::debug
00080 
00081 #ifndef NDEBUG
00082 #define BTK_ASSERT(expr,str)       if (!(expr)) {                                    \
00083                                       static BTK::debug::assert_code status =        \
00084                                             BTK::debug::EXIT;                        \
00085                                       if (status != BTK::debug::IGNORE) {            \
00086                 status = BTK::debug::                        \
00087                      current_assert_handler((str),       \
00088                                                                         __FILE__,    \
00089                               __LINE__);   \
00090                                         if (BTK::debug::EXIT == status)              \
00091                   throw BTK::debug::BTKAssertion(str);       \
00092                                      }                                               \
00093                                    };
00094 
00095 #else
00096 #define BTK_ASSERT(expr,str)
00097 #endif
00098 
00099 }; // namespace BTK
00100 
00101 #endif // BTK_DEBUG_H

Generated on Wed Apr 14 00:43:16 2004 for BTK by doxygen 1.3.6