OSDN Git Service

e96d2a5241ab9d95715c0be10c50af998343b6f7
[moflib/moflib.git] / moflib-1.0 / moflib / moflib / mof / utilities.hpp
1 #pragma once
2 #define _USE_MATH_DEFINES
3 #include <math.h>
4 #include <boost/foreach.hpp>
5 #define foreach BOOST_FOREACH 
6
7 namespace mof{
8     
9     inline float deg2rad( float deg )
10     {
11         return deg / 180.0f * static_cast<float>(M_PI);
12     }
13
14     inline float rad2deg( float rad )
15     {
16         return rad / static_cast<float>(M_PI) * 180.0f;
17     }
18
19     template< typename T , int N >
20     int lengthOf( T (&)[N] )
21     {
22         return N;
23     }
24     
25     template< typename T , int N >
26     T& lastOf( T(&arr)[N] )
27     {
28         return arr[N-1];
29     }
30
31     template< typename T >
32     void safe_delete( T* (&p) )
33     {
34         delete p;
35         p = NULL;
36     }
37
38     template< typename T >
39     void safe_delete_array( T* (&p) )
40     {
41         delete[] p;
42         p = NULL;
43     }
44
45     inline int rotation_mod(int a , unsigned int b)
46     {
47         return a >= 0 
48             ? a % b 
49             : b - (-a % b);
50     }
51
52
53
54 } // namespace mof
55