rheolef  7.0
compiler.h
Go to the documentation of this file.
1 #ifndef _RHEO_COMPILER_H
2 #define _RHEO_COMPILER_H
3 
4 #include "rheolef/config.h" /* as generated by configure */
5 
6 #include <cmath>
7 namespace rheolef {
8 using std::cos;
9 using std::sin;
10 using std::tan;
11 using std::acos;
12 using std::asin;
13 using std::atan;
14 using std::cosh;
15 using std::sinh;
16 using std::tanh;
17 using std::exp;
18 using std::log;
19 using std::log10;
20 using std::sqrt;
21 using std::abs;
22 using std::fabs;
23 using std::floor;
24 using std::ceil;
25 using std::atan2;
26 using std::pow;
27 using std::fmod;
28 } // namespace rheolef
29 
30 
31 #include <complex>
32 namespace rheolef {
33 
34 template<class T>
35 struct float_traits {
36  typedef T type;
37 };
38 template<class T>
39 struct float_traits<std::complex<T> >
40 {
41  typedef typename float_traits<T>::type type;
42 };
43 } // namespace rheolef
44 
45 // for DEC/Compacq cxx: use standard iostreams
46 #ifdef _RHEOLEF_HAVE_DEC_CXX
47 # ifndef __USE_STD_IOSTREAM
48 # define __USE_STD_IOSTREAM 1
49 # endif
50 #endif
51 
52 // for CRAY C++ STL library: in <iterator.h>, need it
53 #ifdef _RHEOLEF_HAVE_CRAY_CXX
54 #define __STL_USE_NAMESPACES
55 #define __STL_CLASS_PARTIAL_SPECIALIZATION
56 #endif
57 
58 #ifdef _RHEOLEF_HAVE_IOS
59 # include <ios>
60 #elif defined(_RHEOLEF_HAVE_IOS_H)
61 # include <ios.h>
62 #endif
63 
64 // buggy g++ on SunOS defines _X !!
65 #ifdef _X
66 #undef _X
67 #endif
68 #ifdef _RHEOLEF_HAVE_ISTREAM
69 # include <istream>
70 #elif defined(_RHEOLEF_HAVE_ISTREAM_H)
71 # include <istream.h> /* ioskit need it without std:: for kai */
72 #endif
73 
74 #ifdef _RHEOLEF_HAVE_OSTREAM
75 # include <ostream>
76 #elif defined(_RHEOLEF_HAVE_OSTREAM_H)
77 # include <ostream.h>
78 #endif
79 
80 #ifdef _RHEOLEF_HAVE_IOSTREAM
81 # include <iostream>
82 #else
83 # include <iostream.h> /* ioskit need it */
84 #endif
85 
86 #ifdef _RHEOLEF_HAVE_FSTREAM
87 # include <fstream>
88 #elif defined(_RHEOLEF_HAVE_FSTREAM_H)
89 # include <fstream.h>
90 #endif
91 
92 #ifdef _RHEOLEF_HAVE_IOMANIP
93 # include <iomanip>
94 #elif defined(_RHEOLEF_HAVE_IOMANIP_H)
95 # include <iomanip.h>
96 #endif
97 
98 # define fatal_macro(message) \
99  { std::cerr << "fatal(" << __FILE__ << "," << __LINE__ << "): " << message << std::endl; exit(1); }
100 # define error_macro(message) \
101  fatal_macro(message)
102 # define warning_macro(message) \
103  { std::cerr << "warning(" << __FILE__ << "," << __LINE__ << "): " << message << std::endl; }
104 # define check_macro(ok_condition, message) \
105  { if (!(ok_condition)) fatal_macro(message); }
106 
107 # ifdef _RHEOLEF_PARANO
108 # ifdef NDEBUG
109 # undef NDEBUG
110 # endif
111 # define trace_macro(message) \
112  { std::cerr << "trace(" << __FILE__ << "," << __LINE__ << "): " << message << std::endl; }
113 # define assert_macro(ok_condition, message) \
114  check_macro(ok_condition,message)
115 # else // not _RHEOLEF_PARANO
116 # ifndef NDEBUG
117 # define NDEBUG
118 # define BOOST_UBLAS_NDEBUG // disable all bounds, structure and similar checks of uBLAS
119 # endif
120 # define trace_macro(message)
121 # define assert_macro(ok_condition, message)
122 # endif // _RHEOLEF_PARANO
123 
124 
125 #ifdef _RHEOLEF_HAVE_LIMITS
126 #include <limits>
127 #else
128 #error numeric_limits<T> C++ class not available in standard library: please, update your compiler !
129 // substitution for numeric_limits<T> class
130 // #include "rheolef/numeric_limits.h"
131 #endif // _RHEOLEF_HAVE_LIMITS
132 
133 #include "rheolef/numeric_flags.h"
134 
135 #if defined(_RHEOLEF_HAVE_FLOAT128)
136 #include <boost/multiprecision/float128.hpp>
137 namespace rheolef {
138 typedef boost::multiprecision::float128 Float;
139 using namespace boost::multiprecision;
140 static inline float128 sqr (const float128& x) { return (x*x); }
141 using boost::math::isnan;
142 using boost::math::isinf;
143 using boost::math::isfinite;
144 using boost::math::isnormal;
145 } // namespace rheolef
146 
147 #elif defined(_RHEOLEF_HAVE_CLN)
148 # include "rheolef/bigfloat.h"
149 namespace rheolef {
150 typedef bigfloat<_RHEOLEF_DIGITS10> Float;
151 } // namespace rheolef
152 
153 #elif defined(_RHEOLEF_HAVE_LONG_DOUBLE)
154 namespace rheolef {
155 typedef long double Float;
156 } // namespace rheolef
157 
158 #else
159 namespace rheolef {
160 typedef double Float;
161 } // namespace rheolef
162 #endif // Float
163 
164 namespace rheolef { namespace details {
165 template <class T, class Sfinae = void>
166 struct is_rheolef_arithmetic: std::false_type {};
167 
168 template <class T>
170 typename std::enable_if<
171  std::is_arithmetic<T>::value
172  || std::is_same<typename std::decay<T>::type,Float>::value
173 >::type>
174 : std::true_type {};
175 
176 }} // namespace rheolef::details
177 
178 
179 namespace rheolef { namespace details {
180 template<class T, class Check = T>
182  typedef T type;
183 };
184 template<class Int>
185 struct upgrade_integral_to_float<Int, typename std::enable_if<std::is_integral<Int>::value,Int>::type>
186 {
187  typedef Float type;
188 };
189 
190 }} // namespace rheolef::details
191 
192 
193 /* max size for char* filename; TODO: may disapear from code... */
194 #define STRLENMAX 1024
195 
196 
197 #ifdef _RHEOLEF_HAVE_MEMORY_H
198 #include <memory.h> // KAI C++
199 #endif
200 
201 #if !defined(_RHEOLEF_HAVE_SQR_DOUBLE)
202 namespace rheolef {
203 static inline double sqr (const double& x) { return (x*x); }
204 } // namespace rheolef
205 #endif
206 
207 #if defined(_RHEOLEF_HAVE_ITERATOR)
208 #include <iterator> // DEC C++
209 #elif defined(_RHEOLEF_HAVE_ITERATOR_H)
210 #include <iterator.h>
211 #endif
212 
213 #if defined(_RHEOLEF_HAVE_STRING)
214 #include <string>
215 #elif defined(_RHEOLEF_HAVE_BSTRING_H)
216 #include <bstring.h>
217 #elif defined(_RHEOLEF_HAVE_MSTRING_H)
218 #include <mstring.h>
219 #endif
220 
221 // greater/less, ect...
222 #if defined(_RHEOLEF_HAVE_FUNCTIONAL)
223 #include <functional> // DEC C++
224 #elif defined(_RHEOLEF_HAVE_FUNCTIONAL_H)
225 #include <functional.h> // KAI C++
226 #elif defined(_RHEOLEF_HAVE_FUNCTION_H)
227 #include <function.h> // GNU C++
228 #endif
229 
230 #if defined(_RHEOLEF_HAVE_NUMERIC)
231 #include <numeric> // standard c++
232 #elif defined(_RHEOLEF_HAVE_NUMERIC_H)
233 #include <numeric.h> // KAI C++
234 #endif
235 
236 #if defined(_RHEOLEF_HAVE_ALGORITHM)
237 #include <algorithm> // standard
238 #elif defined(_RHEOLEF_HAVE_ALGO_H)
239 #include <algo.h> // old GNU C++
240 #endif
241 
242 namespace rheolef {
243 using std::min;
244 using std::max;
245 #ifdef TO_CLEAN
246 // TODO: promote<T1,T2>::type max(T1,T2) {...}
247 // conflict with max(field_nonlinear_expr<E>,int)
248 template <class T> T max (T x, int y) { return x > y ? x : T(y); }
249 template <class T> T max (int x, T y) { return x > y ? T(x) : y; }
250 template <class T> T min (T x, int y) { return x < y ? x : T(y); }
251 template <class T> T min (int x, T y) { return x < y ? T(x) : y; }
252 template <class T> T abs (T x) { return (x > T(0) ? x : -x); }
253 #endif // TO_CLEAN
254 } // namespace rheolef
255 
256 #if defined(_RHEOLEF_HAVE_CSTLIB)
257 # include <cstdlib>
258 #else
259 # include <stdlib.h>
260 #endif
261 
262 #if defined(_RHEOLEF_HAVE_CSTLIB)
263 # include <cstdio>
264 #else
265 # include <stdio.h>
266 #endif
267 
268 #if defined(_RHEOLEF_HAVE_CLIMITS)
269 # include <climits> /* MAXINT, HUGE */
270 #else
271 # include <limits.h> /* MAXINT, HUGE */
272 #endif
273 
274 #ifdef _RHEOLEF_HAVE_UTILITY
275 #include <utility>
276 #elif defined(_RHEOLEF_HAVE_UTILITY_H)
277 #include <utility.h> // pair with KAI C++
278 #endif
279 
280 #if defined(_RHEOLEF_HAVE_VECTOR)
281 #include <vector>
282 #else
283 #include <vector.h>
284 #endif
285 
286 #if defined(_RHEOLEF_HAVE_LIST)
287 #include <list>
288 #else
289 #include <list.h>
290 #endif
291 
292 #if defined(_RHEOLEF_HAVE_SET)
293 #include <set>
294 #else
295 #include <set.h>
296 #endif
297 
298 #if defined(_RHEOLEF_HAVE_MAP)
299 #include <map>
300 #else
301 #include <map.h>
302 #endif
303 
304 // by default ublas::vector<T>::iterator has no [i] accessors
305 #if defined(_RHEOLEF_HAVE_BOOST)
306 #define BOOST_UBLAS_USE_INDEXED_ITERATOR
307 #endif
308 
309 # ifdef _RHEOLEF_HAVE_DMALLOC /* C++ malloc debug */
310 
311 #define DMALLOC_DISABLE /* do not re-define free() and such as macros: clash with boost that calls std::free() */
312 #include <dmalloc.h> // link also with -ldmalloc
313 #include "rheolef/dmalloc_return.h" // from dmalloc lib
314 
315 // defined in "util/dmallocxx/dmallocc.cc"
316 #define USE_NEW_INLINE
317 #ifdef USE_NEW_INLINE
318 inline
319 void *operator new(size_t size, const char *const file, int line)
320 {
321  if (size == 0) return (void*)0;
322  return dmalloc_malloc(file, line, size, DMALLOC_FUNC_NEW,
323  0 /* no alignment */, 0 /* no xalloc messages */);
324 }
325 inline
326 void *operator new[](size_t size, const char *const file, int line)
327 {
328  if (size == 0) return (void*)0;
329  return dmalloc_malloc(file, line, size, DMALLOC_FUNC_NEW_ARRAY,
330  0 /* no alignment */, 0 /* no xalloc messages */);
331 }
332 inline
333 void
334 operator delete(void *pnt)
335 {
336  char *file;
337  GET_RET_ADDR(file);
338  dmalloc_free(file, 0, pnt, DMALLOC_FUNC_DELETE);
339 }
340 inline
341 void
342 operator delete[](void *pnt)
343 {
344  char *file;
345  GET_RET_ADDR(file);
346  dmalloc_free(file, 0, pnt, DMALLOC_FUNC_DELETE_ARRAY);
347 }
348 #else // USE_NEW_INLINE
349 void *operator new(size_t, const char *const, int);
350 void *operator new[](size_t, const char *const, int);
351 void operator delete(void *);
352 void operator delete[](void *);
353 #endif // USE_NEW_INLINE
354 # define new_macro(obj) new (__FILE__ , __LINE__) obj
355 # define new_tab_macro(typ, n) (new (__FILE__ , __LINE__) typ [(n)])
356 # define delete_macro(ptr) { if (ptr) delete (ptr); }
357 # define delete_tab_macro(ptr) { if (ptr) delete [] (ptr); }
358 
359 # else // ! _RHEOLEF_HAVE_DMALLOC : standard c++ new, delete
360 
361 # define new_macro(obj) (new obj)
362 # define new_tab_macro(typ, n) (new typ [(n)])
363 # define delete_macro(ptr) { if (ptr) delete (ptr); }
364 # define delete_tab_macro(ptr) { if (ptr) delete [] (ptr); }
365 
366 # endif // _RHEOLEF_HAVE_DMALLOC
367 
368 #endif // _RHEO_COMPILER_H
space_mult_list< T, M > pow(const space_basic< T, M > &X, size_t n)
Definition: space_mult.h:87
static double sqr(const double &x)
Definition: compiler.h:203
STL namespace.
irheostream, orheostream - large data streams
Definition: compiler.h:7
double Float
Definition: compiler.h:160
tensor_basic< T > exp(const tensor_basic< T > &a, size_t d)
Definition: tensor-exp.cc:147
#define GET_RET_ADDR(file)