utilities.h File Reference

Contains utility definitions used throughout all of my projects. More...

#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>

Go to the source code of this file.

Defines

#define DECLARE_STL_TYPEDEF(type, def)
#define DECLARE_STL_TYPEDEF2(type1, type2, def)
#define DECLARE_STL_TYPEDEF3(typeP, type2, type3, def)
#define FOREACH(iterator_type, container, iter)
 Iterate over all elements in an stl container.
#define dprintf(__s_,...)
#define DEBUG   1
#define ASSERT(exp)
#define NYI()
#define safeFree(p)
#define safeDelete(p)
#define safeDeleteArray(p)
#define MIN(x, y)
#define MAX(x, y)
#define MIN3(x, y, z)
#define MAX3(x, y, z)
#define ABS(x)
#define EQ(a, b)   (fabs((a) - (b)) < EPSILON)
#define NEQ(a, b)   (fabs((a) - (b)) > EPSILON)
#define DEGREES_TO_RADIANS(d)   ((d) * (M_PI / 180.0))
#define RADIANS_TO_DEGREES(r)   ((r) * (180.0 / M_PI))
#define CAP(val, min, max)
#define CAPMAX(val, max)   CAP((val), 0, (max))
#define CAPMIN(val, min)   CAP((val), (min), 1)
#define CAP01(val)   CAP((val), 0, 1)
#define PURE_FUNCTION
#define GET_SET(type, l, L)
#define GET_SET_BOOL(pre, L)
#define MEMBER(type, l)
#define GET(type, l, L)   GET_GENERIC(type, l, get##L)
#define SET(type, l, L)   SET_GENERIC(type, l, L)
#define GET_BOOL(pre, L)   GET_GENERIC(bool, pre ## L, pre ## L)
#define SET_BOOL(pre, L)   SET_GENERIC(bool, pre ## L, L)
#define GET_GENERIC(type, l, L)
#define SET_GENERIC(type, l, L)


Detailed Description

Contains utility definitions used throughout all of my projects.

Author:
Travis Fischer (fisch0920@gmail.com)
Date:
Summer 2008
Note:
Some of these definitions assume the availability of GCC preprocessor extensions

Definition in file utilities.h.


Define Documentation

#define ABS (  ) 

Value:

({                   \
   register const typeof(x) ___tx = (x);  \
   (___tx >= 0 ? ___tx : -___tx);   \
})

Definition at line 180 of file utilities.h.

#define ASSERT ( exp   ) 

Value:

do {                                               \
         if ((exp) == false) {                           \
            fprintf(stderr, "\n");                       \
            dprintf("Assertion FAILED: '" #exp "'\n\n"); \
            abort();                                     \
         }                                               \
      } while(0)

Definition at line 79 of file utilities.h.

#define CAP ( val,
min,
max   ) 

Value:

({             \
   const typeof (val) val__ = (val);      \
   const typeof (min) min__ = (min);      \
   const typeof (max) max__ = (max);      \
   ((val__ >= max__) ? max__ : (val__ <= min__ ? min__ : val__)); \
})

Definition at line 193 of file utilities.h.

#define CAP01 ( val   )     CAP((val), 0, 1)

Definition at line 202 of file utilities.h.

#define CAPMAX ( val,
max   )     CAP((val), 0, (max))

Definition at line 200 of file utilities.h.

#define CAPMIN ( val,
min   )     CAP((val), (min), 1)

Definition at line 201 of file utilities.h.

#define DEBUG   1

Definition at line 73 of file utilities.h.

#define DECLARE_STL_TYPEDEF ( type,
def   ) 

Value:

typedef type                    def;               \
   typedef def::iterator           def##Iter;         \
   typedef def::const_iterator     def##ConstIter
Declare typedefs along with iterators and const_iterators Ex: DECLARE_STL_TYPEDEF(std::vector<Shape>, ShapeList); => typedef std::vector<Shape> ShapeList; typedef ShapeList::iterator ShapeListIter; typedef ShapeList::connst_iterator ShapeListConnstIter;

Definition at line 36 of file utilities.h.

#define DECLARE_STL_TYPEDEF2 ( type1,
type2,
def   ) 

Value:

typedef type1,type2             def;               \
   typedef def::iterator           def##Iter;         \
   typedef def::const_iterator     def##ConstIter
Use for stl types which contain a comma (commas are not allowed otherwise in preprocessor macro invocations)

Definition at line 43 of file utilities.h.

#define DECLARE_STL_TYPEDEF3 ( typeP,
type2,
type3,
def   ) 

Value:

typedef type2,type2,type3             def;         \
   typedef def::iterator           def##Iter;         \
   typedef def::const_iterator     def##ConstIter
Use for stl types which contain two commas (commas are not allowed otherwise in preprocessor macro invocations)

Definition at line 50 of file utilities.h.

#define DEGREES_TO_RADIANS (  )     ((d) * (M_PI / 180.0))

Definition at line 189 of file utilities.h.

#define dprintf ( __s_,
...   ) 

Value:

{                                       \
   fprintf(stderr, "%s::%s (%d): ", __FILE__, __func__, __LINE__); \
   fprintf(stderr, (__s_), ## __VA_ARGS__);                        \
}

Definition at line 66 of file utilities.h.

#define EQ ( a,
 )     (fabs((a) - (b)) < EPSILON)

Definition at line 186 of file utilities.h.

#define FOREACH ( iterator_type,
container,
iter   ) 

Value:

for(iterator_type (iter) = (container).begin();   \
        (iter) != (container).end(); ++(iter))
Iterate over all elements in an stl container.

Definition at line 56 of file utilities.h.

#define GET ( type,
l,
 )     GET_GENERIC(type, l, get##L)

Definition at line 254 of file utilities.h.

#define GET_BOOL ( pre,
 )     GET_GENERIC(bool, pre ## L, pre ## L)

Definition at line 260 of file utilities.h.

#define GET_GENERIC ( type,
l,
 ) 

Value:

public:                          \
      inline type L() const __attribute__((always_inline)) { \
         return m_##l;              \
      }

Definition at line 266 of file utilities.h.

#define GET_SET ( type,
l,
 ) 

Value:

GET(type, l, L)           \
   SET(type, l, L)           \
   MEMBER(type, l)

Definition at line 234 of file utilities.h.

#define GET_SET_BOOL ( pre,
 ) 

Value:

GET_BOOL(pre, L)          \
   SET_BOOL(pre, L)          \
   MEMBER(bool, pre ## L)

Definition at line 244 of file utilities.h.

#define MAX ( x,
 ) 

Value:

({                \
   const typeof (x) _x_ = (x);      \
   const typeof (y) _y_ = (y);      \
   ((_x_ > _y_) ? _x_ : _y_);       \
})

Definition at line 158 of file utilities.h.

#define MAX3 ( x,
y,
 ) 

Value:

({            \
   const typeof (x) __x = (x);      \
   const typeof (y) __y = (y);      \
   const typeof (z) __z = (z);      \
   ((__x > __y) ? (__x > __z ? __x: __z) : (__y > __z ? __y : __z)); \
})

Definition at line 171 of file utilities.h.

#define MEMBER ( type,
 ) 

Value:

protected:            \
      type m_##l;        \
   public:

Definition at line 249 of file utilities.h.

#define MIN ( x,
 ) 

Value:

({                \
   const typeof (x) x_ = (x);       \
   const typeof (y) y_ = (y);       \
   ((x_ < y_) ? x_ : y_);           \
})

Definition at line 152 of file utilities.h.

#define MIN3 ( x,
y,
 ) 

Value:

({            \
   const typeof (x) x__ = (x);      \
   const typeof (y) y__ = (y);      \
   const typeof (z) z__ = (z);      \
   ((x__ < y__) ? (x__ < z__ ? x__ : z__) : (y__ < z__ ? y__ : z__)); \
})

Definition at line 164 of file utilities.h.

#define NEQ ( a,
 )     (fabs((a) - (b)) > EPSILON)

Definition at line 187 of file utilities.h.

 
#define NYI (  ) 

Value:

do {                                                  \
      dprintf("Not Yet Implemented!");                   \
      ASSERT(0);                                         \
   } while(0)

Definition at line 88 of file utilities.h.

#define PURE_FUNCTION

A pure function is a function that has no side effects, whose return value depends soley on the values of its arguments. Multiple calls to a pure function with the same arguments can be optimized in subexpressions because they are guaranteed to produce the same result. (available on Linux only)

"Optimizing Software in C++", Agner Fog, 2008

Definition at line 221 of file utilities.h.

#define RADIANS_TO_DEGREES (  )     ((r) * (180.0 / M_PI))

Definition at line 190 of file utilities.h.

#define safeDelete (  ) 

Value:

do {                 \
      if ((p)) {        \
         delete ((p));  \
         (p) = NULL;    \
      }                 \
   } while(0)

Definition at line 111 of file utilities.h.

#define safeDeleteArray (  ) 

Value:

do {                    \
      if ((p)) {           \
         delete[] ((p));   \
         (p) = NULL;       \
      }                    \
   } while(0)

Definition at line 119 of file utilities.h.

#define safeFree (  ) 

Value:

do {              \
      if ((p)) {     \
         free((p));  \
         (p) = NULL; \
      }              \
   } while(0)

Definition at line 103 of file utilities.h.

#define SET ( type,
l,
 )     SET_GENERIC(type, l, L)

Definition at line 257 of file utilities.h.

#define SET_BOOL ( pre,
 )     SET_GENERIC(bool, pre ## L, L)

Definition at line 263 of file utilities.h.

#define SET_GENERIC ( type,
l,
 ) 

Value:

public:                          \
      inline void set##L(type newVal) __attribute__((always_inline)) { \
         m_##l = newVal;            \
      }

Definition at line 272 of file utilities.h.


Generated on 28 Feb 2009 for Milton by doxygen 1.5.6