Logo Search packages:      
Sourcecode: quantlib version File versions

qldefines.hpp

Go to the documentation of this file.
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*
 Copyright (C) 2000-2004 StatPro Italia srl

 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it
 under the terms of the QuantLib license.  You should have received a
 copy of the license along with this program; if not, please email
 <quantlib-dev@lists.sf.net>. The license is also available online at
 <http://quantlib.org/reference/license.html>.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

/*! \file qldefines.hpp
    \brief Global definitions and compiler switches.
*/

#ifndef quantlib_defines_hpp
/* install-hook */
#define quantlib_defines_hpp

#include <boost/config.hpp>
#include <boost/version.hpp>
#if BOOST_VERSION < 103100
    #error using an old version of Boost, please update.
#endif
#if !defined(BOOST_ENABLE_ASSERT_HANDLER)
    #define BOOST_ENABLE_ASSERT_HANDLER
#endif

/* eventually these will go into userconfig.hpp.
   For the time being, we hard code them here.
*/
#define QL_INTEGER int
#define QL_BIG_INTEGER long
#define QL_REAL double


/*! \defgroup macros QuantLib macros

    Global definitions and a few macros which help porting the
    code to different compilers.

    @{
*/

#if (defined(_DEBUG) || defined(DEBUG))
    #define QL_DEBUG
#endif

//! version string
#ifdef QL_DEBUG
    #define QL_VERSION "0.3.9-debug"
#else
00061     #define QL_VERSION "0.3.9"
#endif

//! version hexadecimal number
00065 #define QL_HEX_VERSION 0x000309f0
//! version string for output lib name
00067 #define QL_LIB_VERSION "0_3_9"

#if   defined(HAVE_CONFIG_H)    // Dynamically created by configure
    #include <ql/config.hpp>
#elif defined(__BORLANDC__)     // Borland C++ 5.5
    #include <ql/config.bcc.hpp>
#elif defined(__MWERKS__)       // Metrowerks CodeWarrior
    #include <ql/config.mwcw.hpp>
/* Use BOOST_MSVC instead of _MSC_VER since some other vendors (Metrowerks,
   for example) also #define _MSC_VER
*/
#elif defined(BOOST_MSVC)       // Microsoft Visual C++
    #include <ql/config.msvc.hpp>
#elif defined(__MINGW32__)      // Minimalistic GNU for Windows
    #include <ql/config.mingw.hpp>
#else                           // We hope that the compiler follows ANSI
    #include <ql/config.ansi.hpp>
#endif


/*! \defgroup miscMacros Generic macros

    Miscellaneous macros for compiler idiosyncrasies not fitting other
    categories.

    @{
*/

/*! \def QL_DUMMY_RETURN
    \brief Is a dummy return statement required?

    Some compilers will issue a warning if it is missing even though
    it could never be reached during execution, e.g., after a block like
    \code
    if (condition)
        return validResult;
    else
        QL_FAIL("whatever the reason");
    \endcode
    On the other hand, other compilers will issue a warning if it is present
    because it cannot be reached.
    For the code to be portable this macro should be used after the block.
*/
#if defined(REQUIRES_DUMMY_RETURN)
    #define QL_DUMMY_RETURN(x)        return x;
#else
00113     #define QL_DUMMY_RETURN(x)
#endif

/*! \def QL_IO_INIT
    \brief I/O initialization

    Sometimes, programs compiled with the free Borland compiler will
    crash miserably upon attempting to write on std::cout.  Strangely
    enough, issuing the instruction
    \code
    std::cout << std::string();
    \endcode
    at the beginning of the program will prevent other accesses to
    <code>std::cout</code> from crashing the program. This macro, to
    be called at the beginning of <code>main()</code>, encapsulates
    the above enchantment for Borland and is defined as empty for the
    other compilers.
*/
#if defined(QL_PATCH_BORLAND)
    #define QL_IO_INIT    std::cout << std::string();
#else
00134     #define QL_IO_INIT
#endif
/*! @} */


#if defined HAVE_CSTDLIB
    #include <cstdlib>
#elif defined HAVE_STDLIB_H
    #include <stdlib.h>
#else
    #error Neither <cstdlib> nor <stdlib.h> found
#endif
#if defined(BOOST_NO_STDC_NAMESPACE)
    namespace std { using ::atoi; }
#endif
#ifndef QL_DISABLE_DEPRECATED
/*! \def QL_ATOI
    \brief conversion from string to int
    \deprecated use std::atoi instead
*/
00154 #define QL_ATOI std::atoi
#endif


/*! \defgroup mathMacros Math functions

    Some compilers still define math functions in the global
    namespace.  For the code to be portable these macros had to be
    used instead of the actual functions. However, Boost provides
    the means of bypassing this limitation; therefore, all these
    macros are now deprecated in favor of the actual functions in
    namespace std.

    @{
*/
#if defined HAVE_CMATH
    #include <cmath>
#elif defined HAVE_MATH_H
    #include <math.h>
#else
    #error Neither <cmath> nor <math.h> found
#endif
#if defined(BOOST_NO_STDC_NAMESPACE)
    namespace std { using ::sqrt; using ::fabs; using ::exp; using ::log;
                    using ::sin; using ::cos; using ::pow; using ::modf;
                    using ::sinh; using ::cosh; using ::floor; }
#endif
#ifndef QL_DISABLE_DEPRECATED
/*! \def QL_SQRT
    \brief square root
    \deprecated use std::sqrt instead
*/
00186 #define QL_SQRT std::sqrt
/*! \def QL_FABS
    \brief absolute value
    \deprecated use std::fabs instead
*/
00191 #define QL_FABS std::fabs
/*! \def QL_EXP
    \brief exponential
    \deprecated use std::exp instead
*/
00196 #define QL_EXP std::exp
/*! \def QL_LOG
    \brief logarithm
    \deprecated use std::log instead
*/
00201 #define QL_LOG std::log
/*! \def QL_SIN
    \brief sine
    \deprecated use std::sin instead
*/
00206 #define QL_SIN std::sin
/*! \def QL_COS
    \brief cosine
    \deprecated use std::cos instead
*/
00211 #define QL_COS std::cos
/*! \def QL_POW
    \brief power
    \deprecated use std::pow instead
*/
00216 #define QL_POW std::pow
/*! \def QL_MODF
   \brief floating-point module
   \deprecated use std::modf instead
*/
00221 #define QL_MODF std::modf
/*! \def QL_SINH
    \brief hyperbolic sine
    \deprecated use std::sinh instead
*/
00226 #define QL_SINH std::sinh
/*! \def QL_COSH
    \brief hyperbolic cosine
    \deprecated use std::cosh instead
*/
00231 #define QL_COSH std::cosh
/*! \def QL_FLOOR
    \brief floor
    \deprecated use std::floor instead
*/
00236 #define QL_FLOOR std::floor
#endif
/*! @} */


/*! \defgroup limitMacros Numeric limits

    Some compilers do not give an implementation of
    <code><limits></code> yet.  For the code to be portable
    these macros should be used instead of the corresponding method of
    <code>std::numeric_limits</code> or the corresponding macro
    defined in <code><limits.h></code>.

    @{
*/
/*! \def QL_MIN_INTEGER
    Defines the value of the largest representable negative integer value
*/
/*! \def QL_MAX_INTEGER
    Defines the value of the largest representable integer value
*/
/*! \def QL_MIN_REAL
    Defines the value of the largest representable negative
    floating-point value
*/
/*! \def QL_MIN_POSITIVE_REAL
    Defines the value of the smallest representable positive double value
*/
/*! \def QL_MAX_REAL
    Defines the value of the largest representable floating-point value
*/
/*! \def QL_EPSILON
    Defines the machine precision for operations over doubles
*/
#include <boost/limits.hpp>
// limits used as such
00272 #define QL_MIN_INTEGER         ((std::numeric_limits<QL_INTEGER>::min)())
00273 #define QL_MAX_INTEGER         ((std::numeric_limits<QL_INTEGER>::max)())
00274 #define QL_MIN_REAL           -((std::numeric_limits<QL_REAL>::max)())
00275 #define QL_MAX_REAL            ((std::numeric_limits<QL_REAL>::max)())
00276 #define QL_MIN_POSITIVE_REAL   ((std::numeric_limits<QL_REAL>::min)())
00277 #define QL_EPSILON             ((std::numeric_limits<QL_REAL>::epsilon)())
// specific values---these should fit into any Integer or Real
#define QL_NULL_INTEGER        ((std::numeric_limits<int>::max)())
#define QL_NULL_REAL           ((std::numeric_limits<float>::max)())
/*! @} */


/*! \defgroup timeMacros Time functions

    Some compilers still define time functions in the global namespace.
    For the code to be portable these macros had to be
    used instead of the actual functions. However, Boost provides
    the means of bypassing this limitation; therefore, all these
    macros are now deprecated in favor of the actual functions in
    namespace std.

    @{
*/
#if defined HAVE_CTIME
    #include <ctime>
#elif defined HAVE_TIME_H
    #include <time.h>
#else
    #error Neither <ctime> nor <time.h> found
#endif
#if defined(BOOST_NO_STDC_NAMESPACE)
    namespace std { using ::time; using ::time_t; using ::tm; using ::gmtime; }
#endif
#ifndef QL_DISABLE_DEPRECATED
/*! \def QL_TIME
    \brief time value
    \deprecated use std::time instead
*/
00310 #define QL_TIME std::time
/*! \def QL_TIME_T
    \brief time_t type
    \deprecated use std::time_t instead
*/
00315 #define QL_TIME_T std::time_t
/*! \def QL_TM
    \brief tm type
    \deprecated use std::tm instead
*/
00320 #define QL_TM std::tm
/*! \def QL_GMTIME
    \brief gmtime function
    \deprecated use std::gmtime instead
*/
00325 #define QL_GMTIME std::gmtime
#endif
/*! @} */


/*! \defgroup charMacros Character functions

    Some compilers still define character functions in the global
    namespace.  For the code to be portable these macros had to be
    used instead of the actual functions. However, Boost provides
    the means of bypassing this limitation; therefore, all these
    macros are now deprecated in favor of the actual functions in
    namespace std.

    @{
*/
#if defined HAVE_CCTYPE
    #include <cctype>
#elif defined HAVE_CTYPE_H
    #include <ctype.h>
#else
    #error Neither <cctype> nor <ctype.h> found
#endif
#if defined(BOOST_NO_STDC_NAMESPACE)
    namespace std { using ::tolower; using ::toupper; }
#endif
#ifndef QL_DISABLE_DEPRECATED
/*! \def QL_TOUPPER
    \brief convert to uppercase
    \deprecated use std::toupper instead
*/
00356 #define QL_TOUPPER std::toupper
/*! \def QL_TOLOWER
    \brief convert to lowercase
    \deprecated use std::tolower instead
*/
00361 #define QL_TOLOWER std::tolower
#endif
/*! @} */


/*! \defgroup algoMacros Min and max functions

    Some compilers still do not define <code>std::min</code> and
    <code>std::max</code>. Moreover, Visual C++ 6 defines them but for
    unfathomable reasons garble their names.  For the code to be
    portable these macros had to be used instead of the actual
    functions. However, Boost provides the means of bypassing this
    limitation; therefore, all these macros are now deprecated in
    favor of the actual functions in namespace std.

    @{
*/
#include <algorithm>
#ifndef QL_DISABLE_DEPRECATED
/*! \def QL_MIN
    \brief minimum between two elements
    \deprecated use std::min instead
*/
00384 #define QL_MIN std::min
/*! \def QL_MAX
    \brief maximum between two elements
    \deprecated use std::max instead
*/
00389 #define QL_MAX std::max
#endif
/*! @} */


/*! \defgroup templateMacros Template capabilities

    Some compilers still do not fully implement the template syntax.
    These macros can be used to select between alternate
    implementations of blocks of code, namely, one that takes
    advantage of template programming techniques and a less efficient
    one which is compatible with all compilers.

    @{
*/

/*! \def QL_TYPENAME

    In Visual C++ 6,  typename can only be used in template declarations
    and not in template definitions.
*/
#if defined(CHOKES_ON_TYPENAME)
    #define QL_TYPENAME
#else
00413     #define QL_TYPENAME typename
#endif
/*! @} */


/*! \defgroup iteratorMacros Iterator support

    Some compilers still define the iterator struct outside the std
    namespace, only partially implement it, or do not implement it at
    all.  For the code to be portable these macros should be used
    instead of the actual functions.

    @{
*/
/*! \def QL_FULL_ITERATOR_SUPPORT
    Some compilers (most notably, Visual C++ 6) still do not fully
    support iterators in their STL implementation.  This macro can be
    used to select between alternate implementations of blocks of
    code, namely, one that takes advantage of full iterator support
    and a less efficient one which is compatible with all compilers.
*/
#if !defined(HAVE_INCOMPLETE_ITERATOR_SUPPORT)
00435     #define QL_FULL_ITERATOR_SUPPORT
#endif

/*! @}  */

/*! @}  */

#endif

Generated by  Doxygen 1.6.0   Back to index