next up previous
Fehlerbehandlung und Robustheit


Implementation von Invariantentests

 
// File: precond.h

#ifndef __PRECONDITION_H
#define __PRECONDITION_H

#include <stdio.h>
#include <typeinfo>
#include <xmsg.h>

class precondition : public xmsg
{
private:
  static const String MakeString(const char *type,
                                 const char *txt,
                                 const char *file,
                                 int line);
public:
  precondition(const char *txt,
               const char *file,
               int line)
               : xmsg(MakeString("Precondition",txt,file,line)){}
};

#define PRECONDITION(p) PRECONDITIONX(p,#p)

#if __DEBUG < 1
#define PRECONDITIONX(p,s)   ((void)0)
#else
#define PRECONDITIONX(p,s)   \
    if(!(p)) {throw precondition(s,__FILE__,__LINE__);}
#endif

#endif


next up previous