00001 // Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory 00002 // 00003 // This file is part of the Olena Library. This library is free 00004 // software; you can redistribute it and/or modify it under the terms 00005 // of the GNU General Public License version 2 as published by the 00006 // Free Software Foundation. 00007 // 00008 // This library is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 // General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this library; see the file COPYING. If not, write to 00015 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston, 00016 // MA 02111-1307, USA. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software library without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to 00022 // produce an executable, this file does not by itself cause the 00023 // resulting executable to be covered by the GNU General Public 00024 // License. This exception does not however invalidate any other 00025 // reasons why the executable file might be covered by the GNU General 00026 // Public License. 00027 00028 #ifndef NTG_UTILS_DEBUG_HH 00029 # define NTG_UTILS_DEBUG_HH 00030 00031 # include <ntg/core/macros.hh> 00032 # include <ntg/core/type_traits.hh> 00033 00034 # include <string> 00035 00036 namespace ntg 00037 { 00038 00039 /*---------------------. 00040 | typename_of_var(obj) | 00041 `---------------------*/ 00042 00043 template<class T> inline 00044 std::string 00045 typename_of_var(const T&) 00046 { return ntg_name(T); } 00047 00048 /*-----------------. 00049 | typename_of<T>() | 00050 `-----------------*/ 00051 00052 /* 00053 This function is handy then there are commas in the type 00054 expression. Else ntg_name(T) is shorter. 00055 */ 00056 00057 template<class T> inline 00058 std::string 00059 typename_of() 00060 { return ntg_name(T); } 00061 00062 /* 00063 Debug context. The idea is to keep a context string to simplify 00064 debugging when an assert fails somewhere in a hidden operator. As 00065 this can be slow, a dynamic boolean specifies wheter the context 00066 has to be maintained or not. 00067 */ 00068 00069 #ifdef NTG_DEBUG 00070 extern bool debug_active; 00071 extern std::string debug_context; 00072 #endif 00073 00074 } 00075 00076 # ifdef NTG_DEBUG 00077 # define ntg_debug_define_vars(State) \ 00078 bool ntg::debug_active = State; \ 00079 std::string ntg::debug_context; 00080 # define ntg_debug_activate() ntg::debug_active = true 00081 # define ntg_debug_desactivate() ntg::debug_active = false 00082 # define ntg_is_debug_active (ntg::debug_active == true) 00083 # define ntg_debug_context_set(Context) ntg::debug_context = Context 00084 # define ntg_debug_context_clear(Context) ntg::debug_context.clear() 00085 # else 00086 # define ntg_debug_define_vars(State) 00087 # define ntg_debug_activate() 00088 # define ntg_debug_desactivate() 00089 # define ntg_is_debug_active false 00090 # define ntg_debug_context_set(Context) 00091 # define ntg_debug_context_clear(Context) 00092 # endif 00093 00094 #endif // !NTG_UTILS_DEBUG_HH