Commit 65aa1964 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

new error handling module

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 2371
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 611cfcc7
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.8 2006-11-28 16:06:24 tforb Exp $
# $Id: Makefile,v 1.9 2007-09-11 07:35:27 tforb Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -127,7 +127,7 @@ HEADERS=$(shell find . -name \*.h)
# in the binary version of the library
# (see below for the configuration of a preinstantiated version of template
# code)
SRC=fcommand.cc filter.cc polesnzeroes.cc fftwaff.cc
SRC=fcommand.cc filter.cc polesnzeroes.cc fftwaff.cc error.cc
# test programs are placed in a subdirectory
TESTS=$(wildcard tests/*.cc)
# whereever we find a README, we will use it
......
/*! \file error.cc
* \brief error handling for libfourier (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: error.cc,v 1.1 2007-09-11 07:35:27 tforb Exp $
* \author Thomas Forbriger
* \date 11/09/2007
*
* error handling for libfourier (implementation)
*
* Copyright (c) 2007 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 11/09/2007 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define FOURIER_ERROR_CC_VERSION \
"FOURIER_ERROR_CC V1.1"
#define FOURIER_ERROR_CC_CVSID \
"$Id: error.cc,v 1.1 2007-09-11 07:35:27 tforb Exp $"
#include <iostream>
#include <fourier/error.h>
using std::cerr;
using std::endl;
namespace fourier {
//! initialize and instantiate
bool Exception::Mreport_on_construct=true;
//! construct from nothing
Exception::Exception():
Mmessage(0), Mfile(0), Mline(0), Mcondition(0)
{ if (Mreport_on_construct) { report(); } }
//! construct with message
Exception::Exception(const char* message):
Mmessage(message), Mfile(0), Mline(0), Mcondition(0)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* condition):
Mmessage(message), Mfile(0), Mline(0), Mcondition(condition)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* file,
const int& line):
Mmessage(message), Mfile(file), Mline(line), Mcondition(0)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info and condition
Exception::Exception(const char* message,
const char* file,
const int& line,
const char* condition):
Mmessage(message), Mfile(file), Mline(line), Mcondition(condition)
{ if (Mreport_on_construct) { report(); } }
//! switch on
void Exception::report_on_construct()
{
Mreport_on_construct=true;
}
//! switch off
void Exception::dont_report_on_construct()
{
Mreport_on_construct=false;
}
//! report
void Exception::report() const
{
base_report();
}
//! report
void Exception::base_report() const
{
cerr << "Exception report:" << endl;
if (Mmessage==0)
{
cerr << " No message" << endl;
}
else
{
cerr << " message: " << Mmessage << endl;
}
if (Mfile!=0)
{
cerr << " triggered in \"" << Mfile << "\" at line #" << Mline << endl;
}
if (Mcondition!=0)
{
cerr << " by condition:" << endl
<< " \"" << Mcondition << "\"" << endl;
}
}
/*----------------------------------------------------------------------*/
//! report violation of assertion
void report_violation(const char* message,
const char* file,
const int& line,
const char* condition)
{
std::cerr << std::endl;
std::cerr << "VIOLATION of condition: " << condition << std::endl;
std::cerr << "* in " << file << " at line " << line << std::endl;
std::cerr << "* message: " << message << std::endl;
}
} // namespace fourier
/* ----- END OF error.cc ----- */
/*! \file error.h
* \brief error handling for libfourier (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: error.h,v 1.1 2007-09-11 07:35:27 tforb Exp $
* \author Thomas Forbriger
* \date 11/09/2007
*
* error handling for libfourier (prototypes)
*
* Copyright (c) 2007 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 11/09/2007 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef FOURIER_ERROR_H_VERSION
#define FOURIER_ERROR_H_VERSION \
"FOURIER_ERROR_H V1.0"
#define FOURIER_ERROR_H_CVSID \
"$Id: error.h,v 1.1 2007-09-11 07:35:27 tforb Exp $"
namespace fourier {
/*! \defgroup group_error Error handling module
*/
/*! \brief Base class for exceptions
*
* This is an exception base class. It holds some information about the
* reason for throwing the exception. The information is printed to cerr
* through function report(). This function may be overloaded by a derived
* type. But its functionality is still accessible through base_report().
*
* The standard behaviour is to print out the message during object
* initialization. If you don't like this, call dont_report_on_construct().
*
* \ingroup group_error
* \sa DATREAD_Xassert
* \sa DATREAD_assert
* \sa DATREAD_abort
*/
class Exception
{
public:
//! Creates exception with no explaning comments
Exception();
//! Creates an exception with an explanation message
Exception(const char* message);
//! Creates an exception with message and failed assertion
Exception(const char* message,
const char* condition);
//! Create with message, failed assertion, and code position
Exception(const char* message,
const char* file,
const int& line,
const char* condition);
//! Create with message and code position
Exception(const char* message,
const char* file,
const int& line);
//! provide explicit virtual destructor
virtual ~Exception() { }
//! Screen report
virtual void report() const;
//! Issue a screen report on construction of exception
static void report_on_construct();
//! Issue NO screen report on construction of exception
static void dont_report_on_construct();
protected:
//! Screen report
void base_report() const;
private:
//! Shall we print to cerr at construction time?
static bool Mreport_on_construct;
//! pointer to message string
const char* Mmessage;
//! pointer to file name string
const char* Mfile;
//! pointer to line number in source file
const int& Mline;
//! pointer to assertion condition text string
const char* Mcondition;
}; // class Exception
/*! \brief report violation of condition
*
* \ingroup group_error
* \param message message of type char*
* \param file name of source code file
* \param line source code line number
* \param condition assert condition
*/
void report_violation(const char* message,
const char* file,
const int& line,
const char* condition);
} // namespace fourier
/*======================================================================*/
//
// preprocessor macros
// ===================
/*! \brief Check an assertion and report by throwing an exception.
*
* \ingroup group_error
* \param C assert condition
* \param M message of type char*
* \param E exception class to throw
*/
#define FOURIER_Xassert(C,M,E) \
if (!(C)) { throw( E ( M , __FILE__, __LINE__, #C )); }
/*! \brief Check an assertion and report by throwing an exception.
*
* \ingroup group_error
* \param C assert condition
* \param M message of type char*
*/
#define FOURIER_assert(C,M) FOURIER_Xassert( C , M , fourier::Exception )
/*! \brief Abort and give a message.
*
* \ingroup group_error
* \param M message of type char*
* \param E exception class to throw
*/
#define FOURIER_abort(M) \
throw( fourier::Exception ( M , __FILE__, __LINE__ ))
#define FOURIER_illegal FOURIER_abort("illegal call!")
/*! \brief Check an assertion and report only.
*
* \ingroup group_error
* \param C assert condition
* \param M message of type char*
* \param V any values that should be output (comment)
* a sequence of values and output operators
*/
#define FOURIER_report_assert(C,M,V) \
if (!(C)) { \
fourier::report_violation(M, __FILE__, __LINE__, #C); \
std::cerr << "* comment: " << V << std::endl; \
std::cerr << std::endl; \
std::cerr.flush(); \
}
/*! \brief Macro to distinguish between fatal and non fatal assertions.
*
* \ingroup group_error
* \param F true for non fatal behaviour
* \param C assert condition
* \param M message of type char*
* \param V any values that should be output (comment)
* a sequence of values and output operators
*/
#define FOURIER_nonfatal_assert(F,C,M,V) \
if (F) { FOURIER_report_assert(C,M,V) } else { FOURIER_assert(C,M) }
#endif // FOURIER_ERROR_H_VERSION (includeguard)
/* ----- END OF error.h ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: fftwaff.cc,v 1.2 2007-09-06 12:48:07 tforb Exp $
* $Id: fftwaff.cc,v 1.3 2007-09-11 07:35:28 tforb Exp $
* \author Thomas Forbriger
* \date 11/07/2006
*
......@@ -19,9 +19,10 @@
#define TF_FFTWAFF_CC_VERSION \
"TF_FFTWAFF_CC V1.0 "
#define TF_FFTWAFF_CC_CVSID \
"$Id: fftwaff.cc,v 1.2 2007-09-06 12:48:07 tforb Exp $"
"$Id: fftwaff.cc,v 1.3 2007-09-11 07:35:28 tforb Exp $"
#include <fourier/fftwaff.h>
#include <fourier/error.h>
#include <tfxx/error.h>
#include <aff/seriesoperators.h>
......@@ -74,6 +75,7 @@ namespace fourier {
*/
DRFFTWAFF::Tspectrum DRFFTWAFF::operator()(const Tseries::Tcoc& s) const
{
FOURIER_assert(int(s.size()) == Msize, "series has wrong size!");
Tspectrum retval(this->Msize/2+1);
aff::Series<fftw_real> out(this->Msize);
aff::Series<fftw_real> in(this->Msize);
......@@ -102,6 +104,8 @@ namespace fourier {
*/
DRFFTWAFF::Tseries DRFFTWAFF::operator()(const Tspectrum::Tcoc& s) const
{
FOURIER_assert(int(s.size()) == (Msize+1/2),
"array of Fourier coefficients has wrong size!");
Tseries retval;
aff::Series<fftw_real> out(Msize);
aff::Series<fftw_real> in(Msize);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment