00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <base/base>
00026
00027 #include <sstream>
00028 #include <iostream>
00029
00030 #ifdef __GNUC__
00031
00032 #include <cxxabi.h>
00033 #endif
00034
00035 std::ostream& base::_Debug = std::cerr;
00036 std::ostream& base::_Log = std::cout;
00037 std::ostream& base::_Console = std::cout;
00038
00039
00040 #ifdef DEBUG
00041 bool _abortOnExceptionConstruction = false;
00042 bool _outputExceptionOnConstruction = true;
00043 bool _abortOnAssertionFailure = false;
00044 #endif
00045
00046
00047 void base::assertionFailure(const base::String& errorstring)
00048 {
00049 #ifdef DEBUG
00050 _Log << "Throwing runtime_error due to assertion failure: " << errorstring << std::endl;
00051 if (_abortOnAssertionFailure) {
00052 _Log << "aborting." << std::endl;
00053 abort();
00054 }
00055 #endif
00056 throw std::runtime_error(errorstring);
00057 }
00058
00059
00060 String base::demangleTypeidName(const String& typeidName)
00061 {
00062 #ifdef __GNUC__
00063 int status;
00064 char* realname = abi::__cxa_demangle(typeidName.c_str(), 0, 0, &status);
00065 String srealname(realname);
00066 free(realname);
00067 return srealname;
00068 #else
00069 throw std::runtime_error(Exception("demangling not implemented on the current platform"));
00070 #endif
00071 }
00072
00073
00074 String base::className(const std::type_info& ti)
00075 {
00076 return demangleTypeidName(ti.name());
00077 }
00078
00079
00080 String base::intToString(Int i)
00081 {
00082 std::ostringstream oss;
00083 oss << i;
00084 return oss.str();
00085 }
00086
00087
00088 Int base::stringToInt(const String& s)
00089 {
00090 std::istringstream iss(s);
00091 Int v;
00092 iss >> v;
00093 return v;
00094 }
00095
00096 Real base::stringToReal(const String& s)
00097 {
00098 std::istringstream iss(s);
00099 Real v;
00100 iss >> v;
00101 return v;
00102 }
00103
00104 String base::realToString(Real r)
00105 {
00106 std::ostringstream oss;
00107 oss << r;
00108 return oss.str();
00109 }
00110
00111
00112