1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | |
3 | /* |
4 | Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl |
5 | Copyright (C) 2003, 2004, 2005, 2006, 2007 StatPro Italia srl |
6 | Copyright (C) 2015 CompatibL |
7 | |
8 | This file is part of QuantLib, a free-software/open-source library |
9 | for financial quantitative analysts and developers - http://quantlib.org/ |
10 | |
11 | QuantLib is free software: you can redistribute it and/or modify it |
12 | under the terms of the QuantLib license. You should have received a |
13 | copy of the license along with this program; if not, please email |
14 | <quantlib-dev@lists.sf.net>. The license is also available online at |
15 | <http://quantlib.org/license.shtml>. |
16 | |
17 | This program is distributed in the hope that it will be useful, but WITHOUT |
18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
19 | FOR A PARTICULAR PURPOSE. See the license for more details. |
20 | */ |
21 | |
22 | /*! \file qldefines.hpp |
23 | \brief Global definitions and compiler switches. |
24 | */ |
25 | |
26 | #ifndef quantlib_defines_hpp |
27 | #define quantlib_defines_hpp |
28 | |
29 | #define QL_HAVE_CONFIG_H |
30 | |
31 | #ifdef _MSC_VER |
32 | /* Microsoft-specific, but needs to be defined before |
33 | including <boost/config.hpp> which somehow includes |
34 | <math.h> under VC++10 |
35 | */ |
36 | #define _USE_MATH_DEFINES |
37 | #endif |
38 | |
39 | #include <boost/config.hpp> |
40 | #include <boost/version.hpp> |
41 | #if BOOST_VERSION < 104800 |
42 | #error using an old version of Boost, please update. |
43 | #endif |
44 | #if !defined(BOOST_ENABLE_ASSERT_HANDLER) |
45 | #define BOOST_ENABLE_ASSERT_HANDLER |
46 | #endif |
47 | |
48 | /* This allows one to include a given file at this point by |
49 | passing it as a compiler define (e.g., -DQL_INCLUDE_FIRST=foo.hpp). |
50 | |
51 | The idea is to provide a hook for defining QL_REAL and at the |
52 | same time including any necessary headers for the new type. |
53 | */ |
54 | #define INCLUDE_FILE(F) INCLUDE_FILE_(F) |
55 | #define INCLUDE_FILE_(F) #F |
56 | #ifdef QL_INCLUDE_FIRST |
57 | # include INCLUDE_FILE(QL_INCLUDE_FIRST) |
58 | #endif |
59 | #undef INCLUDE_FILE_ |
60 | #undef INCLUDE_FILE |
61 | |
62 | /* Eventually these might go into userconfig.hpp. |
63 | For the time being, we hard code them here. |
64 | They can be overridden by passing the #define to the compiler. |
65 | */ |
66 | #ifndef QL_INTEGER |
67 | # define QL_INTEGER int |
68 | #endif |
69 | |
70 | #ifndef QL_BIG_INTEGER |
71 | # define QL_BIG_INTEGER long |
72 | #endif |
73 | |
74 | #ifndef QL_REAL |
75 | # define QL_REAL double |
76 | #endif |
77 | |
78 | |
79 | /*! \defgroup macros QuantLib macros |
80 | |
81 | Global definitions and a few macros which help porting the |
82 | code to different compilers. |
83 | |
84 | @{ |
85 | */ |
86 | |
87 | #if (defined(_DEBUG) || defined(DEBUG)) |
88 | #define QL_DEBUG |
89 | #endif |
90 | |
91 | #if defined(QL_HAVE_CONFIG_H) // Dynamically created by configure |
92 | #include <ql/config.hpp> |
93 | /* Use BOOST_MSVC instead of _MSC_VER since some other vendors (Metrowerks, |
94 | for example) also #define _MSC_VER |
95 | */ |
96 | #elif defined(BOOST_MSVC) // Microsoft Visual C++ |
97 | #include <ql/config.msvc.hpp> |
98 | #elif defined(__MINGW32__) // Minimalistic GNU for Windows |
99 | #include <ql/config.mingw.hpp> |
100 | #elif defined(__SUNPRO_CC) // Sun Studio |
101 | #include <ql/config.sun.hpp> |
102 | #else // We hope that the compiler follows ANSI |
103 | #include <ql/config.ansi.hpp> |
104 | #endif |
105 | |
106 | |
107 | // extra debug checks |
108 | #ifdef QL_DEBUG |
109 | #ifndef QL_EXTRA_SAFETY_CHECKS |
110 | #define QL_EXTRA_SAFETY_CHECKS |
111 | #endif |
112 | #endif |
113 | |
114 | #ifdef QL_ENABLE_THREAD_SAFE_OBSERVER_PATTERN |
115 | #if BOOST_VERSION < 105800 |
116 | #error Boost version 1.58 or higher is required for the thread-safe observer pattern |
117 | #endif |
118 | #endif |
119 | |
120 | #ifdef QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER |
121 | #if BOOST_VERSION < 105900 |
122 | #error Boost version 1.59 or higher is required for the parallel unit test runner |
123 | #endif |
124 | #endif |
125 | |
126 | // ensure that needed math constants are defined |
127 | #include <ql/mathconstants.hpp> |
128 | |
129 | |
130 | // import global functions into std namespace |
131 | #if defined(BOOST_NO_STDC_NAMESPACE) |
132 | #include <cmath> |
133 | namespace std { |
134 | using ::sqrt; using ::abs; using ::fabs; |
135 | using ::exp; using ::log; using ::pow; |
136 | using ::sin; using ::cos; using ::asin; using ::acos; |
137 | using ::sinh; using ::cosh; |
138 | using ::floor; using ::fmod; using ::modf; |
139 | } |
140 | #endif |
141 | |
142 | |
143 | /*! \defgroup limitMacros Numeric limits |
144 | |
145 | Some compilers do not give an implementation of |
146 | <code>\<limits\></code> yet. For the code to be portable |
147 | these macros should be used instead of the corresponding method of |
148 | <code>std::numeric_limits</code> or the corresponding macro |
149 | defined in <code><limits.h></code>. |
150 | |
151 | @{ |
152 | */ |
153 | /*! \def QL_MIN_INTEGER |
154 | Defines the value of the largest representable negative integer value |
155 | */ |
156 | /*! \def QL_MAX_INTEGER |
157 | Defines the value of the largest representable integer value |
158 | */ |
159 | /*! \def QL_MIN_REAL |
160 | Defines the value of the largest representable negative |
161 | floating-point value |
162 | */ |
163 | /*! \def QL_MIN_POSITIVE_REAL |
164 | Defines the value of the smallest representable positive double value |
165 | */ |
166 | /*! \def QL_MAX_REAL |
167 | Defines the value of the largest representable floating-point value |
168 | */ |
169 | /*! \def QL_EPSILON |
170 | Defines the machine precision for operations over doubles |
171 | */ |
172 | #include <limits> |
173 | // limits used as such |
174 | #define QL_MIN_INTEGER ((std::numeric_limits<QL_INTEGER>::min)()) |
175 | #define QL_MAX_INTEGER ((std::numeric_limits<QL_INTEGER>::max)()) |
176 | #define QL_MIN_REAL -((std::numeric_limits<QL_REAL>::max)()) |
177 | #define QL_MAX_REAL ((std::numeric_limits<QL_REAL>::max)()) |
178 | #define QL_MIN_POSITIVE_REAL ((std::numeric_limits<QL_REAL>::min)()) |
179 | #define QL_EPSILON ((std::numeric_limits<QL_REAL>::epsilon)()) |
180 | /*! @} */ |
181 | |
182 | /*! @} */ |
183 | |
184 | |
185 | // For the time being we're keeping a QL_DEPRECATED macro because |
186 | // of <https://stackoverflow.com/questions/38378693/>. We need to |
187 | // use it to deprecate constructors until we drop support for VC++2015. |
188 | // Other features (methods, typedefs etc.) can use [[deprecated]] and |
189 | // possibly add a message. |
190 | |
191 | // emit warning when using deprecated features |
192 | // clang-format off |
193 | #if defined(BOOST_MSVC) // Microsoft Visual C++ |
194 | # define QL_DEPRECATED __declspec(deprecated) |
195 | # define QL_DEPRECATED_DISABLE_WARNING \ |
196 | __pragma(warning(push)) \ |
197 | __pragma(warning(disable : 4996)) |
198 | # define QL_DEPRECATED_ENABLE_WARNING \ |
199 | __pragma(warning(pop)) |
200 | #elif defined(__GNUC__) |
201 | # define QL_DEPRECATED __attribute__((deprecated)) |
202 | # define QL_DEPRECATED_DISABLE_WARNING \ |
203 | _Pragma("GCC diagnostic push") \ |
204 | _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") |
205 | # define QL_DEPRECATED_ENABLE_WARNING \ |
206 | _Pragma("GCC diagnostic pop") |
207 | #elif defined(__clang__) |
208 | # define QL_DEPRECATED __attribute__((deprecated)) |
209 | # define QL_DEPRECATED_DISABLE_WARNING \ |
210 | _Pragma("clang diagnostic push") \ |
211 | _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") |
212 | # define QL_DEPRECATED_ENABLE_WARNING \ |
213 | _Pragma("clang diagnostic pop") |
214 | #else |
215 | // we don't know how to enable it, just define the macros away |
216 | # define QL_DEPRECATED |
217 | # define QL_DEPRECATED_DISABLE_WARNING |
218 | # define QL_DEPRECATED_ENABLE_WARNING |
219 | #endif |
220 | // clang-format on |
221 | |
222 | #endif |
223 | |