mydefs.hpp
Go to the documentation of this file.
1 /*
2 ===============================================================================
3 
4  FILE: mydefs.hpp
5 
6  CONTENTS:
7 
8  Basic data type definitions to be robust across platforms.
9 
10  PROGRAMMERS:
11 
12  martin.isenburg@gmail.com
13 
14  COPYRIGHT:
15 
16  (c) 2005-2011, Martin Isenburg, LASSO - tools to catch reality
17 
18  This is free software; you can redistribute and/or modify it under the
19  terms of the GNU Lesser General Licence as published by the Free Software
20  Foundation. See the COPYING file for more information.
21 
22  This software is distributed WITHOUT ANY WARRANTY and without even the
23  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 
25  CHANGE HISTORY:
26 
27  10 January 2011 -- licensing change for LGPL release and liblas integration
28  13 July 2005 -- created after returning with many mosquito bites from OBX
29 
30 ===============================================================================
31 */
32 #ifndef MYDEFS_HPP
33 #define MYDEFS_HPP
34 
35 typedef int I32;
36 typedef short I16;
37 typedef char I8;
38 
39 typedef unsigned int U32;
40 typedef unsigned short U16;
41 typedef unsigned char U8;
42 
43 #if defined(_WIN32) // 64 byte integer under Windows
44 typedef unsigned __int64 U64;
45 typedef __int64 I64;
46 #else // 64 byte integer elsewhere ...
47 typedef unsigned long long U64;
48 typedef long long I64;
49 #endif
50 
51 typedef float F32;
52 typedef double F64;
53 
54 #if defined(_MSC_VER) && (_MSC_VER < 1300)
55 typedef int BOOL;
56 #else
57 typedef int BOOL;
58 #endif
59 
60 typedef union U32I32F32 { U32 u32; I32 i32; F32 f32; } U32I32F32;
61 typedef union U64I64F64 { U64 u64; I64 i64; F64 f64; } U64I64F64;
62 
63 #define F32_MAX +2.0e+37f
64 #define F32_MIN -2.0e+37f
65 
66 #define U8_MIN ((U8)0x0) // 0
67 #define U8_MAX ((U8)0xFF) // 255
68 #define U8_MAX_PLUS_ONE 0x0100 // 256
69 
70 #define U16_MIN ((U16)0x0) // 0
71 #define U16_MAX ((U16)0xFFFF) // 65535
72 #define U16_MAX_PLUS_ONE 0x00010000 // 65536
73 
74 #define U32_MIN ((U32)0x0) // 0
75 #define U32_MAX ((U32)0xFFFFFFFF) // 4294967295
76 #if defined(WIN32) // 64 byte unsigned int constant under Windows
77 #define U32_MAX_PLUS_ONE 0x0000000100000000 // 4294967296
78 #else // 64 byte unsigned int constant elsewhere ...
79 #define U32_MAX_PLUS_ONE 0x0000000100000000ull // 4294967296
80 #endif
81 
82 #define I8_MIN ((I8)0x80) // -128
83 #define I8_MAX ((I8)0x7F) // 127
84 
85 #define I16_MIN ((I16)0x8000) // -32768
86 #define I16_MAX ((I16)0x7FFF) // 32767
87 
88 #define I32_MIN ((I32)0x80000000) // -2147483648
89 #define I32_MAX ((I32)0x7FFFFFFF) // 2147483647
90 
91 #define I64_MIN ((I64)0x8000000000000000)
92 #define I64_MAX ((I64)0x7FFFFFFFFFFFFFFF)
93 
94 #define U8_FOLD(n) (((n) < U8_MIN) ? (n+U8_MAX_PLUS_ONE) : (((n) > U8_MAX) ? (n-U8_MAX_PLUS_ONE) : (n)))
95 
96 #define I8_CLAMP(n) (((n) <= I8_MIN) ? I8_MIN : (((n) >= I8_MAX) ? I8_MAX : ((I8)(n))))
97 #define U8_CLAMP(n) (((n) <= U8_MIN) ? U8_MIN : (((n) >= U8_MAX) ? U8_MAX : ((U8)(n))))
98 
99 #define I16_CLAMP(n) (((n) <= I16_MIN) ? I16_MIN : (((n) >= I16_MAX) ? I16_MAX : ((I16)(n))))
100 #define U16_CLAMP(n) (((n) <= U16_MIN) ? U16_MIN : (((n) >= U16_MAX) ? U16_MAX : ((U16)(n))))
101 
102 #define I32_CLAMP(n) (((n) <= I32_MIN) ? I32_MIN : (((n) >= I32_MAX) ? I32_MAX : ((I32)(n))))
103 #define U32_CLAMP(n) (((n) <= U32_MIN) ? U32_MIN : (((n) >= U32_MAX) ? U32_MAX : ((U32)(n))))
104 
105 #define I8_QUANTIZE(n) (((n) >= 0) ? (I8)((n)+0.5f) : (I8)((n)-0.5f))
106 #define U8_QUANTIZE(n) (((n) >= 0) ? (U8)((n)+0.5f) : (U8)(0))
107 
108 #define I16_QUANTIZE(n) (((n) >= 0) ? (I16)((n)+0.5f) : (I16)((n)-0.5f))
109 #define U16_QUANTIZE(n) (((n) >= 0) ? (U16)((n)+0.5f) : (U16)(0))
110 
111 #define I32_QUANTIZE(n) (((n) >= 0) ? (I32)((n)+0.5f) : (I32)((n)-0.5f))
112 #define U32_QUANTIZE(n) (((n) >= 0) ? (U32)((n)+0.5f) : (U32)(0))
113 
114 #define I64_QUANTIZE(n) (((n) >= 0) ? (I64)((n)+0.5f) : (I64)((n)-0.5f))
115 #define U64_QUANTIZE(n) (((n) >= 0) ? (U64)((n)+0.5f) : (U64)(0))
116 
117 #define I16_FLOOR(n) ((((I16)(n)) > (n)) ? (((I16)(n))-1) : ((I16)(n)))
118 #define I32_FLOOR(n) ((((I32)(n)) > (n)) ? (((I32)(n))-1) : ((I32)(n)))
119 #define I64_FLOOR(n) ((((I64)(n)) > (n)) ? (((I64)(n))-1) : ((I64)(n)))
120 
121 #define I16_CEIL(n) ((((I16)(n)) < (n)) ? (((I16)(n))+1) : ((I16)(n)))
122 #define I32_CEIL(n) ((((I32)(n)) < (n)) ? (((I32)(n))+1) : ((I32)(n)))
123 #define I64_CEIL(n) ((((I64)(n)) < (n)) ? (((I64)(n))+1) : ((I64)(n)))
124 
125 #define I8_FITS_IN_RANGE(n) (((n) >= I8_MIN) || ((n) <= I8_MAX) ? TRUE : FALSE)
126 #define U8_FITS_IN_RANGE(n) (((n) >= U8_MIN) || ((n) <= U8_MAX) ? TRUE : FALSE)
127 #define I16_FITS_IN_RANGE(n) (((n) >= I16_MIN) || ((n) <= I16_MAX) ? TRUE : FALSE)
128 #define U16_FITS_IN_RANGE(n) (((n) >= U16_MIN) || ((n) <= U16_MAX) ? TRUE : FALSE)
129 
130 #define U32_ZERO_BIT_0(n) (((n)&(U32)0xFFFFFFFE))
131 
132 #ifndef FALSE
133 #define FALSE 0
134 #endif
135 
136 #ifndef TRUE
137 #define TRUE 1
138 #endif
139 
140 #ifndef NULL
141 #define NULL 0
142 #endif
143 
145 {
146  const U32 i = 1;
147  return (*((U8*)&i) == 1);
148 }
149 
150 #define ENDIANSWAP16(n) \
151  ( ((((U16) n) << 8) & 0xFF00) | \
152  ((((U16) n) >> 8) & 0x00FF) )
153 
154 #define ENDIANSWAP32(n) \
155  ( ((((U32) n) << 24) & 0xFF000000) | \
156  ((((U32) n) << 8) & 0x00FF0000) | \
157  ((((U32) n) >> 8) & 0x0000FF00) | \
158  ((((U32) n) >> 24) & 0x000000FF) )
159 
160 inline void ENDIAN_SWAP_16(U8* field)
161 {
162  U8 help = field[0];
163  field[0] = field[1];
164  field[1] = help;
165 }
166 
167 inline void ENDIAN_SWAP_32(U8* field)
168 {
169  U8 help;
170  help = field[0];
171  field[0] = field[3];
172  field[3] = help;
173  help = field[1];
174  field[1] = field[2];
175  field[2] = help;
176 }
177 
178 inline void ENDIAN_SWAP_64(U8* field)
179 {
180  U8 help;
181  help = field[0];
182  field[0] = field[7];
183  field[7] = help;
184  help = field[1];
185  field[1] = field[6];
186  field[6] = help;
187  help = field[2];
188  field[2] = field[5];
189  field[5] = help;
190  help = field[3];
191  field[3] = field[4];
192  field[4] = help;
193 }
194 
195 inline void ENDIAN_SWAP_16(const U8* from, U8* to)
196 {
197  to[0] = from[1];
198  to[1] = from[0];
199 }
200 
201 inline void ENDIAN_SWAP_32(const U8* from, U8* to)
202 {
203  to[0] = from[3];
204  to[1] = from[2];
205  to[2] = from[1];
206  to[3] = from[0];
207 }
208 
209 inline void ENDIAN_SWAP_64(const U8* from, U8* to)
210 {
211  to[0] = from[7];
212  to[1] = from[6];
213  to[2] = from[5];
214  to[3] = from[4];
215  to[4] = from[3];
216  to[5] = from[2];
217  to[6] = from[1];
218  to[7] = from[0];
219 }
220 
221 #endif
BOOL IS_LITTLE_ENDIAN()
Definition: mydefs.hpp:144
int BOOL
Definition: mydefs.hpp:57
union U64I64F64 U64I64F64
float F32
Definition: mydefs.hpp:51
short I16
Definition: mydefs.hpp:36
void ENDIAN_SWAP_32(U8 *field)
Definition: mydefs.hpp:167
unsigned int U32
Definition: mydefs.hpp:39
unsigned short U16
Definition: mydefs.hpp:40
long long I64
Definition: mydefs.hpp:48
unsigned char U8
Definition: mydefs.hpp:41
union U32I32F32 U32I32F32
U32 u32
Definition: mydefs.hpp:60
char I8
Definition: mydefs.hpp:37
F32 f32
Definition: mydefs.hpp:60
void ENDIAN_SWAP_16(U8 *field)
Definition: mydefs.hpp:160
int I32
Definition: mydefs.hpp:35
void ENDIAN_SWAP_64(U8 *field)
Definition: mydefs.hpp:178
U64 u64
Definition: mydefs.hpp:61
unsigned long long U64
Definition: mydefs.hpp:47
I32 i32
Definition: mydefs.hpp:60
double F64
Definition: mydefs.hpp:52


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:08