VCRA-SZCZERBACKI-PointBasedRendering/ssDefs.hpp

00001 #ifndef __SSDEFS_HPP
00002 #define __SSDEFS_HPP
00003 
00004 #include <cstddef>                                                                      // we need to include this
00005 
00006 namespace SS
00007 {
00008 
00009 //------------------------------------------------------------------------
00010 // Debug Build (react automatically to the _DEBUG macro)
00011 //------------------------------------------------------------------------
00012 
00013 #if defined(_DEBUG)                                                                                     // debug build
00014 #       undef SS_DEBUG
00015 #       define SS_DEBUG
00016 #endif // _DEBUG
00017 
00018 
00019 #ifdef  SS_DEBUG
00020 #define SS_DEBUG_CODE(X) X
00021 #else
00022 #define SS_DEBUG_CODE(X)
00023 #endif
00024 
00025 #if defined (_MSC_VER)
00026 #       define SS_BUILD_MSC                                                                     // Microsoft Visual C++ (any version)
00027 #       if (_MSC_VER == 1200)                                                                   
00028 #               define SS_BUILD_MSC6                                                            // Microsoft Visual C++ 6.0 or higher (also SS_BUILD_MSC defined)
00029 #   endif
00030 #       define SS_X86_RETURN_EAX                                                                // even inline functions return parameters correctly in eax
00031 #       define SS_COMPILER "Microsoft Visual C++"
00032 #endif
00033 
00034 #define SS_NULL_STATEMENT (static_cast<void>(0))                        // no statement
00035 
00036 //------------------------------------------------------------------------
00037 // Compilation-time assertion. If the expression 'expr' evaluates to false,
00038 // the compilation will be aborted and an error message will be given.
00039 // Unfortunately the error message itself won't display the expression,
00040 // so you will have to scan the source to the line given by the message
00041 // to see which assertion went wrong. This variant of CT assertion can
00042 // be used even inside class descriptions etc.
00043 //
00044 // Note that the CT assertion is evaluated in both release and debug
00045 // builds (as it doesn't generate any real code).
00046 //
00047 //------------------------------------------------------------------------
00048 
00049 #define SS_CT_ASSERT(expr) typedef bool SSCompilationTimeAssertion[(expr) ? 1 : -1] 
00050 
00051 //------------------------------------------------------------------------
00052 // Define 16-bit and 32-bit integers (modify code below with #ifdefs if 
00053 // compiler asserts here about the size!)
00054 //------------------------------------------------------------------------
00055 
00056 typedef char                                    INT8;                                   //  8-bit signed integer
00057 typedef unsigned char                   UINT8;                                  //  8-bit unsigned integer
00058 typedef short int                               INT16;                  // 16-bit signed integer
00059 typedef unsigned short int              UINT16;                 // 16-bit unsigned integer
00060 typedef int                                             INT32;                  // 32-bit signed integer
00061 typedef unsigned int                    UINT32;                 // 32-bit unsigned integer
00062 
00063 //------------------------------------------------------------------------
00064 // Make sure that certain typedefs really do have specified sizes.
00065 //------------------------------------------------------------------------
00066 
00067 SS_CT_ASSERT(sizeof(INT16)==2);
00068 SS_CT_ASSERT(sizeof(UINT16)==2);
00069 SS_CT_ASSERT(sizeof(INT32)==4);
00070 SS_CT_ASSERT(sizeof(UINT32)==4);
00071 
00072 //------------------------------------------------------------------------
00073 // The for() fix macro for MSVC (as Visual C++ does not respect the C++
00074 // standard)
00075 //------------------------------------------------------------------------
00076 
00077 #if defined (SS_BUILD_MSC)
00078 #       if !defined (for)
00079                 inline bool getFalse (void) { return false; }
00080 #               define for if(SS::getFalse()); else for
00081 #       endif // for
00082 #endif  // SS_BUILD_MSC
00083 
00084 //------------------------------------------------------------------------
00085 // Commonly used swap,min2,max2 templates
00086 //------------------------------------------------------------------------
00087 
00088 template <class T> inline void swap (T& a, T& b)
00089 {
00090         T t = a;
00091         a = b;
00092         b = t;
00093 }
00094 
00095 template <class T> inline const T& min2 (const T& a, const T& b)        { return a<=b ? a : b; }
00096 template <class T> inline const T& max2 (const T& a, const T& b)        { return a>=b ? a : b; }
00097 
00098 //------------------------------------------------------------------------
00099 // Float -> int casting
00100 //------------------------------------------------------------------------
00101 
00102 int             intChop         (const float&);                         // extremely fast, always correct (int)(f)
00103 int             intFloor        (const float&);                         // extremely fast, always correct (int)(floor(f)) routine
00104 int             intCeil         (const float&);                         // extremely fast, always correct (int)(ceil(f)) routine
00105 
00106 
00107 //------------------------------------------------------------------------
00108 // Abs and fabs
00109 //------------------------------------------------------------------------
00110 
00111 inline int              abs                     (int i)         { return i < 0 ? -i : i; }
00112 inline float    fabs            (float f)       { return f < 0 ? -f : f; }
00113 inline double   fabs            (double f)      { return f < 0 ? -f : f; }
00114 
00115 //------------------------------------------------------------------------
00116 // Some compilers define macros that may clash with out function naming
00117 //------------------------------------------------------------------------
00118 
00119 #undef min
00120 #undef max
00121 
00122 //------------------------------------------------------------------------
00123 // Assertions for debug build ("assume construction" not used any more as
00124 // it inteferes with code optimization on MSVC6)
00125 //------------------------------------------------------------------------
00126 
00127 void assertFail (const char* expr, const char* file, int line, const char* message); 
00128 
00129 #if defined (SS_DEBUG) && !defined (SS_DISABLE_ASSERTS)
00130 #       define SS_ASSERT(e)                     ((e) ? SS_NULL_STATEMENT : SS::assertFail(#e,__FILE__,__LINE__,""))
00131 #       define SS_ASSERT_PRINT(a,b)     ((a) ? SS_NULL_STATEMENT : SS::assertFail(#a,__FILE__,__LINE__,#b))
00132 #       define SS_API_ASSERT(e)         ((e) ? SS_NULL_STATEMENT : SS::assertFail("API Error:"#e,__FILE__,__LINE__,""))
00133 #else
00134 #       define SS_ASSERT(e)                     (SS_NULL_STATEMENT)                                     
00135 #       define SS_ASSERT_PRINT(a,b)     (SS_NULL_STATEMENT)                                     
00136 #       define SS_API_ASSERT(e)         (SS_NULL_STATEMENT)                                     
00137 #endif // SS_DEBUG
00138 
00139 } // namespace SS
00140 
00141 
00142 //------------------------------------------------------------------------
00143 #endif // __SSDEFS_HPP

Generated on Thu Feb 15 09:09:20 2007 for Surface Splating by  doxygen 1.5.1-p1