MeshKit  1.0
std.h
Go to the documentation of this file.
00001 #ifndef GFX_STD_INCLUDED // -*- C++ -*-
00002 #define GFX_STD_INCLUDED
00003 
00004 /************************************************************************
00005 
00006   Standard base include file for all gfx-based programs.  This defines
00007   various common stuff that is used elsewhere.
00008 
00009   $Id: std.h,v 1.8 1997/06/25 14:12:31 garland Exp $
00010 
00011  ************************************************************************/
00012 
00013 
00014 #include <stdlib.h>
00015 #include <string>
00016 #include <math.h>
00017 #include <iostream>
00018 
00019 
00020 #ifndef FEQ_EPS
00021 #define FEQ_EPS 1e-6
00022 #define FEQ_EPS2 1e-12
00023 #endif
00024 inline bool FEQ(double a,double b,double eps=FEQ_EPS) { return fabs(a-b)<eps; }
00025 inline bool FEQ(float a,float b,float eps=FEQ_EPS) { return fabsf(a-b)<eps; }
00026 
00027 #ifndef GFX_NO_AXIS_NAMES
00028 enum Axis {X=0, Y=1, Z=2, W=3};
00029 #endif
00030 
00031 
00032 #define fatal_error(s)  report_error(s,__FILE__,__LINE__)
00033 
00034 #ifdef assert
00035 #  undef assert
00036 #endif
00037 #define  assert(i)  (i)?((void)NULL):assert_failed(# i,__FILE__,__LINE__)
00038 
00039 #ifdef SAFETY
00040 #  define AssertBound(t) assert(t)
00041 #else
00042 #  define AssertBound(t)
00043 #endif
00044 
00045 //
00046 // Define the report_error and assert_failed functions.
00047 //
00048 inline void report_error(const char *msg,const char *file,int line)
00049 {
00050     std::cerr << msg << " ("<<file<<":"<<line<<")"<<std::endl;
00051     exit(1);
00052 }
00053 
00054 inline void assert_failed(const char *text,const char *file,int line)
00055 {
00056         std::cerr << "Assertion failed: {" << text <<"} at ";
00057         std::cerr << file << ":" << line << std::endl;
00058     abort();
00059 }
00060 
00061 inline void assertf(int test, const char *msg,
00062                     const char *file=__FILE__, int line=__LINE__)
00063 {
00064     if( !test )
00065     {
00066         std::cerr << "Assertion failed: " << msg << " at ";
00067         std::cerr << file << ":" << line << std::endl;
00068         abort();
00069     }
00070 }
00071 
00072 // GFX_STD_INCLUDED
00073 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines