Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
assertions.C File Reference
#include <CGAL/config.h>
#include <cstdio>
#include <cstdlib>
#include <CGAL/assertions.h>
#include <iostream>
#include <cassert>
#include "commpi.h"
Include dependency graph for assertions.C:

Go to the source code of this file.

Functions

CGAL_BEGIN_NAMESPACE void not_implemented ()
 
void printStackBacktrace ()
 
static void _standard_error_handler (const char *what, const char *expr, const char *file, int line, const char *msg)
 
static void _standard_warning_handler (const char *, const char *expr, const char *file, int line, const char *msg)
 
void assertion_fail (const char *expr, const char *file, int line, const char *msg)
 Default error handler. More...
 
void precondition_fail (const char *expr, const char *file, int line, const char *msg)
 
void postcondition_fail (const char *expr, const char *file, int line, const char *msg)
 
void warning_fail (const char *expr, const char *file, int line, const char *msg)
 
Failure_function set_error_handler (Failure_function handler)
 Sets the handler for assertion-failures. More...
 
Failure_function set_warning_handler (Failure_function handler)
 
Failure_behaviour set_error_behaviour (Failure_behaviour eb)
 Controls the behavior when an assertion fails. More...
 
Failure_behaviour set_warning_behaviour (Failure_behaviour eb)
 

Variables

static Failure_behaviour _error_behaviour = ABORT
 
static Failure_behaviour _warning_behaviour = CONTINUE
 
static Failure_function _error_handler = _standard_error_handler
 
static Failure_function _warning_handler = _standard_warning_handler
 

Function Documentation

static void _standard_error_handler ( const char *  what,
const char *  expr,
const char *  file,
int  line,
const char *  msg 
)
static

Definition at line 96 of file assertions.C.

102 {
103  std::cerr << "Rocface error: " << what << " violation!" << std::endl
104  << "Expr: " << expr << std::endl
105  << "File: " << file << std::endl
106  << "Line: " << line << std::endl;
107  if ( msg != 0)
108  std::cerr << "Explanation:" << msg << std::endl;
109 }
static void _standard_warning_handler ( const char *  ,
const char *  expr,
const char *  file,
int  line,
const char *  msg 
)
static

Definition at line 116 of file assertions.C.

121 {
122  std::cerr << "Rocface warning: check violation!" << std::endl
123  << "Expr: " << expr << std::endl
124  << "File: " << file << std::endl
125  << "Line: " << line << std::endl;
126  if ( msg != 0)
127  std::cerr << "Explanation:" << msg << std::endl;
128 
129 }
void assertion_fail ( const char *  expr,
const char *  file,
int  line,
const char *  msg 
)

Default error handler.

Definition at line 142 of file assertions.C.

References _error_behaviour, ABORT, COMMPI_Initialized(), CONTINUE, EXIT, EXIT_WITH_SUCCESS, MPI_COMM_WORLD, and printStackBacktrace().

146 {
147  (*_error_handler)("assertion", expr, file, line, msg);
149  switch (_error_behaviour) {
150  case ABORT:
151  if (COMMPI_Initialized()) MPI_Abort(MPI_COMM_WORLD,-1); abort();
152  case EXIT:
153  exit(1); // EXIT_FAILURE
154  case EXIT_WITH_SUCCESS:
155  exit(0); // EXIT_SUCCESS
156  case CONTINUE:
157  ;
158  }
159 }
here we put it at the!beginning of the common block The point to point and collective!routines know about but MPI_TYPE_STRUCT as yet does not!MPI_STATUS_IGNORE and MPI_STATUSES_IGNORE are similar objects!Until the underlying MPI library implements the C version of these are declared as arrays of MPI_STATUS_SIZE!The types and are OPTIONAL!Their values are zero if they are not available Note that!using these reduces the portability of MPI_IO INTEGER MPI_BOTTOM INTEGER MPI_DOUBLE_PRECISION INTEGER MPI_LOGICAL INTEGER MPI_2REAL INTEGER MPI_2DOUBLE_COMPLEX INTEGER MPI_LB INTEGER MPI_WTIME_IS_GLOBAL INTEGER MPI_COMM_WORLD
static Failure_behaviour _error_behaviour
Definition: assertions.C:73
COM_BEGIN_NAME_SPACE void printStackBacktrace()
Print the stack backtrace.
int COMMPI_Initialized()
Definition: commpi.h:168

Here is the call graph for this function:

CGAL_BEGIN_NAMESPACE void not_implemented ( )

Definition at line 65 of file assertions.C.

66 {
67  assert( false);
68 }
void postcondition_fail ( const char *  expr,
const char *  file,
int  line,
const char *  msg 
)

Definition at line 182 of file assertions.C.

References _error_behaviour, ABORT, COMMPI_Initialized(), CONTINUE, EXIT, EXIT_WITH_SUCCESS, MPI_COMM_WORLD, and printStackBacktrace().

186 {
187  (*_error_handler)("postcondition", expr, file, line, msg);
189  switch (_error_behaviour) {
190  case ABORT:
191  if (COMMPI_Initialized()) MPI_Abort(MPI_COMM_WORLD,-1); abort();
192  case EXIT:
193  exit(1); // EXIT_FAILURE
194  case EXIT_WITH_SUCCESS:
195  exit(0); // EXIT_SUCCESS
196  case CONTINUE:
197  ;
198  }
199 }
here we put it at the!beginning of the common block The point to point and collective!routines know about but MPI_TYPE_STRUCT as yet does not!MPI_STATUS_IGNORE and MPI_STATUSES_IGNORE are similar objects!Until the underlying MPI library implements the C version of these are declared as arrays of MPI_STATUS_SIZE!The types and are OPTIONAL!Their values are zero if they are not available Note that!using these reduces the portability of MPI_IO INTEGER MPI_BOTTOM INTEGER MPI_DOUBLE_PRECISION INTEGER MPI_LOGICAL INTEGER MPI_2REAL INTEGER MPI_2DOUBLE_COMPLEX INTEGER MPI_LB INTEGER MPI_WTIME_IS_GLOBAL INTEGER MPI_COMM_WORLD
static Failure_behaviour _error_behaviour
Definition: assertions.C:73
COM_BEGIN_NAME_SPACE void printStackBacktrace()
Print the stack backtrace.
int COMMPI_Initialized()
Definition: commpi.h:168

Here is the call graph for this function:

void precondition_fail ( const char *  expr,
const char *  file,
int  line,
const char *  msg 
)

Definition at line 162 of file assertions.C.

References _error_behaviour, ABORT, COMMPI_Initialized(), CONTINUE, EXIT, EXIT_WITH_SUCCESS, MPI_COMM_WORLD, and printStackBacktrace().

166 {
167  (*_error_handler)("precondition", expr, file, line, msg);
169  switch (_error_behaviour) {
170  case ABORT:
171  if (COMMPI_Initialized()) MPI_Abort(MPI_COMM_WORLD,-1); abort();
172  case EXIT:
173  exit(1); // EXIT_FAILURE
174  case EXIT_WITH_SUCCESS:
175  exit(0); // EXIT_SUCCESS
176  case CONTINUE:
177  ;
178  }
179 }
here we put it at the!beginning of the common block The point to point and collective!routines know about but MPI_TYPE_STRUCT as yet does not!MPI_STATUS_IGNORE and MPI_STATUSES_IGNORE are similar objects!Until the underlying MPI library implements the C version of these are declared as arrays of MPI_STATUS_SIZE!The types and are OPTIONAL!Their values are zero if they are not available Note that!using these reduces the portability of MPI_IO INTEGER MPI_BOTTOM INTEGER MPI_DOUBLE_PRECISION INTEGER MPI_LOGICAL INTEGER MPI_2REAL INTEGER MPI_2DOUBLE_COMPLEX INTEGER MPI_LB INTEGER MPI_WTIME_IS_GLOBAL INTEGER MPI_COMM_WORLD
static Failure_behaviour _error_behaviour
Definition: assertions.C:73
COM_BEGIN_NAME_SPACE void printStackBacktrace()
Print the stack backtrace.
int COMMPI_Initialized()
Definition: commpi.h:168

Here is the call graph for this function:

void printStackBacktrace ( )

Definition at line 76 of file assertions.C.

References i.

76  {
77 #ifdef TRACEBACK
78  const int max_stack=64;
79  void *stackPtrs[max_stack];
80 
81  int levels=backtrace(stackPtrs,max_stack);
82  char **symbols=backtrace_symbols(stackPtrs, levels);
83 
84  const int nSkip=2;
85  std::printf( "\nStack Backtrace:\n");
86  for ( int i=nSkip; i<levels; i++) {
87  std::printf( " [%d] %s\n", i-nSkip, symbols[i]);
88  }
89 #endif
90 }
blockLoc i
Definition: read.cpp:79
Failure_behaviour set_error_behaviour ( Failure_behaviour  eb)

Controls the behavior when an assertion fails.

Definition at line 244 of file assertions.C.

References _error_behaviour.

245 {
247  _error_behaviour = eb;
248  return result;
249 }
Failure_behaviour
Behavior of failures.
static Failure_behaviour _error_behaviour
Definition: assertions.C:73
Failure_function set_error_handler ( Failure_function  handler)

Sets the handler for assertion-failures.

Definition at line 228 of file assertions.C.

References _error_handler.

229 {
231  _error_handler = handler;
232  return( result);
233 }
void(* Failure_function)(const char *, const char *, const char *, int, const char *)
Function type for error handlers.
static Failure_function _error_handler
Definition: assertions.C:134
Failure_behaviour set_warning_behaviour ( Failure_behaviour  eb)

Definition at line 252 of file assertions.C.

References _warning_behaviour.

253 {
255  _warning_behaviour = eb;
256  return result;
257 }
Failure_behaviour
Behavior of failures.
static Failure_behaviour _warning_behaviour
Definition: assertions.C:74
Failure_function set_warning_handler ( Failure_function  handler)

Definition at line 236 of file assertions.C.

References _warning_handler.

237 {
239  _warning_handler = handler;
240  return( result);
241 }
void(* Failure_function)(const char *, const char *, const char *, int, const char *)
Function type for error handlers.
static Failure_function _warning_handler
Definition: assertions.C:137
void warning_fail ( const char *  expr,
const char *  file,
int  line,
const char *  msg 
)

Definition at line 205 of file assertions.C.

References _warning_behaviour, ABORT, CONTINUE, EXIT, EXIT_WITH_SUCCESS, MPI_COMM_WORLD, and printStackBacktrace().

209 {
210  (*_warning_handler)("warning", expr, file, line, msg);
212  switch (_warning_behaviour) {
213  case ABORT:
214  MPI_Abort(MPI_COMM_WORLD,-1); abort();
215  case EXIT:
216  exit(1); // EXIT_FAILURE
217  case EXIT_WITH_SUCCESS:
218  exit(0); // EXIT_SUCCESS
219  case CONTINUE:
220  ;
221  }
222 }
here we put it at the!beginning of the common block The point to point and collective!routines know about but MPI_TYPE_STRUCT as yet does not!MPI_STATUS_IGNORE and MPI_STATUSES_IGNORE are similar objects!Until the underlying MPI library implements the C version of these are declared as arrays of MPI_STATUS_SIZE!The types and are OPTIONAL!Their values are zero if they are not available Note that!using these reduces the portability of MPI_IO INTEGER MPI_BOTTOM INTEGER MPI_DOUBLE_PRECISION INTEGER MPI_LOGICAL INTEGER MPI_2REAL INTEGER MPI_2DOUBLE_COMPLEX INTEGER MPI_LB INTEGER MPI_WTIME_IS_GLOBAL INTEGER MPI_COMM_WORLD
COM_BEGIN_NAME_SPACE void printStackBacktrace()
Print the stack backtrace.
static Failure_behaviour _warning_behaviour
Definition: assertions.C:74

Here is the call graph for this function:

Variable Documentation

Failure_behaviour _error_behaviour = ABORT
static
Failure_function _error_handler = _standard_error_handler
static

Definition at line 134 of file assertions.C.

Referenced by set_error_handler().

Failure_behaviour _warning_behaviour = CONTINUE
static

Definition at line 74 of file assertions.C.

Referenced by set_warning_behaviour(), and warning_fail().

Failure_function _warning_handler = _standard_warning_handler
static

Definition at line 137 of file assertions.C.

Referenced by set_warning_handler().