00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2006 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 #ifndef ASSERT_H 00021 #define ASSERT_H 00022 00023 #ifdef NS3_ASSERT_ENABLE 00024 00025 #include <iostream> 00026 00027 /** 00028 * \ingroup core 00029 * \defgroup debugging Debugging 00030 */ 00031 /** 00032 * \ingroup debugging 00033 * \defgroup assert Assert 00034 * 00035 * \brief assert functions and macros 00036 * 00037 * The assert macros are used to verify 00038 * at runtime that a certain condition is true. If it is 00039 * not true, the program halts. These checks are built 00040 * into the program only in debugging builds. They are 00041 * removed in optimized builds. 00042 */ 00043 00044 /** 00045 * \ingroup assert 00046 * \param condition condition to verifiy. 00047 * 00048 * At runtime, in debugging builds, if this condition is not 00049 * true, the program prints the source file, line number and 00050 * unverified condition and halts by dereferencing a null pointer. 00051 */ 00052 #define NS_ASSERT(condition) \ 00053 do \ 00054 { \ 00055 if (!(condition)) \ 00056 { \ 00057 std::cerr << "assert failed. file=" << __FILE__ << \ 00058 ", line=" << __LINE__ << ", cond=\""#condition << \ 00059 "\"" << std::endl; \ 00060 int *a = 0; \ 00061 *a = 0; \ 00062 } \ 00063 } \ 00064 while (false) 00065 00066 00067 /** 00068 * \ingroup assert 00069 * \param condition condition to verifiy. 00070 * \param message message to output 00071 * 00072 * At runtime, in debugging builds, if this condition is not 00073 * true, the program prints the message to output and 00074 * halts by dereferencing a null pointer. 00075 */ 00076 #define NS_ASSERT_MSG(condition, message) \ 00077 do \ 00078 { \ 00079 if (!(condition)) \ 00080 { \ 00081 std::cerr << message << std::endl; \ 00082 int *a = 0; \ 00083 *a = 0; \ 00084 } \ 00085 } \ 00086 while (false) 00087 00088 #else /* NS3_ASSERT_ENABLE */ 00089 00090 #define NS_ASSERT(cond) 00091 #define NS_ASSERT_MSG(cond,msg) 00092 00093 #endif /* NS3_ASSERT_ENABLE */ 00094 00095 #endif /* ASSERT_H */