OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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 size_t size = strlen(cond) + strlen(file) + 500;
49 msg = new char[size];
50 snprintf( msg, size, "Assertion: %s, failed in %s, line %8d.",
51 cond, file, line );
52}
53
54assertion::assertion( const char *m ):
55 std::runtime_error(m)
56{
57 msg = new char[ strlen(m)+1 ];
58 strcpy( msg, m );
59}
60
62 std::runtime_error(a.msg)
63{
64 msg = new char[ strlen(a.msg)+1 ];
65 strcpy( msg, a.msg );
66}
67
69{
70 msg = new char[ strlen(a.msg)+1 ];
71 strcpy( msg, a.msg );
72 return *this;
73}
74
75//---------------------------------------------------------------------------//
76// Function to perform the task of actually throwing an assertion.
77//---------------------------------------------------------------------------//
78
79void toss_cookies( const char *cond, const char *file, int line )
80{
81 std::string what = "Assertion '" + std::string(cond) + "' failed. \n";
82 what += "in \n";
83 what += std::string(file) + ", line " + std::to_string(line);
84
85 throw std::runtime_error(what);
86}
87
88//---------------------------------------------------------------------------//
89// Function to perform the task of actually throwing an isistion.
90//---------------------------------------------------------------------------//
91
92void insist( const char *cond, const char *msg, const char *file, int line )
93{
94 size_t size = strlen(cond) + strlen(msg) + strlen(file) + 500;
95 char* fullmsg = new char[size];
96 snprintf( fullmsg, size, "%s\nAssertion '%s' failed in \n%s on line %8d.",
97 msg, cond, file, line );
98
99 throw assertion( fullmsg );
100
101}
102
103//---------------------------------------------------------------------------//
104// end of Assert.cpp
105//---------------------------------------------------------------------------//
106
107/***************************************************************************
108 * $RCSfile: PAssert.cpp,v $ $Author: adelmann $
109 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
110 * IPPL_VERSION_ID: $Id: PAssert.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
111 ***************************************************************************/
std::complex< double > a
void insist(const char *cond, const char *msg, const char *file, int line)
Definition PAssert.cpp:92
void toss_cookies(const char *cond, const char *file, int line)
Definition PAssert.cpp:79
STL namespace.
assertion & operator=(const assertion &a)
Definition PAssert.cpp:68
assertion(const char *cond, const char *file, int line)
Definition PAssert.cpp:45
char * msg
Definition PAssert.h:50