1 // -*- c++ -*- (enables emacs c++ mode)
2 //===========================================================================
3 //
4 // Copyright (C) 1995-2008 Yves Renard
5 //
6 // This file is a part of GETFEM++
7 //
8 // Getfem++  is  free software;  you  can  redistribute  it  and/or modify it
9 // under  the  terms  of the  GNU  Lesser General Public License as published
10 // by  the  Free Software Foundation;  either version 2.1 of the License,  or
11 // (at your option) any later version.
12 // This program  is  distributed  in  the  hope  that it will be useful,  but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or  FITNESS  FOR  A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 // License for more details.
16 // You  should  have received a copy of the GNU Lesser General Public License
17 // along  with  this program;  if not, write to the Free Software Foundation,
18 // Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
19 //
20 // As a special exception, you may use this file as part of a free software
21 // library without restriction.  Specifically, if other files instantiate
22 // templates or use macros or inline functions from this file, or you compile
23 // this file and link it with other files to produce an executable, this
24 // file does not by itself cause the resulting executable to be covered by
25 // the GNU General Public License.  This exception does not however
26 // invalidate any other reasons why the executable file might be covered by
27 // the GNU General Public License.
28 //
29 //===========================================================================
30 
31 /**@file gmm_std.h
32    @author  Yves Renard <Yves.Renard@insa-lyon.fr>,
33    @author  Julien Pommier <Julien.Pommier@insa-toulouse.fr>
34    @date June 01, 1995.
35    @brief basic setup for gmm (includes, typedefs etc.)
36 */
37 #ifndef GMM_STD_H__
38 #define GMM_STD_H__
39 
40 #ifndef __USE_STD_IOSTREAM
41 # define __USE_STD_IOSTREAM
42 #endif
43 
44 #ifndef __USE_BSD
45 # define __USE_BSD
46 #endif
47 
48 #ifndef __USE_ISOC99
49 # define __USE_ISOC99
50 #endif
51 
52 #if defined(_MSC_VER) && _MSC_VER >= 1400 // Secure versions for VC++
53 # define GMM_SECURE_CRT
54 # define SECURE_NONCHAR_SSCANF sscanf_s
55 # define SECURE_NONCHAR_FSCANF fscanf_s
56 # define SECURE_STRNCPY(a, la, b, lb) strncpy_s(a, la, b, lb)
57 # define SECURE_FOPEN(F, filename, mode) (*(F) = 0,  fopen_s(F, filename, mode))
58 # define SECURE_SPRINTF1(S, l, st, p1) sprintf_s(S, l, st, p1)
59 # define SECURE_SPRINTF2(S, l, st, p1, p2) sprintf_s(S, l, st, p1, p2)
60 # define SECURE_SPRINTF4(S, l, st, p1, p2, p3, p4) sprintf_s(S, l, st, p1, p2, p3, p4)
61 # define SECURE_STRDUP(s) _strdup(s)
62 # ifndef _SCL_SECURE_NO_DEPRECATE
63 #   error Add the option /D_SCL_SECURE_NO_DEPRECATE to the compilation command
64 # endif
65 #else
66 # define SECURE_NONCHAR_SSCANF sscanf
67 # define SECURE_NONCHAR_FSCANF fscanf
68 # define SECURE_STRNCPY(a, la, b, lb) strncpy(a, b, lb)
69 # define SECURE_FOPEN(F, filename, mode) ((*(F)) = fopen(filename, mode))
70 # define SECURE_SPRINTF1(S, l, st, p1) sprintf(S, st, p1)
71 # define SECURE_SPRINTF2(S, l, st, p1, p2) sprintf(S, st, p1, p2)
72 # define SECURE_SPRINTF4(S, l, st, p1, p2, p3, p4) sprintf(S, st, p1, p2, p3, p4)
73 # define SECURE_STRDUP(s) strdup(s)
74 #endif
75 
76 
77 #if !defined(GMM_USES_MPI) && GETFEM_PARA_LEVEL > 0
78 # define GMM_USES_MPI
79 #endif
80 
81 /* ********************************************************************** */
82 /*	Compilers detection.						  */
83 /* ********************************************************************** */
84 
85 /* for sun CC 5.0 ...
86 #if defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x500
87 # include <stdcomp.h>
88 # undef _RWSTD_NO_CLASS_PARTIAL_SPEC
89 # undef _RWSTD_NO_NAMESPACE
90 #endif
91 */
92 /* for VISUAL C++ ...
93    #if defined(_MSC_VER) //  && !defined(__MWERKS__)
94    #define _GETFEM_MSVCPP_ _MSC_VER
95    #endif
96 */
97 
98 #if defined(__GNUC__)
99 #  if (__GNUC__ < 3)
100 #    error : PLEASE UPDATE g++ TO AT LEAST 3.0 VERSION
101 #  endif
102 #endif
103 
104 /* ********************************************************************** */
105 /*	C++ Standard Headers.						  */
106 /* ********************************************************************** */
107 #include <cstdlib>
108 #include <cstddef>
109 #include <cmath>
110 #include <cstring>
111 #include <cctype>
112 #include <cassert>
113 #include <climits>
114 #include <iostream>
115 //#include <ios>
116 #include <fstream>
117 #include <ctime>
118 #include <exception>
119 #include <typeinfo>
120 #include <stdexcept>
121 #include <iterator>
122 #include <algorithm>
123 #include <vector>
124 #include <deque>
125 #include <string>
126 #include <complex>
127 #include <limits>
128 #include <sstream>
129 #include <numeric>
130 
131 
132 using std::endl; using std::cout; using std::cerr;
133 using std::ends; using std::cin;
134 
135 namespace gmm {
136 
137   /* ******************************************************************* */
138   /*       Clock functions.                                              */
139   /* ******************************************************************* */
140 
141 # if  defined(HAVE_SYS_TIMES)
uclock_sec(void)142   inline double uclock_sec(void) {
143     static double ttclk = 0.;
144     if (ttclk == 0.) ttclk = sysconf(_SC_CLK_TCK);
145     tms t; times(&t); return double(t.tms_utime) / ttclk;
146   }
147 # else
148   inline double uclock_sec(void)
149   { return double(clock())/double(CLOCKS_PER_SEC); }
150 # endif
151 
152   /* ******************************************************************** */
153   /*	Fixed size integer types.                     			  */
154   /* ******************************************************************** */
155   // Remark : the test program dynamic_array tests the lenght of
156   //          resulting integers
157 
158   template <size_t s> struct fixed_size_integer_generator {
159     typedef void int_base_type;
160     typedef void uint_base_type;
161   };
162 
163   template <> struct fixed_size_integer_generator<sizeof(char)> {
164     typedef signed char int_base_type;
165     typedef unsigned char uint_base_type;
166   };
167 
168   template <> struct fixed_size_integer_generator<sizeof(short int)
169     - ((sizeof(short int) == sizeof(char)) ? 78 : 0)> {
170     typedef signed short int int_base_type;
171     typedef unsigned short int uint_base_type;
172   };
173 
174   template <> struct fixed_size_integer_generator<sizeof(int)
175     - ((sizeof(int) == sizeof(short int)) ? 59 : 0)> {
176     typedef signed int int_base_type;
177     typedef unsigned int uint_base_type;
178   };
179 
180   template <> struct fixed_size_integer_generator<sizeof(long)
181     - ((sizeof(int) == sizeof(long)) ? 93 : 0)> {
182     typedef signed long int_base_type;
183     typedef unsigned long uint_base_type;
184   };
185 
186   template <> struct fixed_size_integer_generator<sizeof(long long)
187     - ((sizeof(long long) == sizeof(long)) ? 99 : 0)> {
188     typedef signed long long int_base_type;
189     typedef unsigned long long uint_base_type;
190   };
191 
192   typedef fixed_size_integer_generator<1>::int_base_type int8_type;
193   typedef fixed_size_integer_generator<1>::uint_base_type uint8_type;
194   typedef fixed_size_integer_generator<2>::int_base_type int16_type;
195   typedef fixed_size_integer_generator<2>::uint_base_type uint16_type;
196   typedef fixed_size_integer_generator<4>::int_base_type int32_type;
197   typedef fixed_size_integer_generator<4>::uint_base_type uint32_type;
198   typedef fixed_size_integer_generator<8>::int_base_type int64_type;
199   typedef fixed_size_integer_generator<8>::uint_base_type uint64_type;
200 
201 // #if INT_MAX == 32767
202 //   typedef signed int    int16_type;
203 //   typedef unsigned int uint16_type;
204 // #elif  SHRT_MAX == 32767
205 //   typedef signed short int    int16_type;
206 //   typedef unsigned short int uint16_type;
207 // #else
208 // # error "impossible to build a 16 bits integer"
209 // #endif
210 
211 // #if INT_MAX == 2147483647
212 //   typedef signed int    int32_type;
213 //   typedef unsigned int uint32_type;
214 // #elif  SHRT_MAX == 2147483647
215 //   typedef signed short int    int32_type;
216 //   typedef unsigned short int uint32_type;
217 // #elif LONG_MAX == 2147483647
218 //   typedef signed long int    int32_type;
219 //   typedef unsigned long int uint32_type;
220 // #else
221 // # error "impossible to build a 32 bits integer"
222 // #endif
223 
224 // #if INT_MAX == 9223372036854775807L || INT_MAX == 9223372036854775807
225 //   typedef signed int    int64_type;
226 //   typedef unsigned int uint64_type;
227 // #elif LONG_MAX == 9223372036854775807L || LONG_MAX == 9223372036854775807
228 //   typedef signed long int    int64_type;
229 //   typedef unsigned long int uint64_type;
230 // #elif LLONG_MAX == 9223372036854775807LL || LLONG_MAX == 9223372036854775807L || LLONG_MAX == 9223372036854775807
231 //   typedef signed long long int int64_type;
232 //   typedef unsigned long long int uint64_type;
233 // #else
234 // # error "impossible to build a 64 bits integer"
235 // #endif
236 
237 #if defined(__GNUC__) && !defined(__ICC)
238 /*
239    g++ can issue a warning at each usage of a function declared with this special attribute
240    (also works with typedefs and variable declarations)
241 */
242 //# define IS_DEPRECATED __attribute__ ((__deprecated__))
243 // annoying : just including .h files e.g. gmm_precond_ildlt.h generates lots of useless warnings with new 4.6+ gcc.
244 # define IS_DEPRECATED
245 /*
246    the specified function is inlined at any optimization level
247 */
248 # define ALWAYS_INLINE __attribute__((always_inline))
249 #else
250 # define IS_DEPRECATED
251 # define ALWAYS_INLINE
252 #endif
253 
254 }
255 
256 #endif /* GMM_STD_H__ */
257 
258