Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

base/base.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)1996 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
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. (http://www.gnu.org)
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   $Id: base.cpp 1029 2004-02-11 20:45:54Z jungd $
00019   $Revision: 1.7 $
00020   $Date: 2004-02-11 15:45:54 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022   
00023 ****************************************************************************/
00024 
00025 #include <base/base>
00026 
00027 #include <sstream>
00028 #include <iostream>
00029 
00030 #ifdef __GNUC__ 
00031 // get namespace abi for className() 
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 

Generated on Thu Jul 29 15:56:04 2004 for OpenSim by doxygen 1.3.6