DebugUtils.h

Go to the documentation of this file.
00001 /*
00002  * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003  * downloading, copying, installing or using the software you agree to
00004  * this license. If you do not agree to this license, do not download,
00005  * install, copy or use the software.
00006  * 
00007  * Intel Open Source License 
00008  * 
00009  * Copyright (c) 2004 Intel Corporation. All rights reserved. 
00010  * 
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are
00013  * met:
00014  * 
00015  *   Redistributions of source code must retain the above copyright
00016  *   notice, this list of conditions and the following disclaimer.
00017  * 
00018  *   Redistributions in binary form must reproduce the above copyright
00019  *   notice, this list of conditions and the following disclaimer in the
00020  *   documentation and/or other materials provided with the distribution.
00021  * 
00022  *   Neither the name of the Intel Corporation nor the names of its
00023  *   contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *  
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
00030  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00031  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00032  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00033  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00034  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00035  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 
00039 #ifndef _OASYS_DEBUG_UTILS_H_
00040 #define _OASYS_DEBUG_UTILS_H_
00041 
00042 #include <cstdio>
00043 #include <cstdlib>
00044 
00045 #include "FatalSignals.h"
00046 
00047 #define ASSERT(x)                                                       \
00048     do { if (! (x)) {                                                   \
00049         fprintf(stderr, "ASSERTION FAILED (" #x ") at %s:%d\n",         \
00050                 __FILE__, __LINE__);                                    \
00051         ::oasys::Breaker::break_here();                                 \
00052         ::oasys::FatalSignals::die();                                   \
00053     } } while(0);
00054 
00055 #ifdef __GNUC__
00056 
00057 #define ASSERTF(x, fmt, args...)                                        \
00058     do { if (! (x)) {                                                   \
00059         fprintf(stderr,                                                 \
00060                 "ASSERTION FAILED (" #x ") at %s:%d: " fmt "\n",        \
00061                 __FILE__, __LINE__, ## args);                           \
00062         ::oasys::Breaker::break_here();                                 \
00063         ::oasys::FatalSignals::die();                                   \
00064     } } while(0);
00065 
00066 #define PANIC(fmt, args...)                                             \
00067     do {                                                                \
00068         fprintf(stderr, "PANIC at %s:%d: " fmt "\n",                    \
00069                 __FILE__, __LINE__ , ## args);                          \
00070         ::oasys::Breaker::break_here();                                 \
00071         ::oasys::FatalSignals::die();                                   \
00072     } while(0);
00073 
00074 #endif // __GNUC__
00075 
00076 #ifdef __win32__
00077 
00078 #define ASSERTF(x, fmt, ...)                                            \
00079     do { if (! (x)) {                                                   \
00080         fprintf(stderr,                                                 \
00081                 "ASSERTION FAILED (" #x ") at %s:%d: " fmt "\n",        \
00082                 __FILE__, __LINE__, __VA_ARGS__ );                      \
00083         ::oasys::Breaker::break_here();                                 \
00084         ::oasys::FatalSignals::die();                                   \
00085     } } while(0);
00086 
00087 #define PANIC(fmt, ...)                                                 \
00088     do {                                                                \
00089         fprintf(stderr, "PANIC at %s:%d: " fmt "\n",                    \
00090                 __FILE__, __LINE__ , __VA_ARGS__);                      \
00091         ::oasys::Breaker::break_here();                                 \
00092         ::oasys::FatalSignals::die();                                   \
00093     } while(0);
00094 
00095 #endif /* __win32__ */
00096 
00097 #define NOTREACHED                                                      \
00098     do {                                                                \
00099         fprintf(stderr, "NOTREACHED REACHED at %s:%d\n",                \
00100                 __FILE__, __LINE__);                                    \
00101         ::oasys::Breaker::break_here();                                 \
00102         ::oasys::FatalSignals::die();                                   \
00103     } while(0);
00104 
00105 #define NOTIMPLEMENTED                                                  \
00106     do {                                                                \
00107         fprintf(stderr, "%s NOT IMPLEMENTED at %s:%d\n",                \
00108                 __FUNCTION__, __FILE__, __LINE__);                      \
00109         ::oasys::Breaker::break_here();                                 \
00110         ::oasys::FatalSignals::die();                                   \
00111     } while(0);
00112 
00117 template <int x> struct static_assert_test{};
00118 template <bool>  struct STATIC_ASSERTION_FAILURE;
00119 template <>      struct STATIC_ASSERTION_FAILURE<true>{};
00120 
00121 #ifdef STATIC_ASSERT
00122 #undef STATIC_ASSERT
00123 #endif
00124 
00125 #define STATIC_ASSERT(_x, _what)                   \
00126     typedef static_assert_test                     \
00127     <                                              \
00128         sizeof(STATIC_ASSERTION_FAILURE<(bool)(_x)>) \
00129     > static_assert_typedef_ ## _what;
00130 
00132 namespace oasys {
00133 class Breaker {
00134 public:
00140     static void break_here();
00141 };
00142 
00146 #define delete_z(_obj)                          \
00147     do { delete _obj; _obj = 0; } while (0)
00148 
00154 #define NO_COPY(_Classname)                                     \
00155     private: _Classname(const _Classname& other)
00156 
00157 #define NO_ASSIGN(_Classname)                                   \
00158     private: _Classname& operator=(const _Classname& other)
00159 
00160 #define NO_ASSIGN_COPY(_Classname)              \
00161    NO_COPY(_Classname);                         \
00162    NO_ASSIGN(_Classname)
00164 
00165 } // namespace oasys
00166 
00167 #include "../memory/Memory.h"
00168 
00169 #endif /* _OASYS_DEBUG_UTILS_H_ */

Generated on Fri Dec 22 14:47:58 2006 for DTN Reference Implementation by  doxygen 1.5.1