src/Utility/PAssert.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  * This program was prepared by PSI. 
00007  * All rights in the program are reserved by PSI.
00008  * Neither PSI nor the author(s)
00009  * makes any warranty, express or implied, or assumes any liability or
00010  * responsibility for the use of this software
00011  *
00012  * Visit http://www.acl.lanl.gov/POOMS for more details
00013  *
00014  ***************************************************************************/
00015 
00016 // -*- C++ -*-
00017 /***************************************************************************
00018  *
00019  * The IPPL Framework
00020  * 
00021  *
00022  * Visit http://people.web.psi.ch/adelmann/ for more details
00023  *
00024  ***************************************************************************/
00025 
00026 //---------------------------------------------------------------------------//
00027 // Assert.cpp
00028 // Geoffrey Furnish
00029 // Fri Jul 25 08:41:38 1997
00030 //---------------------------------------------------------------------------//
00031 // @> Helper functions for the Assert facility.
00032 //---------------------------------------------------------------------------//
00033 
00034 // include files
00035 #include "Utility/PAssert.h"
00036 #include "Utility/IpplInfo.h"
00037 
00038 #ifdef IPPL_USE_STANDARD_HEADERS
00039 #include <iostream>
00040 using namespace std;
00041 #else
00042 #include <iostream.h>
00043 #endif
00044 
00045 #include <string.h>
00046 #include <stdio.h>
00047 #include <stdlib.h>
00048 
00049 //---------------------------------------------------------------------------//
00050 
00051 assertion::assertion( const char *cond, const char *file, int line )
00052 {
00053     msg = new char[ strlen(cond) + strlen(file) + 500 ];
00054     sprintf( msg, "Assertion: %s, failed in %s, line %8d.",
00055              cond, file, line );
00056 }
00057 
00058 assertion::assertion( const char *m )
00059 {
00060     msg = new char[ strlen(m)+1 ];
00061     strcpy( msg, m );
00062 }
00063 
00064 assertion::assertion( const assertion& a )
00065 {
00066     msg = new char[ strlen(a.msg)+1 ];
00067     strcpy( msg, a.msg );
00068 }
00069 
00070 assertion& assertion::operator=( const assertion& a )
00071 {
00072     msg = new char[ strlen(a.msg)+1 ];
00073     strcpy( msg, a.msg );
00074     return *this;
00075 }
00076 
00077 //---------------------------------------------------------------------------//
00078 // Function to perform the task of actually throwing an assertion.
00079 //---------------------------------------------------------------------------//
00080 
00081 void toss_cookies( const char *cond, const char *file, int line )
00082 {
00083   // inform other nodes they should quit
00084   Ippl::exitAllNodes(cond, false);
00085 
00086 #ifndef IPPL_NO_EXCEPTIONS
00087     throw assertion( cond, file, line );
00088 #else
00089     abort();
00090 #endif
00091 }
00092 
00093 //---------------------------------------------------------------------------//
00094 // Function to perform the task of actually throwing an isistion.
00095 //---------------------------------------------------------------------------//
00096 
00097 void insist( const char *cond, const char *msg, const char *file, int line )
00098 {
00099   // inform other nodes they should quit
00100   Ippl::exitAllNodes(msg, false);
00101 
00102 #ifndef IPPL_NO_EXCEPTIONS
00103     throw assertion( msg );
00104 #else
00105     abort();
00106 #endif
00107 }
00108 
00109 //---------------------------------------------------------------------------//
00110 //                              end of Assert.cpp
00111 //---------------------------------------------------------------------------//
00112 
00113 /***************************************************************************
00114  * $RCSfile: PAssert.cpp,v $   $Author: adelmann $
00115  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:33 $
00116  * IPPL_VERSION_ID: $Id: PAssert.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $ 
00117  ***************************************************************************/

Generated on Mon Jan 16 13:23:59 2006 for IPPL by  doxygen 1.4.6