Qualia  0.2
common.h
Go to the documentation of this file.
1 /*
2  * common.h
3  *
4  * Common definitions.
5  *
6  * This file is part of Qualia https://github.com/sofian/qualia
7  *
8  * (c) 2011 Sofian Audry -- info(@)sofianaudry(.)com
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
29 #ifndef COMMON_H_
30 #define COMMON_H_
31 
32 // Platform check macros.
33 
35 #define is_avr() defined(__AVR__)
36 
38 #define is_arduino() defined(ARDUINO)
39 
41 #define is_computer() !defined(__AVR__)
42 
43 // Define WIN32 (for liblo)
44 #ifdef _WIN32
45  #ifndef WIN32
46  #define WIN32
47  #endif
48 #endif
49 
50 #ifndef __STDC_LIMIT_MACROS
51 #define __STDC_LIMIT_MACROS
52 #endif
53 
54 #include <stdlib.h>
55 #include <float.h>
56 //#include <limits.h>
57 #include <stdint.h>
58 #include <math.h>
59 
60 // Old systems need that to define FLT_MAX and DBL_MAX
61 #ifndef DBL_MAX
62  #if !is_computer() or defined(_WIN32)
63  #include <float.h>
64  #else
65  #include <values.h>
66  #endif
67 #endif
68 
69 #ifdef _MSC_VER
70  #ifndef for
71  #define for if (0) {} else for
72  #endif
73 
74  #define M_PI 3.14159265358979323846
75  #define popen(x,y) _popen(x,y)
76  #define pclose(x) _pclose(x)
77  #define isnan(x) _isnan(x)
78  #define log1p(x) log(1+(x))
79 #endif
80 
81 // Basic definitions from Arduino.h
82 #if (is_arduino())
83  #if ARDUINO >= 100
84  #include "Arduino.h"
85  #else
86  #include "WProgram.h"
87  #endif
88 #endif
89 
90 
92 #define bitFlip(value, bit) ((value) ^= (1UL << (bit))) // Added an extra bit macro.
93 
94 // Parameters.
95 //#define USE_DOUBLE
96 //#define USE_STATIC_ALLOC
97 //#define STATIC_ALLOCATOR_SIZE 100
98 
99 //#define DEBUG_LEVEL 2
100 
101 #ifdef USE_DOUBLE
102  typedef double real;
103  #define INF DBL_MAX
104 #else
105  typedef float real;
106  #define INF FLT_MAX
107 #endif
108 
109  // We use srandom/random/RANDOM_MAX instead of srand/rand/RAND_MAX
110 #ifdef WIN32
111  #define srandom srand
112  #define random rand
113 #endif
114 
115 #ifndef RANDOM_MAX
116  #define RANDOM_MAX RAND_MAX
117 #endif
118 
119 #if !is_arduino()
120 #include <qualia/compat/Arduino.h>
121 #endif
122 
123 #if is_avr()
125 #endif
126 
127 #include <qualia/core/error.h>
128 #include <qualia/core/Allocator.h>
129 
130 #endif