OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
PAssert.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  * This program was prepared by PSI.
7  * All rights in the program are reserved by PSI.
8  * Neither PSI nor the author(s)
9  * makes any warranty, express or implied, or assumes any liability or
10  * responsibility for the use of this software
11  *
12  * Visit www.amas.web.psi for more details
13  *
14  ***************************************************************************/
15 
16 // -*- C++ -*-
17 /***************************************************************************
18  *
19  * The IPPL Framework
20  *
21  *
22  * Visit http://people.web.psi.ch/adelmann/ for more details
23  *
24  ***************************************************************************/
25 
26 //---------------------------------------------------------------------------//
27 // Assert.cpp
28 // Geoffrey Furnish
29 // Fri Jul 25 08:41:38 1997
30 //---------------------------------------------------------------------------//
31 // @> Helper functions for the Assert facility.
32 //---------------------------------------------------------------------------//
33 
34 // include files
35 #include "Utility/PAssert.h"
36 
37 #include <iostream>
38 using namespace std;
39 #include <cstring>
40 #include <cstdio>
41 #include <cstdlib>
42 
43 //---------------------------------------------------------------------------//
44 
45 assertion::assertion( const char *cond, const char *file, int line ):
46  std::runtime_error(cond)
47 {
48  msg = new char[ strlen(cond) + strlen(file) + 500 ];
49  sprintf( msg, "Assertion: %s, failed in %s, line %8d.",
50  cond, file, line );
51 }
52 
53 assertion::assertion( const char *m ):
54  std::runtime_error(m)
55 {
56  msg = new char[ strlen(m)+1 ];
57  strcpy( msg, m );
58 }
59 
61  std::runtime_error(a.msg)
62 {
63  msg = new char[ strlen(a.msg)+1 ];
64  strcpy( msg, a.msg );
65 }
66 
68 {
69  msg = new char[ strlen(a.msg)+1 ];
70  strcpy( msg, a.msg );
71  return *this;
72 }
73 
74 //---------------------------------------------------------------------------//
75 // Function to perform the task of actually throwing an assertion.
76 //---------------------------------------------------------------------------//
77 
78 void toss_cookies( const char *cond, const char *file, int line )
79 {
80  // inform other nodes they should quit
81  // Ippl::exitAllNodes(cond, false);
82  std::string what = "Assertion '" + std::string(cond) + "' failed. \n";
83  what += "in \n";
84  what += std::string(file) + ", line " + std::to_string(line);
85 
86  throw std::runtime_error(what);
87 }
88 
89 //---------------------------------------------------------------------------//
90 // Function to perform the task of actually throwing an isistion.
91 //---------------------------------------------------------------------------//
92 
93 void insist( const char *cond, const char *msg, const char *file, int line )
94 {
95  // inform other nodes they should quit
96  // Ippl::exitAllNodes(msg, false);
97 
98  char* fullmsg = new char[ strlen(cond) + strlen(msg) + strlen(file) + 500 ];
99  sprintf( fullmsg, "%s\nAssertion '%s' failed in \n%s on line %8d.",
100  msg, cond, file, line );
101 
102  throw assertion( fullmsg );
103 
104 }
105 
106 //---------------------------------------------------------------------------//
107 // end of Assert.cpp
108 //---------------------------------------------------------------------------//
109 
110 /***************************************************************************
111  * $RCSfile: PAssert.cpp,v $ $Author: adelmann $
112  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
113  * IPPL_VERSION_ID: $Id: PAssert.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
114  ***************************************************************************/
assertion(const char *cond, const char *file, int line)
Definition: PAssert.cpp:45
void insist(const char *cond, const char *msg, const char *file, int line)
Definition: PAssert.cpp:93
assertion & operator=(const assertion &a)
Definition: PAssert.cpp:67
char * msg
Definition: PAssert.h:55
void toss_cookies(const char *cond, const char *file, int line)
Definition: PAssert.cpp:78