00001 00033 #ifndef _MSC_VER 00034 # include <itpp/config.h> 00035 #else 00036 # include <itpp/config_msvc.h> 00037 #endif 00038 00039 #include <itpp/base/itassert.h> 00040 #include <iostream> 00041 #include <sstream> 00042 #include <string> 00043 #include <stdexcept> 00044 #include <cstdlib> 00045 00046 00047 namespace itpp { 00048 00049 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00050 00051 static bool warnings_enabled = true; 00052 static std::ostream *warn = &std::cerr; 00053 #ifdef ITPP_EXCEPTIONS 00054 static bool it_using_exceptions = true; 00055 #else 00056 static bool it_using_exceptions = false; 00057 #endif 00058 00059 #endif //DOXYGEN_SHOULD_SKIP_THIS 00060 00061 void it_assert_f(std::string ass, std::string msg, std::string file, int line) 00062 { 00063 std::ostringstream line_str; 00064 line_str << line << std::flush; 00065 00066 std::string error = "*** Assertion failed in "; 00067 error += file; 00068 error += " on line "; 00069 error += line_str.str(); 00070 error += ":\n"; 00071 error += msg; 00072 error += " ("; 00073 error += ass; 00074 error += ")"; 00075 std::cerr << error << std::endl << std::flush; 00076 #ifdef ITPP_EXCEPTIONS 00077 if (it_using_exceptions) 00078 throw std::runtime_error(error); 00079 else 00080 #endif 00081 abort(); 00082 } 00083 00084 void it_error_f(std::string msg, std::string file, int line) 00085 { 00086 std::ostringstream line_str; 00087 line_str << line << std::flush; 00088 00089 std::string error = "*** Error in "; 00090 error += file; 00091 error += " on line "; 00092 error += line_str.str(); 00093 error += ":"; 00094 error += msg; 00095 std::cerr << error << std::endl << std::flush; 00096 #ifdef ITPP_EXCEPTIONS 00097 if (it_using_exceptions) 00098 throw std::runtime_error(error); 00099 else 00100 #endif 00101 abort(); 00102 } 00103 00104 void it_warning_f(std::string msg, std::string file, int line) 00105 { 00106 if (warnings_enabled) 00107 (*warn) << "*** Warning in " << file << " on line " << line << ":" 00108 << std::endl << msg << std::endl << std::flush; 00109 } 00110 00111 void it_enable_exceptions(bool on) 00112 { 00113 it_using_exceptions = on; 00114 } 00115 00116 void it_enable_warnings() 00117 { 00118 warnings_enabled = true; 00119 } 00120 00121 void it_disable_warnings() 00122 { 00123 warnings_enabled = false; 00124 } 00125 00126 void it_redirect_warnings(std::ostream *warn_stream) 00127 { 00128 warn = warn_stream; 00129 } 00130 00131 } //namespace itpp
Generated on Fri Jun 8 00:37:32 2007 for IT++ by Doxygen 1.5.2