OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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>
38using namespace std;
39#include <cstring>
40#include <cstdio>
41#include <cstdlib>
42
43//---------------------------------------------------------------------------//
44
45assertion::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
53assertion::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
78void toss_cookies( const char *cond, const char *file, int line )
79{
80 std::string what = "Assertion '" + std::string(cond) + "' failed. \n";
81 what += "in \n";
82 what += std::string(file) + ", line " + std::to_string(line);
83
84 throw std::runtime_error(what);
85}
86
87//---------------------------------------------------------------------------//
88// Function to perform the task of actually throwing an isistion.
89//---------------------------------------------------------------------------//
90
91void insist( const char *cond, const char *msg, const char *file, int line )
92{
93 char* fullmsg = new char[ strlen(cond) + strlen(msg) + strlen(file) + 500 ];
94 sprintf( fullmsg, "%s\nAssertion '%s' failed in \n%s on line %8d.",
95 msg, cond, file, line );
96
97 throw assertion( fullmsg );
98
99}
100
101//---------------------------------------------------------------------------//
102// end of Assert.cpp
103//---------------------------------------------------------------------------//
104
105/***************************************************************************
106 * $RCSfile: PAssert.cpp,v $ $Author: adelmann $
107 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
108 * IPPL_VERSION_ID: $Id: PAssert.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
109 ***************************************************************************/
std::complex< double > a
void insist(const char *cond, const char *msg, const char *file, int line)
Definition: PAssert.cpp:91
void toss_cookies(const char *cond, const char *file, int line)
Definition: PAssert.cpp:78
assertion & operator=(const assertion &a)
Definition: PAssert.cpp:67
assertion(const char *cond, const char *file, int line)
Definition: PAssert.cpp:45
char * msg
Definition: PAssert.h:50