common/errors.h
///////////////////////////////////////////////////////////////////////////////
// Filename: errors.h
///////////////////////////////////////////////////////////////////////////////
// Purpose: declaration of class "errors"
///////////////////////////////////////////////////////////////////////////////
// History:
// ========
//
// Date Time Name Description
// -------- -------- -------- ------------------------------------------------
// 96/01/29 00:43:20 muellerg: created
//
///////////////////////////////////////////////////////////////////////////////
#ifndef __ERRORS_H__
#define __ERRORS_H__
// Feature test switches ///////////////////////////// Feature test switches //
/* NONE */
// System headers /////////////////////////////////////////// System headers //
#include <stdlib.h>
#include <sys/types.h>
#include <stdarg.h>
// Local headers ///////////////////////////////////////////// Local headers //
/* NONE */
// Macros /////////////////////////////////////////////////////////// Macros //
// these macros allow to give some information about where a bug was discovered
// from a program
#ifdef __GNUC__
#define BUG(x) error.bug(__PRETTY_FUNCTION__, __FILE__, __LINE__, x)
#else
#define BUG(x) error.bug(NULL, __FILE__, __LINE__, x)
#endif
// File scope objects /////////////////////////////////// File scope objects //
/* NONE */
// External variables, functions, and classes ///////////// External objects //
class errors;
extern errors error; // defined in errordekl.c
// Signal catching functions ///////////////////// Signal catching functions //
/* NONE */
// Structures, unions, and class definitions /////////////////// Definitions //
/* Class errors is a convinient way to handle all the
* different types of errors.
* A debug level can be specified.
* A program should use the function set_program_name()
* to register its name. This makes it possible to destinguish
* the errors from different programs.
*/
class errors
{
public:
enum errorlevel /* the different error levels */
{
harmless, /* a harmless error, continue */
warn, /* a warning, continue */
error, /* a real error, continue */
fatal /* a fatal error, exit the program */
};
enum debuglevel
{
high=1, /* show all debug statements */
medium=2, /* quite a lot */
some=3, /* show some of the debug statements */
low=4, /* show only important ones */
none=5 /* don't show debug statements */
};
/* constructor, destructor */
errors(char *name, debuglevel level=none)
: program_name(name),
error_debuglevel(level)
{
/* nothing to do */
};
~errors(void){}
errors(debuglevel level=none)
: error_debuglevel(level)
{
program_name = "(program name not set)";
};
/* system errors */
/* take the number in errno */
void system(char *message = NULL, errorlevel err_level=fatal);
/* error number specified in error_number */
void system(int errno_number, char *message = NULL,
errorlevel err_level=fatal);
/* panic: terminate programm with message */
void panic(char *message);
/* bug */
/* program bug. Always terminates a program */
void bug(char *function, char *sourcefile, int lineno, char *message);
/* warning, uses printf style for arguments */
void warning(char *fmt,...);
/* debugging */
/* debug output */
void debug(char *message, debuglevel dlevel=high);
/* get/set debug level */
debuglevel get_debug_level(void);
debuglevel set_debug_level(debuglevel debugl);
/* set program name */
char *set_program_name(char *name);
private:
char *program_name; /* program name */
debuglevel error_debuglevel; /* debuglevel */
};