IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
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 <cstdio>
40#include <cstdlib>
41#include <cstring>
42
43//---------------------------------------------------------------------------//
44
45assertion::assertion(const char* cond, const char* file, int line)
46 : std::runtime_error(cond) {
47 msg = new char[strlen(cond) + strlen(file) + 500];
48 sprintf(msg, "Assertion: %s, failed in %s, line %8d.", cond, file, line);
49}
50
52 : std::runtime_error(m) {
53 msg = new char[strlen(m) + 1];
54 strcpy(msg, m);
55}
56
58 : std::runtime_error(a.msg) {
59 msg = new char[strlen(a.msg) + 1];
60 strcpy(msg, a.msg);
61}
62
64 msg = new char[strlen(a.msg) + 1];
65 strcpy(msg, a.msg);
66 return *this;
67}
68
69//---------------------------------------------------------------------------//
70// Function to perform the task of actually throwing an assertion.
71//---------------------------------------------------------------------------//
72
73void toss_cookies(const char* cond, const char* file, int line) {
74 std::string what = "Assertion '" + std::string(cond) + "' failed. \n";
75 what += "in \n";
76 what += std::string(file) + ", line " + std::to_string(line);
77
78 throw std::runtime_error(what);
79}
80
81//---------------------------------------------------------------------------//
82// Function to perform the task of actually throwing an isistion.
83//---------------------------------------------------------------------------//
84void insist(const char* cond, const char* msg, const char* file, int line) {
85 char* fullmsg = new char[strlen(cond) + strlen(msg) + strlen(file) + 500];
86 sprintf(fullmsg, "%s\nAssertion '%s' failed in \n%s on line %8d.", msg, cond, file, line);
87
88 throw assertion(fullmsg);
89}
90
91//---------------------------------------------------------------------------//
92// end of Assert.cpp
93//---------------------------------------------------------------------------//
94
95/***************************************************************************
96 * $RCSfile: PAssert.cpp,v $ $Author: adelmann $
97 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
98 * IPPL_VERSION_ID: $Id: PAssert.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
99 ***************************************************************************/
void insist(const char *cond, const char *msg, const char *file, int line)
Definition PAssert.cpp:84
void toss_cookies(const char *cond, const char *file, int line)
Definition PAssert.cpp:73
STL namespace.
assertion & operator=(const assertion &a)
Definition PAssert.cpp:63
assertion(const char *cond, const char *file, int line)
Definition PAssert.cpp:45
char * msg
Definition PAssert.h:54