Visualization Library 2.0.0-b3

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
std_types.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2017, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef stdtypes_INCLUDE_ONCE
33 #define stdtypes_INCLUDE_ONCE
34 
35 #include <vlCore/config.hpp>
36 #include <vlCore/checks.hpp>
37 
38 namespace vl
39 {
41  typedef char i8;
43  typedef unsigned char u8;
45  typedef short i16;
47  typedef unsigned short u16;
49  typedef int i32;
51  typedef unsigned int u32;
53  typedef long long i64;
55  typedef unsigned long long u64;
57  typedef float f32;
59  typedef double f64;
60 
61  // trigonometric constants
62 
64  const double dPi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093845;
66  const double dDEG_TO_RAD = dPi / 180.0;
68  const double dRAD_TO_DEG = 180.0 / dPi;
69 
71  const float fPi = (float)3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093845;
73  const float fDEG_TO_RAD = float(dPi / 180.0);
75  const float fRAD_TO_DEG = float(180.0 / dPi);
76 
77  class degree;
78 
80  class radian
81  {
82  public:
83  radian(real val): mValue(val) {}
84  operator real() { return mValue; }
85  operator degree();
86 
87  private:
88  real mValue;
89  };
90 
92  class degree
93  {
94  public:
95  degree(real val): mValue(val) {}
96  operator real() { return mValue; }
97  operator radian();
98 
99  private:
100  real mValue;
101  };
102 
103  inline radian::operator degree() { return mValue*(real)dRAD_TO_DEG; }
104  inline degree::operator radian() { return mValue*(real)dDEG_TO_RAD; }
105 
107  template<typename T>
108  void swapBytes(T& value)
109  {
110  union
111  {
112  T* value;
113  char* ptr;
114  } u;
115  u.value = &value;
116  char* a = u.ptr;
117  char* b = u.ptr + sizeof(T) - 1;
118  while(a<b)
119  {
120  char tmp = *a;
121  *a = *b;
122  *b = tmp;
123  ++a;
124  --b;
125  }
126  }
127 
128  VL_COMPILE_TIME_CHECK( sizeof(i8)*8 == 8 );
129  VL_COMPILE_TIME_CHECK( sizeof(u8)*8 == 8 );
130  VL_COMPILE_TIME_CHECK( sizeof(i16)*8 == 16 );
131  VL_COMPILE_TIME_CHECK( sizeof(u16)*8 == 16 );
132  VL_COMPILE_TIME_CHECK( sizeof(i32)*8 == 32 );
133  VL_COMPILE_TIME_CHECK( sizeof(u32)*8 == 32 );
134  VL_COMPILE_TIME_CHECK( sizeof(i64)*8 == 64 );
135  VL_COMPILE_TIME_CHECK( sizeof(u64)*8 == 64 );
136  VL_COMPILE_TIME_CHECK( sizeof(f32)*8 == 32 );
137  VL_COMPILE_TIME_CHECK( sizeof(f64)*8 == 64 );
138 }
139 
140 #endif
const double dPi
Greek Pi constant using double precision.
Definition: std_types.hpp:64
unsigned long long u64
64 bits unsigned integer
Definition: std_types.hpp:55
degree(real val)
Definition: std_types.hpp:95
unsigned char u8
8 bits unsigned integer
Definition: std_types.hpp:43
short i16
16 bits signed integer
Definition: std_types.hpp:45
radian(real val)
Definition: std_types.hpp:83
double f64
64 bits floating point value
Definition: std_types.hpp:59
const double dRAD_TO_DEG
Constant to convert radian into degree using double precision.
Definition: std_types.hpp:68
int i32
32 bits signed integer
Definition: std_types.hpp:49
Visualization Library main namespace.
const float fPi
Greek Pi constant using float precision.
Definition: std_types.hpp:71
const double dDEG_TO_RAD
Constant to convert degree into radian using double precision.
Definition: std_types.hpp:66
Simple class representing quantities in degrees, converts automatically to vl::radian and real...
Definition: std_types.hpp:92
Simple class representing quantities in radians, converts automatically to vl::degree and real...
Definition: std_types.hpp:80
unsigned int u32
32 bits unsigned integer
Definition: std_types.hpp:51
VL_COMPILE_TIME_CHECK(sizeof(i8) *8==8)
char i8
8 bits signed integer
Definition: std_types.hpp:41
const float fDEG_TO_RAD
Constant to convert degree into radian using float precision.
Definition: std_types.hpp:73
long long i64
64 bits signed integer
Definition: std_types.hpp:53
void swapBytes(T &value)
Swaps the byte order of the given object.
Definition: std_types.hpp:108
unsigned short u16
16 bits unsigned integer
Definition: std_types.hpp:47
float f32
32 bits floating point value
Definition: std_types.hpp:57
const float fRAD_TO_DEG
Constant to convert radian into degree using float precision.
Definition: std_types.hpp:75